/* global $: true */ /* global unsafeWindow: true */ // ==UserScript== // @name Geocaching.com + GeoLeaks.com // @namespace geoleaks // @version 2.5.9 // @author GeoLeaks Geocaching Forum // @description Add link to geoleaks.com on geocache pages see also: https://geoleaks.com/forum/showthread.php?tid=25207 // @supportURL https://geoleaks.com/forum/showthread.php?tid=25207 // @require https://greasyfork.org/scripts/38445-monkeyconfig/code/MonkeyConfig.js // @include http://www.geocaching.com/geocache/* // @include https://www.geocaching.com/geocache/* // @include https://geoleaks.com/forum/newthread.php?* // @include https://geoleaks.com/forum/search.php* // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @grant GM_addStyle // ==/UserScript== // @require https://raw.github.com/odyniec/MonkeyConfig/master/monkeyconfig.js (function() { 'use strict'; var buttonInfo = { error: { color: '#cc3399', colorHigh: '#ff66cc', text: 'Error!' }, notfound: { color: '#90040b', colorHigh: '#cc0000', text: 'Ask on GeoLeaks' }, solved: { color: '#02874d', colorHigh: '#00b265', text: 'Solved on GeoLeaks' }, unknown: { color: '#12508c', colorHigh : '#0000ff', text: 'Found on GeoLeaks' }, unsolved: { color: '#e98300', colorHigh : '#ffcc00', text: 'Solving on GeoLeaks' }, wait: { color: '#cdcdcd', colorHigh : '#eeeeee', text: 'Searching on GeoLeaks' } // dnf: '#1c3d4c' , // virtual: '#009bbb', }; var regions = { // Netherlands 'Groningen, Netherlands': { fid : 12 }, 'Friesland, Netherlands': { fid : 13 }, 'Drenthe, Netherlands': { fid : 14 }, 'Overijssel, Netherlands': { fid : 15 }, 'Flevoland, Netherlands': { fid : 16 }, 'Gelderland, Netherlands': { fid : 17 }, 'Utrecht, Netherlands': { fid : 18 }, 'Noord-Holland, Netherlands': { fid : 19 }, 'Zuid-Holland, Netherlands': { fid : 20 }, 'Zeeland, Netherlands': { fid : 21 }, 'Noord-Brabant, Netherlands': { fid : 22 }, 'Limburg, Netherlands': { fid : 23 }, // Belgium 'Brussels, Belgium': { fid : 41 }, 'Antwerpen, Belgium': { fid : 42 }, 'Limburg, Belgium': { fid : 43 }, 'West-Vlaanderen, Belgium': { fid : 44 }, 'Oost-Vlaanderen, Belgium': { fid : 45 }, 'Vlaams-Brabant, Belgium': { fid : 46 }, 'Brabant wallon, Belgium': { fid : 47 }, 'Hainaut, Belgium': { fid : 48 }, 'Liège, Belgium': { fid : 49 }, 'Luxembourg, Belgium': { fid : 50 }, 'Namur, Belgium': { fid : 51 }, // Germany 'Bremen, Germany': { fid : 98 }, 'Hamburg, Germany': { fid : 99 }, 'Niedersachsen, Germany': { fid : 100 }, 'Nordrhein-Westfalen, Germany': { fid : 101 }, 'Hessen, Germany': { fid : 102 }, 'Rheinland-Pfalz, Germany': { fid : 103 }, 'Saarland, Germany': { fid : 104 }, 'Schleswig-Holstein, Germany': { fid : 105 }, 'Mecklenburg-Vorpommern, Germany': { fid : 106 }, 'Brandenburg, Germany': { fid : 107 }, 'Berlin, Germany': { fid : 108 }, 'Sachsen-Anhalt, Germany': { fid : 109 }, 'Thüringen, Germany': { fid : 110 }, 'Sachsen, Germany': { fid : 111 }, 'Baden-Württemberg, Germany': { fid : 112 }, 'Bayern, Germany': { fid : 113 }, // Europe 'Andorra' : { fid : 198, cc : 'AD' }, 'Albania' : { fid : 202, cc : 'AL' }, 'Austria' : { fid : 144, cc : 'AT' }, 'Belarus' : { fid : 203, cc : 'BLR' }, 'Bosnia and Herzegovina' : { fid : 204, cc : 'BA' }, 'Bulgaria' : { fid : 174, cc : 'BG' }, 'Croatia' : { fid : 166, cc : 'HR' }, 'Cyprus' : { fid : 196, cc : 'CY' }, 'Czechia' : { fid : 160, cc : 'CZ' }, 'Denmark' : { fid : 137, cc : 'DK' }, 'Estonia' : { fid : 186, cc : 'EE' }, 'Faroe Islands' : { fid : 218, cc : 'FO' }, 'Finland' : { fid : 156, cc : 'FI' }, 'Aland Islands': { fid : 156, cc : 'AX' }, 'France': { fid : 68, cc : 'F' }, 'Monaco': { fid : 68, cc : 'MC' }, 'Gibraltar': { fid : 221, cc : 'GI' }, 'Greece' : { fid : 146, cc : 'GR' }, 'Hungary' : { fid : 162, cc : 'HU' }, 'Iceland' : { fid : 175, cc : 'IS' }, 'Ireland' : { fid : 148, cc : 'IE' }, 'Italy' : { fid : 149, cc : 'IT' }, 'San Marino' : { fid : 149, cc : 'SM' }, 'Vatican City State' : { fid : 149, cc : 'VA' }, 'Latvia' : { fid : 187, cc : 'LV' }, 'Liechtenstein' : { fid : 200, cc : 'LI' }, 'Lithuania' : { fid : 188, cc : 'LT' }, 'Luxembourg': { fid : 66, cc : 'LX' }, 'Malta' : { fid : 172, cc : 'MT' }, 'Montenegro' : { fid : 205, cc : 'ME' }, 'North Macedonia' : { fid : 206, cc : 'MK' }, 'Norway' : { fid : 158, cc : 'NO' }, 'Poland' : { fid : 164, cc : 'PL' }, 'Portugal' : { fid : 154, cc : 'PT' }, 'Romania' : { fid : 194, cc : 'RO' }, 'Russian Federation' : { fid : 207, cc : 'RU' }, 'Serbia' : { fid : 208, cc : 'RS' }, 'Slovakia' : { fid : 170, cc : 'SK' }, 'Slovenia' : { fid : 168, cc : 'SI' }, 'Spain' : { fid : 142, cc : 'ES' }, 'Sweden' : { fid : 139, cc : 'SE' }, 'Switzerland' : { fid : 152, cc : 'CH' }, 'Ukraine' : { fid : 209, cc : 'UA' }, 'United Kingdom': { fid : 87, cc : 'UK' }, 'Guernsey': { fid : 87, cc : 'GG' }, 'Jersey': { fid : 87, cc : 'JE' }, 'Isle of Man': { fid : 87, cc : 'IM' }, // Rest of the world 'Australia' : { fid : 180, cc : 'AU' }, 'Canada' : { fid : 178, cc : 'CA' }, 'New Zealand' : { fid : 184, cc : 'NZ' }, 'South Africa' : { fid : 182, cc : 'SA' }, 'Alabama, United States': { fid : 88, cc : 'AL' }, 'Alaska, United States': { fid : 88, cc : 'AK' }, 'Arizona, United States' : { fid : 88, cc : 'AZ' }, 'Arkansas, United States' : { fid : 88, cc : 'AR' }, 'California, United States' : { fid : 88, cc : 'CA' }, 'Colorado, United States' : { fid : 88, cc : 'CO' }, 'Connecticut, United States' : { fid : 88, cc : 'CT' }, 'Delaware, United States' : { fid : 88, cc : 'DE' }, 'District of Columbia, United States' : { fid : 88, cc : 'DC' }, 'Florida, United States' : { fid : 88, cc : 'FL' }, 'Georgia, United States' : { fid : 88, cc : 'GA' }, 'Hawaii, United States' : { fid : 88, cc : 'HI' }, 'Idaho, United States' : { fid : 88, cc : 'ID' }, 'Illinois, United States' : { fid : 88, cc : 'IL' }, 'Indiana, United States' : { fid : 88, cc : 'IN' }, 'Iowa, United States' : { fid : 88, cc : 'IA' }, 'Kansas, United States' : { fid : 88, cc : 'KS' }, 'Kentucky, United States' : { fid : 88, cc : 'KY' }, 'Louisiana, United States' : { fid : 88, cc : 'LA' }, 'Maine, United States' : { fid : 88, cc : 'ME' }, 'Maryland, United States' : { fid : 88, cc : 'MD' }, 'Massachusetts, United States' : { fid : 88, cc : 'MA' }, 'Michigan, United States' : { fid : 88, cc : 'MI' }, 'Minnesota, United States' : { fid : 88, cc : 'MN' }, 'Mississippi, United States' : { fid : 88, cc : 'MS' }, 'Missouri, United States' : { fid : 88, cc : 'MO' }, 'Montana, United States' : { fid : 88, cc : 'MT' }, 'Nebraska, United States' : { fid : 88, cc : 'NE' }, 'Nevada, United States' : { fid : 88, cc : 'NV' }, 'New Hampshire, United States' : { fid : 88, cc : 'NH' }, 'New Jersey, United States' : { fid : 88, cc : 'NJ' }, 'New Mexico, United States' : { fid : 88, cc : 'NM' }, 'New York, United States' : { fid : 88, cc : 'NY' }, 'North Carolina, United States' : { fid : 88, cc : 'NC' }, 'North Dakota, United States' : { fid : 88, cc : 'ND' }, 'Ohio, United States' : { fid : 88, cc : 'OH' }, 'Oklahoma, United States' : { fid : 88, cc : 'OK' }, 'Oregon, United States' : { fid : 88, cc : 'OR' }, 'Pennsylvania, United States' : { fid : 88, cc : 'PA' }, 'Rhode Island, United States' : { fid : 88, cc : 'RI' }, 'South Carolina, United States' : { fid : 88, cc : 'SC' }, 'South Dakota, United States' : { fid : 88, cc : 'SD' }, 'Tennessee, United States' : { fid : 88, cc : 'TN' }, 'Texas, United States' : { fid : 88, cc : 'TX' }, 'Utah, United States' : { fid : 88, cc : 'UT' }, 'Vermont, United States' : { fid : 88, cc : 'VT' }, 'Virginia, United States' : { fid : 88, cc : 'VA' }, 'Washington, United States' : { fid : 88, cc : 'WA' }, 'West Virginia, United States' : { fid : 88, cc : 'WV' }, 'Wisconsin, United States' : { fid : 88, cc : 'WI' }, 'Wyoming, United States' : { fid : 88, cc : 'WY' }, 'default' : { fid : 70 } }; const GCTYPE_Traditional = 2; const GCTYPE_Multi = 3; const GCTYPE_Virtual = 4; const GCTYPE_Letterbox = 5; const GCTYPE_Mystery = 8; const GCTYPE_Earthcache = 137; const GCTYPE_Wherigo = 1858; const LOGTYPE_Found = 2; const LOGTYPE_Did_not_found = 3; var gctypes = []; gctypes[GCTYPE_Traditional] = { fid : 38 }; gctypes[GCTYPE_Multi] = { fid : 38 }; gctypes[GCTYPE_Virtual] = { fid : 77 }; gctypes[GCTYPE_Letterbox] = { fid : 38 }; // 'Event Cache // 'Unknown Cache // 'Project APE Cache // 'Webcam Cache // 'Cache In Trash Out Event gctypes[GCTYPE_Earthcache] = { fid : 77 }; // 'Mega-Event Cache // 'GPS Adventures Exhibit gctypes[GCTYPE_Wherigo] = { fid : 38 }; // 'Lost and Found Event Cache // 'Groundspeak HQ // 'Groundspeak Lost and Found Celebration // 'Groundspeak Block Party // 'Giga-Event Cache var cfg = new MonkeyConfig({ title: 'Geocaching + Geoleaks Configuration', menuCommand: true, params: { open_in_new_window: { type: 'checkbox', default: false }, } }); var gccode = ''; var gcname = ''; var gctype = 0; var logtype = 0; var region = ''; var coords = ''; var wait = 5000; var link_id = '#linkToGeoLeaks'; var form_id = '#formToGeoLeaks'; function setInputFields() { var params = new URLSearchParams(window.location.search); for (var param of params) { var elems = document.getElementsByName(param[0]); for (var elem of elems) { switch (elem.nodeName) { case 'TEXTAREA' : elem.innerHTML = param[1]; elem.value = param[1]; break; default : elem.value = param[1]; break; } } } } function updateButton(type) { $(link_id) .css('background-color', buttonInfo[type][$(link_id).data('colorState')]) .css('border-color', buttonInfo[type][$(link_id).data('colorState')]) .data('color', buttonInfo[type].color) .data('colorHigh', buttonInfo[type].colorHigh) .html(buttonInfo[type].text) ; } function setHref(href) { $(link_id) .attr('href', href) .attr('target', cfg.get('open_in_new_window') && !href.startsWith('#') ? '_blank' : '_self') ; } function newMessageUrl() { var forumInfo = regions.default; if (gctypes[gctype]) { forumInfo = gctypes[gctype]; } else { for (var key in regions) { if (region.endsWith(key)) { forumInfo = regions[key]; break; } console.debug('Region:' + region); } } var subject = gccode + ' ' + gcname; if (forumInfo.cc) { subject += ' (' + forumInfo.cc + ')'; } var message = 'https://coord.info/' + gccode + "\n" + "\n" + 'https://greasyfork.org/en/scripts/376355-geocaching-com-geoleaks ' + "\n" + "\n" + 'Geeft aan dat er nog geen topic voor deze cache is, wie kan er helpen? Indicates that there is no topic for this cache yet, who can help?' "\n"; return '' + 'https://geoleaks.com/forum/newthread.php?fid=' + forumInfo.fid + '&subject=' + encodeURIComponent(subject) + '&message_new=' + encodeURIComponent(message) + '&message=' + encodeURIComponent(message) ; } function checkGeoleaks() { updateButton('wait'); $.post({ url: "https://geoleaks.com/forum/search.php", data: { 'action' : 'do_search', 'keywords' : gccode, 'postthread' : 2, // Alleen titels doorzoeken 'sortby' : 'lastpost', 'sortordr' : 'asc', }, success: function(result){ var url = result.match(/search.\php\?action=results[^"]*/); if (!url) { if (-1 !== result.indexOf('