collectTB-Codes

Collect TB-Codes from TB Listing

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name            collectTB-Codes
// @namespace       https://github.com/Confectrician/collect_tb_codes
// @author          Confectrician
// @description     Collect TB-Codes from TB Listing
// @include         https://www.geocaching.com/track/details.aspx*
// @grant           GM_getValue
// @grant           GM_setValue
// @grant           GM_registerMenuCommand
// @grant           unsafeWindow
// @version         2.03
// ==/UserScript==


var stored;
var tbcodes = [];
var codehash = [];


function clearCollection() {
  GM_setValue("tbcodeshashed","");
  TA = document.getElementById('gm_tb_ta');
  TA.innerHTML = "";
  alert("TB-Codes cleared");
}

// main()

GM_registerMenuCommand( "TB-Codes clear", clearCollection );

try {
	stored = GM_getValue("tbcodeshashed");
	//console.log("stored = " + stored);
	tbcodes = stored.split('|');
	//console.log("tbcodes = " + tbcodes);
	//console.log("tbcodes length = " + tbcodes.length);
    //alert("Stored " + tbcodes.length + " TB-Codes");
	for(var i=0 ; i < tbcodes.length ; i++)
	{
		codehash[tbcodes[i]]=i;
		//console.log("codehash["+tbcodes[i]+"] Nr. " + i  + " = " + codehash[tbcodes[i]]);
	}
}
catch (err){
}

try
{
	var GCElement = document.getElementById('ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoCode');
	var GCCode    = GCElement.innerHTML;
	codehash[GCCode]=0;

	stored="";
	var i= 0;
	for (var st in codehash) {
	    //console.log("forschleife " + st + " " + i);
	    if(i++){
	        //console.log("ifbedingung true");
            stored = stored + '|';
        }
        stored = stored + st;    
  }
    output = stored;
	if(stored[stored.length -1] == ";"){
	    output = stored.substr(0,stored.length -1);
	}
	//console.log("stored length = " + stored.length);
	GM_setValue("tbcodeshashed",stored);
	var Element=document.getElementById('divContentSide');
	Element.innerHTML=Element.innerHTML + "<div style='width: 250px;'>" + tbcodes.length + ' TB-Codes Stored<br />(Refresh could be necessary)<br /><textarea id=\"gm_tb_ta\" cols=\'40\' rows=\'30\'>' + output.replace(/\|/gi,";") + '</textarea></div>';
    //.replace(/\|/gi,";")
}
catch (err){
}