// ==UserScript==
// @name GeoKrety Toolbox
// @version 0.3.6
// @copyright 2016, simor
// @namespace http://simor.net/greasemonkey/
// @description Shows GeoKrety trackables on geocaching.com cache pages and facilitates dropping GK trackables into GC caches.
// @include https://www.geocaching.com/geocache/GC*
// ==/UserScript==
// HISTORY
// -------
// 0.3.6 8 May 2023 JS: document.evaluate() require 2 arguments
// 0.3.5 12 Jan 2019 Site layout update
// 0.3.4 18 Apr 2018 Extract original cache coordinates from javascript
// 0.3.3 8 Feb 2016 Site layout update
// 0.3.2 18 Oct 2011 Site layout update
// 0.3.1 13 May 2011 Site layout update
// 0.3.0 6 Feb 2010 + script is now compatible with Google Chrome
// * some internal and GUI improvements
// 0.2.4 16 Jan 2010 * Combined both Geokrety areas into one
// * Some layout fixes (thanks to Thomas E.)
// 0.2.3 13 Jan 2010 Code optimization
// 0.2.2 13 Jan 2010 Site layout update
// * Internal changes
// 0.2.1 10 Dec 2009 * Some GUI fixes
// + Brought back the "log a gk" link
// 0.2.0 26 Nov 2009 + Easy geokret drop
// * Further serverside speed improvements
// 0.1.6 13 Nov 2009 New (lighter & faster) way of fetching and displaying geokret list
// + New dedicated search engine for GeoKrety Toolbox on GK site
// * Swapped XML with JSON data structures
// 0.1.5 5 Nov 2009 Site layout update
// 0.1.4 19 Oct 2009 Little fix
// 0.1.3 18 Oct 2009 + Added error handler for the http request but this doesn't solve timeout issue (waiting for next version of GM)
// 0.1.2 15 Oct 2009 Code optimization
// + Automatic version check
// + Easy debug option
// + In-code images
// * GK search area increased
// 0.1.1 13 Oct 2009 Some slight fixes
// 0.1.0 12 Oct 2009 Initial version
var SUC_script_num = 59670,
VER = '0.3.6',
DEBUG = false,
GKHOST = 'geokrety.org',
border_style = '1px solid #B0B0B0',
border_style2 = '1px solid #E06060',
imgDrop = '',
pixel_grey = '',
geokretyorg_header = '
GeoKrety.org
';
//var imgGKico = '';
var gcwaypoint, lat, lon;
// window.drop_geokret = function() {
// var select = document.getElementById("gk_select");
// var url = '//'+GKHOST+'/ruchy.php?gkt=drop_gc&nr='+select.value+'&waypoint='+gcwaypoint+'&lat='+lat+'&lon='+lon+'&gkt_return_url='+escape(window.location.href);
// debug('window.location.href='+url);
// window.location.href = url;
// };
window.gk_selectchange = function() {
if (this.selectedIndex==0) {
document.getElementById("gk_dropselected").setAttribute("style","cursor:not-allowed");
document.getElementById("gk_dropselected").removeAttribute("href");
}
else {
var url = '//'+GKHOST+'/ruchy.php?gkt=drop_gc&nr='+this.options[this.selectedIndex].value+'&waypoint='+gcwaypoint+'&lat='+lat+'&lon='+lon;
debug('url='+url);
document.getElementById("gk_dropselected").setAttribute("style","cursor:pointer");
document.getElementById("gk_dropselected").setAttribute("href",url);
}
}
window.gk_getinventory = function() {
var imgRefresh = '';
var gk_inventory = document.getElementById("gk_inventory");
gk_inventory.innerHTML='Retrieving ...';
var gk_inventory2 = document.getElementById("gk_inventory2");
gk_inventory2.setAttribute('style','display:none');
var xhr = new XMLHttpRequest();
xhr.onerror = function() {
debug('Request failed with ' + xhr.status + ' ' + xhr.statusText + '\nData:\n' + xhr.responseText);
gk_inventory.innerHTML='Error retrieving data.';
}
xhr.onload = function() {
debug('Request returned ' + xhr.status + ' ' + xhr.statusText + '\nData:\n|' + xhr.responseText +'|');
var inventory = JSON.parse(this.responseText);
var len = inventory.list.length;
if(len>0)
{
var krets='';
for (var i = 0; i < len; i++) {
krets=krets+'';
}
gk_inventory.innerHTML = '';
gk_inventory2.setAttribute('style','');
document.getElementById("gk_select").addEventListener("change", gk_selectchange, false);
document.getElementById("gk_select").addEventListener("keyup", gk_selectchange, false);
}
else
{
if (inventory.loggedin) {
gk_inventory.innerHTML = 'Your inventory on GeoKrety.org is empty.';
}
else
{
gk_inventory.innerHTML = 'Your are not logged in on GeoKrety.org. To view your inventory you need to log in and then click refresh inventory.';
}
}
}
xhr.overrideMimeType('text/plain');
xhr.open("GET", "//"+GKHOST+"/gkt/inventory_v3.php", true);
xhr.withCredentials = "true";
xhr.send(null);
document.getElementById("gk_getinventory_icon").innerHTML = imgRefresh;
this.innerHTML = 'Refresh my GK Inventory';
};
function go() {
// ------------------------------- images -------------------------------
var imgLogGK = '';
// ------------------------------- geokrets sitting in the cache -------------------------------
var prefix_krets_in_cache = document.createElement('span');
prefix_krets_in_cache.setAttribute("id","prefix_krets_in_cache");
var table_krets_in_cache = document.createElement('span');
tmp = '