// ==UserScript==
// @name     Reocities.com
// @namespace http://reocities.com/download/
// @description Fix geocities.com links 
// @include     *
// ==/UserScript==

(function(d){

    function main() {

	var counter = 0;
	var anchors = d.getElementsByTagName('a');
	var anchors_length = anchors.length;
	for (var i=0; i<anchors_length; i++) {
	    if (anchors[i].hostname == "geocities.com" || anchors[i].hostname == "www.geocities.com" ) {
		anchors[i].href = "http://www.reocities.com" + anchors[i].pathname;
		counter++;
	    } 
	}

	// this fixes hotlinked images, but we're not too happy about those anyway...

	var images = d.getElementsByTagName('img');	
	var images_length = images.length;
	
	for (var i=0; i<images_length; i++) {
		
		if (images[i].src.substring(0,24) == "http://www.geocities.com") {
			images[i].src = "http://www.reocities.com" + images[i].src.substring(24);
			counter++;
		}
		
		if (images[i].src.substring(0,20) == "http://geocities.com" ) {
			images[i].src = "http://www.reocities.com" + images[i].src.substring(20);
			counter++;
		}
	}

	if (counter === 0) {
	    setTimeout(main, 60000);
	    working = {};
	} else {
	    // setTimeout(main, 10000 / counter);
	} 
    }

    main();
}(document));





