-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeoKrety.Toolbox.user.js
299 lines (247 loc) · 15.5 KB
/
GeoKrety.Toolbox.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// ==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 = '<img style="padding:0;border:0;vertical-align:middle;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAAVElEQVR42mNkoBAw4hD%2FT6xa3AY0IPEaRg2gqwH%2F0TRhstH0YBrgBSTNsFh1Coi3ETYAuyE4NOMPA5gheDTjMwBhyDb86vAZAAtUvGoIGUAQUGwAAIrkGxG1kinTAAAAAElFTkSuQmCC"/>',
pixel_grey = '<img style="padding:0;border:0;vertical-align:middle;" src="../images/pixel_grey.gif" width="100%" height="1px" />',
geokretyorg_header = '<h3 class="WidgetHeader" style="margin-top:1em; font-size:100%"><strong>Geo<span style="color: white; background-color: #303030;">Krety</span>.org</strong></h3>';
//var imgGKico = '<img align="absmiddle" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAAU0lEQVR42mP8DwQMFADGwW8AIyMjHQzApghmLkgOmY0uBxL5jyyIrhDdAHTDsBqA7gV0OWQXoxiA7hV0F2ALE5K8QNAFZIUBxbEwOBISAwWAYgMANHpy8qY1e9UAAAAASUVORK5CYII%3D"/>';
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 = '<img style="padding:0;border:0;vertical-align:middle;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAADHklEQVR42qWTbUhTURjHn7udrW2ttQxtXSc6M20qYZdFJSo6yHS9oFCLxJCKQsoPUlIfsk8ZRFkYGEkv9MKwGNEbZRamprGCxjUip%2FZitrm5TMvmnHp3d2%2Fn3kqKgj504M853P%2F%2F%2FJ7Duc8heJ4n4D8GIQDyLg434LXpL74T6ygWwgri7Of27QuYPwA554dKgecrN%2BeT1PQ0LxoIEXD9kY8uzl24d%2FQrE%2BMdmWLc%2FslgOMy5OnaS%2Ft8AwiLzjLsGTwWbzHoqGGRBoZTCzcdeuigntirC8ukcz4NKKYF7Dn8gNMk%2BceyO758BLK97Q8pkUtvaTDI3FAyDNmoWMAwHtzoGaZzZRUYr89MMc3UI11LPQXC70%2BtnmEjD88rFYyJg2bHuCqNBuz8uSqlXqBDc6fTQJZZFVGPTO7prf5qJOu6icM66egWZSrC8xD06GegdGGvE3l0RkHaYbjSbYjcgfMpeX6DfPTTejCuvFI7YfYgSLze9psui16krjaRGzxIw1er0tmKvSgQkH3Q4LTlJVISNwAPHe%2Fr1kUxTSvXTUrwvq69mVfnPC8O59jWZhgwpkkJTx9sXOJcrAhKq2trX5BkzwiwHrZ19LwZq83J%2Fborf1yr84icfTphtOOc0Z6dQMiSBB209NM6ZRABZcb92ZZbRHCGQwvfeN%2Bj1jNT5TluaBAD2nD9Yz2L18wtIA5kohUjoWafrjq%2B%2BsEQERO%2B8tS4%2BJa5EEafXqIDlulqeu%2FB3%2B8j5Yhp7zoIteVTz1TbatD6bGp9kYdrrHRzocR%2F7dK6oXgRoy%2BxaJEflGRvzdUPjLKgjUzD8stf%2F2fPxIa58Ns1aSKnkEvjwJQzRs6XQc7OlnWfZ0rHLVt9MI6m32BJls5VZSZvXafwTHEglBCgQ8cpzxV6bUGalhkMcGDQS6L5gF3qjeeLa1urfOlEYspwDOhSbnqpNTlQjQ4Ickbphb8Olk4v2bKMm2O8tHqMg4OWpiwKkjrmxwzYDIAhCJfiEcl4URC9Rg5pEBBPgIGbpLpi%2FOPmPZzb6xsU5TlT%2FCpDjSYAosCT%2FeMUcFivoGyb2cjTnPs%2B9AAAAAElFTkSuQmCC"/>';
var gk_inventory = document.getElementById("gk_inventory");
gk_inventory.innerHTML='<i>Retrieving ...</i>';
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='<option value="0">--- Select GeoKret ---</option>';
for (var i = 0; i < len; i++) {
krets=krets+'<option value="'+inventory.list[i].tc+'">'+inventory.list[i].n+'</option>';
}
gk_inventory.innerHTML = '<select id="gk_select" style="width: 100%;margin-top:3px;">'+krets+'</select>';
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 = '<span style="line-height:1.2em;">Your are not logged in on GeoKrety.org. To view your inventory you need to <a href="//'+GKHOST+'/longin.php">log in</a> and then click refresh inventory.</span>';
}
}
}
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 = '<img style="padding:0;border:0;vertical-align:middle;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8%2F9hAAAA8klEQVR42mOcnsLwnwEIMpkYEGAWAyMDkYARZEB6KgMDUy8Dw7kFEEGjAuINQhjQzcAQVqLNsP%2F2fYadwd%2BINghhQA%2FQgGKIAV%2F%2B%2FmWQEBRhWOv6lKBBKF4IK0I1QF5YgEFeSIAhX%2BEowiA0Q4gyQFRMgkFDWJYhxX0CA8MuMgxYWABxAbpmDAPCS3QY9t28Bzfg%2FtSnODViGtAJNKACYsDrxd8wNcZC0gscLIbIIQyoRZLEZiPQgHMzoekkHYsBM2cDU%2BMc7BphTBQD0L2AzwCYRnQAMog%2BBlDmBUKBWB%2FC8P%2FuCwYGZQkGhsY1%2BA3AFo0AdpGZgTxJCIcAAAAASUVORK5CYII%3D" />';
// ------------------------------- 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 = '<table id="table_krets_in_cache" width="100%" cellspacing="2" cellpadding="0" style="line-height:1.2em;margin-bottom:0"></table>';
table_krets_in_cache.innerHTML = tmp;
// ------------------------------- GeoKrety.org inventory -------------------------------
var krets_header = document.createElement('span');
tmp = geokretyorg_header;
krets_header.innerHTML = tmp;
var table_krets_with_me = document.createElement('span');
tmp = '<table width="100%" cellspacing="2" cellpadding="0" style="margin-bottom:0">';
tmp += '<tr><td colspan=2 style="padding:0;line-height:1px">'+pixel_grey+'</td></tr><tr><td style="padding:0;width=16px"><center>'+imgLogGK+'</center></td><td><a id="gk_logkret" href="//'+GKHOST+'/ruchy.php?gkt=log_gc&waypoint='+gcwaypoint+'&lat='+lat+'&lon='+lon+'">Log any GeoKret here</a></td></tr>';
tmp += '<tr><td colspan=2 style="padding:0;line-height:1px">'+pixel_grey+'</td></tr><tr><td colspan=2 id="gk_inventory" style="padding:0"></td></tr>';
tmp += '<tr id="gk_inventory2" style="display:none"><td style="width:16px;padding:2px">'+imgDrop+'</td><td><a id="gk_dropselected" style="cursor:not-allowed">Drop/dip selected GK</a></td></tr>';
tmp += '<tr><td style="width:16px;padding:2px"><center><span id="gk_getinventory_icon">'+imgDrop+'</span></center></td><td><a id="gk_getinventory" style="cursor: pointer">Drop a GK in this cache</a></td></tr>';
tmp += '</table>';
table_krets_with_me.innerHTML = tmp;
var krets_content = document.createElement('div');
krets_content.setAttribute("style","border:"+border_style+";padding:2px 2px");
krets_content.appendChild(prefix_krets_in_cache);
krets_content.appendChild(table_krets_in_cache);
krets_content.appendChild(table_krets_with_me);
// ------------------------------- -------------------------------
var lnk = document.getElementById("ctl00_ContentBody_lnkTravelBugs");
lnk = getRealNextSibling(lnk);
lnk.appendChild(krets_header);
lnk.appendChild(krets_content);
document.getElementById("gk_getinventory").addEventListener("click", gk_getinventory, false);
// ------------------------------- -------------------------------
//if (latlon.textContent.match(regex)) {
window.gk_searchgeokrets();
//}
}
window.gk_searchgeokrets = function() {
var imgGK = '<img style="padding:0;border:0;vertical-align:middle;" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAXCAYAAAAC9s%2FZAAACtUlEQVR42o2UXUiTURjH%2F6%2BZ5tAQS0tDp25Wa4VNUSnc%2BhANcnPqndiXldo00KTVVAq8sfkRJgnlEm%2BaXiRmfrVZDdLh9SAmZJtZrC7KXLJprmiuM0tpH8d64Lwv73mf%2F%2B%2Bc838ODwN6uLy%2BGX9JDE3ocnnqGYbxq%2FEGuLyFPiv%2BBvmlrYstFgva2%2B5geHAQISwWcsVilFw4Dy6X6wNh%2FK1cKC3Ek6EBREVsw9LyMri79yAtIw0KhQKJCQkeEB%2BATvcC0lwJAoODwQphwelwIEsihpjswvblMy5VXt4Y0NvTi%2BJTxYiM3oXqwnzEfLNDbX6HvKIiGPoe4WptLfjZ2XTAyPAIJFIpMlMOQi8twNfGBryqb0D3%2B1kYurpw%2F4EKhy%2BW0gH6iQnk5JxAXDwHk%2FIa%2FNBpYD1bip%2BcRMBqBZd4EBoZSQf0qNU4d%2FoM0kRC1F%2BXI%2FekGAbjFBzfHTiUmupTTg%2FAjNkMWVk5nCsuBGwOxNbwMPT39cNmt6Ot5Tau1FSTuXA6QNl4C61NTSiXyXC3vR11N29AQUxzh6qzE5kiEfbxeHTAkUwhXE4nOElJGB4dxVPNKBbtizielQXds%2Bd4bTahsqKCDuDEJ2B7RASSBQKoH6oRExMN68ICZGRHPD4fk8Tge6rOjQFL5Lxs4nR5WRm0Wi36Bh7jAH8%2FlEolXo6Po7mlmQ4QJCfjo%2BUDbDYb3szOIC42DmNjWgQFbQGbzcYUqYYkT0wH1Clq0dTaihXnCkoqZeju6Fgv25BGg%2FTUFOyM2kEHmE0myKuq8JYkC9yTGekI5e0Fa9oEyTU5RPkFG98Do9EI5%2Fw8prtUCJubgyEoGJ%2FI4G4KQOzRY8gnZtIA%2F9VMvMXeDWUVMkFK5Q6hUOjxQ6%2FXr75F5DKB0pHWIe7HGmgt%2Fgh9NH477d%2Bgf%2BX%2BAio4KictimHrAAAAAElFTkSuQmCC"/>';
var prefix_krets_in_cache = document.getElementById("prefix_krets_in_cache");
prefix_krets_in_cache.innerHTML = '<i>Retrieving ...</i>';
var xhr = new XMLHttpRequest();
var url = "//"+GKHOST+"/gkt/search_v3.php?mode=latlon&lat="+lat+"&lon="+lon;
xhr.onerror = function() {
/*debug('Request failed with ' + xhr.status + ' ' + xhr.statusText + '\nData:\n' + xhr.responseText);*/
prefix_krets_in_cache.innerHTML = 'Error retrieving data. <a id="gk_searchgeokrets" style="cursor: pointer">Try again</a>';
document.getElementById("gk_searchgeokrets").addEventListener("click", gk_searchgeokrets, false);
}
xhr.onload = function() {
/*debug('Request returned ' + xhr.status + ' ' + xhr.statusText + '\nData:\n|' + xhr.responseText +'|');*/
var gk = JSON.parse(this.responseText);
/*debug("geokrety:",gk.length); for(var att in gk) { if (gk.hasOwnProperty(att)) { debug(gk[att]); } }*/
prefix_krets_in_cache.innerHTML = '';
var krets='';
if (gk.length>0)
for (var i=gk.length-1; i>=0; i--) {
krets='<tr><td style="width:16px;padding:2px">'+imgGK+'</td><td><a href="//'+GKHOST+'/konkret.php?id='+gk[i].id+'" target="_blank">' + gk[i].n + '</a></td></tr>'+krets;
}
else { krets='<tr><td>No geokrets in this cache.</td></tr>'; }
document.getElementById("table_krets_in_cache").innerHTML=krets;
}
xhr.overrideMimeType('text/plain');
xhr.open("GET", url, true);
xhr.send(null);
}
function init() {
debug('Toolbox starting!');
var tmp, url, cond1, cond2;
url = window.location.href;
debug('Checking URL...');
regex = /https?:\/\/www\.geocaching\.com\/geocache\/GC/;
if (url.match(regex)) {
debug('Match found');
debug('Checking if user is logged in...');
tmp = document.getElementById("ctl00_ContentBody_trNotLoggedIn");
if (tmp != null) {
debug('User is not logged in!');
var krets_header = document.createElement('span');
krets_header.innerHTML = geokretyorg_header+'<div style="border:'+border_style2+';padding:5px 5px">Please log in :)</div>';
tmp = document.getElementById("ctl00_ContentBody_lnkTravelBugs");
if (tmp != null) {
tmp = getRealNextSibling(tmp);
tmp.appendChild(krets_header);
}
debug('Exiting');
return;
}
debug('User is logged in');
debug('Searching for waypoint code...');
if (document.getElementById('ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoCode').textContent.match(/(GC[A-Z0-9]+)/)) { gcwaypoint=RegExp.$1; cond1=true; debug('Waypoint found'); }
else { gcwaypoint=''; cond1=false; debug('Waypoint not found');}
debug('Searching for coordinates...');
if (document.evaluate("//script[contains(., 'MapTilesEnvironment')]", document).iterateNext().textContent.match(/oldLatLngDisplay":"([NS])\s(\d{1,3}).\s(\d{1,2})\.(\d{3}).\s([EW])\s(\d{1,3}).\s(\d{1,2})\.(\d{3})."/)) { cond2=true; debug('Coordinates found'); }
else { cond2=false; debug('Coordinates not found'); }
if ( !cond1 || !cond2 ) {
var krets_header = document.createElement('span');
tmp = geokretyorg_header+'<div style="border:'+border_style2+';padding:5px 5px">';
if (!cond1) { tmp += 'Waypoint not found<br/>'; }
if (!cond2) { tmp += 'Coordinates not found<br/>'; }
tmp += '</div>';
krets_header.innerHTML = tmp;
var lnk = document.getElementById("ctl00_ContentBody_lnkTravelBugs");
if (lnk != null) {
lnk = getRealNextSibling(lnk);
lnk.appendChild(krets_header);
}
return;
}
lat = parseFloat(RegExp.$2) + (parseFloat(RegExp.$3) + (parseFloat(RegExp.$4)/1000))/60;
if (RegExp.$1 == 'S') {lat = -1 * lat;}
lat = Math.round(lat*100000)/100000;
debug("lat="+lat);
lon = parseFloat(RegExp.$6) + (parseFloat(RegExp.$7) + (parseFloat(RegExp.$8)/1000))/60;
if (RegExp.$5 == 'W') {lon = -1 * lon;}
lon = Math.round(lon*100000)/100000;
debug("lon="+lon);
go();
}
else
{
debug('Match not found!');
}
}
function getRealNextSibling(ele) {
ele = ele.nextSibling;
while (ele.nodeType !=1) { ele = ele.nextSibling; }
return ele;
}
function debug(s) {
if (DEBUG && console) {
unsafeWindow.console.log('GKT: '+s);
}
}
init();