/* global $: true */
/* global waitForKeyElements: true */
/* global GM_xmlhttpRequest: true */
/* global GM_getValue: true */
/* global GM_setValue: true */
/* global unsafeWindow: true */
// jshint newcap:false
// jshint multistr:true
// ==UserScript==
// @author Ground Zero Communications AB
// @license The MIT License (MIT)
// @name Geocaching.com + Project-GC
// @namespace PGC
// @description Adds links and data to Geocaching.com to make it collaborate with PGC
// @icon https://project-gc.com/favicon-32x32.png
// @include http://www.geocaching.com/*
// @include https://www.geocaching.com/*
// @exclude https://www.geocaching.com/profile/profilecontent.html
// @version 2.3.11
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
// @require https://greasyfork.org/scripts/383527-wait-for-key-elements/code/Wait_for_key_elements.js?version=701631
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant GM.xmlHttpRequest
// @grant GM.setValue
// @grant GM.getValue
// @connect maps.googleapis.com
// @connect project-gc.com
// @connect img.geocaching.com
// @connect s3.amazonaws.com
// @connect nominatim.openstreetmap.org
// @connect *
// @downloadURL none
// ==/UserScript==
/*
MIT License
Copyright (c) 2014 Ground Zero Communications AB
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function() {
'use strict';
var pgcUrl = 'https://project-gc.com/',
cdnDomain = 'https://cdn2.project-gc.com/',
pgcApiUrl = pgcUrl + 'api/gm/v1/',
externalLinkIcon = 'https://cdn2.project-gc.com/images/external_small.png',
galleryLinkIcon = 'https://cdn2.project-gc.com/images/pictures_16.png',
challengeCheckerSuccessIcon = 'https://cdn2.project-gc.com/images/check16.png',
challengeCheckerFailIcon = 'https://cdn2.project-gc.com/images/cancel16.png',
mapLinkIcon = 'https://cdn2.project-gc.com/images/map_app_16.png',
loggedIn = null,
subscription = null,
pgcUsername = null,
gccomUsername = null,
latestLogs = [],
latestLogsAlert = false,
settings = {},
path = window.location.pathname,
challengeCheckerResults = null;
// Don't run the script for iframes
if (window.top == window.self) {
Main();
}
function Main() {
ReadSettings();
CheckPGCLogin();
}
function Router() {
if (path.match(/^\/geocache\/.*/) !== null) {
Page_CachePage();
} else if (path.match(/^\/seek\/cache_details\.aspx.*/) !== null) {
Page_CachePage();
} else if (path.match(/^\/seek\/cache_logbook\.aspx.*/) !== null) {
Page_Logbook();
} else if (path.match(/^\/bookmarks\/.*/) !== null) {
Page_Bookmarks();
} else if (path.match(/^\/map\/.*/) !== null) {
Page_Map();
} else if(path.match(/^\/seek\/gallery\.aspx.*/) !== null) {
Page_Gallery();
} else if(path.match(/^\/profile\/.*/) !== null) {
Page_Profile();
} else if (path.match(/^\/account\/drafts/) !== null) {
Page_Drafts();
} else if (path.match(/^\/account\/messagecenter/) !== null) {
Page_Messagecenter();
} else if (path.match(/^\/seek\/cdpf\.aspx/) !== null) {
Page_PrintCachePage();
}
}
function GetSettingsItems() {
var items = {
showVGPS: {
title: 'Show Virtual GPS',
default: true
},
addChallengeCheckers: {
title: 'Add challenge checkers',
default: true
},
makeCopyFriendly: {
title: 'Make copy friendly GC-Code and link',
default: true
},
addPgcMapLinks: {
title: 'Add PGC map links',
default: true
},
addLatestLogs: {
title: 'Add latest logs',
default: true
},
cloneLogsPerType: {
title: 'Clone number of logs per type',
default: true
},
addPGCLocation: {
title: 'Add PGC Location',
default: true
},
addAddress: {
title: 'Add OSM reverse geocoded address',
default: true
},
removeUTM: {
title: 'Remove UTM coordinates',
default: true
},
addPgcFp: {
title: 'Add FP from PGC',
default: true
},
showWeekday: {
title: 'Show weekday of the place date',
default: true
},
profileStatsLinks: {
title: 'Add links to Profile stats',
default: true
},
tidy: {
title: 'Tidy the web a bit',
default: true
},
collapseDownloads: {
title: 'Collapse download links',
default: false
},
addPgcGalleryLinks: {
title: 'Add links to PGC gallery',
default: true
},
addMapBookmarkListLinks: {
title: 'Add links for bookmark lists',
default: true
},
decryptHints: {
title: 'Automatically decrypt hints',
default: true
},
addElevation: {
title: 'Add elevation',
default: true
},
imperial: {
title: 'Use imperial units',
default: false
},
removeDisclaimer: {
title: 'Remove disclaimer',
default: false
},
parseExifLocation: {
title: 'Parse Exif location',
default: true
},
addGeocacheLogsPerProfileCountry: {
title: 'Geocachelogs per profile country',
default: true
},
openDraftLogInSameWindow: {
title: 'Open Compose Log entries in Drafts in same window',
default: true
},
cachenoteFont: {
title: 'Change personal cache note font to monospaced',
default: true
},
logbookLinks: {
title: 'Add links to logbook tabs',
default: true
},
addMyNumberOfLogs: {
title: 'Add my number of logs above log button',
default: true
},
hideMapFromPrintCachePage: {
title: 'Hide map from print cache page',
default: true
},
addCachedChallengeCheckerResults: {
title: 'Add icons for cached Challenge checker results',
default: true
},
hideLogVoting: {
title: 'Hide log upvote buttons and sorting options',
default: false
}
};
return items;
}
async function ReadSettings() {
settings = await GM.getValue('settings');
if (typeof(settings) != 'undefined') {
settings = JSON.parse(settings);
if (settings === null) {
settings = [];
}
} else {
settings = [];
}
var items = GetSettingsItems();
for (var item in items) {
if (typeof(settings[item]) == 'undefined') {
settings[item] = items[item].default;
}
}
}
function SaveSettings(e) {
e.preventDefault();
settings = {};
for (var item in GetSettingsItems()) {
settings[item] = Boolean($('#pgcUserMenuForm input[name="' + item + '"]').is(':checked'));
}
var json = JSON.stringify(settings);
GM.setValue('settings', json);
$('#pgcUserMenuWarning').css('display', 'inherit');
}
function IsSettingEnabled(setting) {
return settings[setting];
}
function MetersToFeet(meters) {
return Math.round(meters * 3.28084);
}
function FormatDistance(distance) {
distance = parseInt(distance, 10);
distance = IsSettingEnabled('imperial') ? MetersToFeet(distance) : distance;
distance = distance.toLocaleString();
return distance;
}
function GetCoordinatesFromExif(exif) {
var GPSLatitudeRef = EXIF.getTag(exif, "GPSLatitudeRef"),
GPSLatitude = EXIF.getTag(exif, "GPSLatitude"),
GPSLongitudeRef = EXIF.getTag(exif, "GPSLongitudeRef"),
GPSLongitude = EXIF.getTag(exif, "GPSLongitude");
if (typeof(GPSLatitude) === 'undefined' || isNaN(GPSLatitude[0]) || isNaN(GPSLatitude[1]) || isNaN(GPSLatitude[1]) ||
isNaN(GPSLongitude[0]) || isNaN(GPSLongitude[1]) || isNaN(GPSLongitude[1])) {
return false;
}
// Create a latitude DD.DDD
var tmp = Number(GPSLatitude[0]) + Number(GPSLatitude[1]) / 60 + Number(GPSLatitude[2]) / 60 / 60,
coords = '';
coords += GPSLatitudeRef;
var d = Math.floor(tmp);
if (d < 10) {
coords += '0' + d;
} else {
coords += d;
}
tmp = (tmp - d) * 60;
coords += ' ' + padLeft(tmp.toFixed(3), 6);
coords += ' ';
// Create a longitude DD.DDD
var tmp = Number(GPSLongitude[0]) + Number(GPSLongitude[1]) / 60 + Number(GPSLongitude[2]) / 60 / 60;
coords += GPSLongitudeRef;
var d = Math.floor(tmp);
if (d < 10) {
coords += '00' + d;
} else if (GPSLongitude[0] < 100) {
coords += '0' + d;
} else {
coords += d;
}
tmp = (tmp - d) * 60;
coords += ' ' + padLeft(tmp.toFixed(3), 6);
return coords;
}
/**
* Check that we are authenticated at Project-GC.com, and that it's with the same username
*/
function CheckPGCLogin() {
GM.xmlHttpRequest({
method: "GET",
url: pgcApiUrl + 'GetMyUsername',
onload: function(response) {
var result = JSON.parse(response.responseText);
if (result.status !== 'OK') {
alert(response.responseText);
return false;
}
pgcUsername = result.data.username;
loggedIn = Boolean(result.data.loggedIn);
subscription = Boolean(result.data.subscription);
function waitForHeader(waitCount) {
if ($('.user-menu')[0]) BuildPGCUserMenu();
else {waitCount++; if (waitCount <= 1000) setTimeout(function(){waitForHeader(waitCount);}, 10);}
}
waitForHeader(0);
Router();
},
onerror: function(response) {
alert(response);
return false;
}
});
}
function BuildPGCUserMenu() {
var loggedInContent, subscriptionContent = '';
gccomUsername = false;
if ($('.username')[0]) {
gccomUsername = $('.username').html();
}
if (loggedIn === false) {
loggedInContent = 'Not logged in';
} else {
loggedInContent = '' + pgcUsername + '';
subscriptionContent = '' + (subscription ? 'Paid' : 'Missing') + ' membership';
}
GM_addStyle('\
#pgc .player-profile, #pgc_gclh .li-user-info {width: auto;}\
#pgc .player-profile:hover {text-decoration: none;}\
#pgc .player-profile a:hover {text-decoration: underline;}\
#pgc .player-profile a {text-decoration: none;color: white;}\
#pgc_gclh img:hover {cursor:pointer;}\
#pgc_gclh .draft-indicator {display: none;}\
#pgcUserMenuForm > li:hover, #pgcUserMenuForm_gclh > li:hover { background-color: #e3dfc9; }\
#pgcUserMenuForm > li, #pgcUserMenuForm_gclh > li { display: block; }\
#pgcUserMenuForm input[type="checkbox"], #pgcUserMenuForm_gclh input[type="checkbox"] { opacity: inherit; width: inherit; height:inherit; overflow:inherit; position:inherit; }\
#pgcUserMenuForm button, #pgcUserMenuForm_gclh button { display: inline-block !important; background: #ede5dc url(images/ui-bg_flat_100_ede5dc_40x100.png) 50% 50% repeat-x !important; border: 1px solid #cab6a3 !important; border-radius: 4px; color: #584528 !important; text-decoration: none; width: auto !important; font-size: 14px; padding: 4px 6px !important;}\
#pgcUserMenuForm button:hover, #pgcUserMenuForm_gclh button:hover { background: #e4d8cb url(images/ui-bgflag_100_e4d8cb_40x100.png) 50% 50% repeat-x !important; }\
#pgcUserMenu, #pgcUserMenu_gclh { right: 19rem; }\
#pgcUserMenu > form, #pgcUserMenu_gclh > form { background-color: white; color: #5f452a; }\
.profile-panel .li-user-info {min-width: 160px;}\
');
var settings = '
\
';
let pgc = '
' + $('#gc-header .player-profile').html() + '
';
$('.user-menu').prepend(pgc);
// Icon
$('#pgc div').prepend('');
$('#pgc img').attr('src', 'https://cdn2.project-gc.com/favicon.ico');
$('#pgc img').attr('style', 'border-radius:100%;');
$('#pgc img').appendTo('#pgc a');
// Username
$('#pgc .username').html(loggedInContent);
// Subscription
$('#pgc .username + span').html(subscriptionContent);
// Menu Toggle
let button = $('.toggle-user-menu').last().parent().clone();
$(button).find('button').attr('id', 'pgcUserMenuButton');
$(button).attr('id', 'pgcButton');
$(button).append(settings);
// Add Toggle Button
$('#pgc').after(button);
$("#pgcUserMenuButton").click(function(e) {
$('#pgcUserMenu').show();
})
$('body').click(function(e) {
if (!$(e.target).parents('#pgcUserMenu')[0] && (!$(e.target).parents('#pgcButton')[0] && $("#pgcUserMenu").css('display') != 'none')) {
$("#pgcUserMenu").hide();
}
})
$('#pgcUserMenuSave').click(function(e) {
SaveSettings(e);
});
// Workaround for users that also use the GClh
function checkForGClh(waitCount) {
if ($('#GClh_II_running')[0] && $('gclh_nav#ctl00_gcNavigation')[0]) {
let gclh_pgc = '
' + $($('.li-user')[0]).find('a').html() + '
'
+ ''
+ settings + '
';
$('#ctl00_uxLoginStatus_divSignedIn').prepend(gclh_pgc);
// Icon
$('#pgc_gclh img').attr('src', 'https://cdn2.project-gc.com/favicon.ico');
$('#pgc_gclh img').attr('style', 'border-radius:100%;');
$('#pgc_gclh img')[0].onclick = function() {open(pgcUrl);};
// User
$('#pgc_gclh .user-name').html(loggedInContent);
// Subscription
$('#pgc_gclh .cache-count').html(subscriptionContent);
// Rename the settings
$('#pgc_gclh .dropdown-menu.menu-user').attr('id', 'pgcUserMenu_gclh');
$('#pgc_gclh .dropdown-menu.menu-user form').attr('id', 'pgcUserMenuForm_gclh');
$('#pgc_gclh .dropdown-menu.menu-user form li:nth-last-child(2) button:nth-last-child(1)').attr('id', 'pgcUserMenuSave_gclh');
$('#pgc_gclh .dropdown-menu.menu-user form li:nth-last-child(1)').attr('id', 'pgcUserMenuWarning_gclh');
$("#pgcUserMenuButton_gclh").click(function(e) {
$('#pgcUserMenu_gclh').toggle();
})
$('#pgcUserMenuSave_gclh').click(function(e) {
SaveSettings(e);
});
} else {waitCount++; if (waitCount <= 1000) setTimeout(function(){checkForGClh(waitCount);}, 10);}
}
checkForGClh(0);
}
/**
* getGcCodeFromPage
* @return string
*/
function getGcCodeFromPage() {
return $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoCode').html();
}
/**
* addToVGPS
*/
function addToVGPS(gccode) {
var listId = $('#comboVGPS').val(),
url = null;
if (typeof(gccode) === 'undefined') { // The map provides the gccode itself
gccode = getGcCodeFromPage();
}
url = pgcApiUrl + 'AddToVGPSList?listId=' + listId + '&gccode=' + gccode + '§ionName=GM-script';
GM.xmlHttpRequest({
method: "GET",
url: url,
onload: function(response) {
var result = JSON.parse(response.responseText),
msg = (result.status === 'OK') ? 'Geocache added to Virtual-GPS!' : 'Geocache not added to Virtual-GPS :(';
$('#btnAddToVGPS').css('display', 'none');
$('#btnRemoveFromVGPS').css('display', '');
alert(msg);
return true;
},
onerror: function(response) {
console.log(response);
return false;
}
});
return true;
}
/**
* removeFromVGPS
*/
function removeFromVGPS(gccode) {
var listId = $('#comboVGPS').val(),
url = null;
if (typeof(gccode) === 'undefined') { // The map provides the gccode itself
gccode = getGcCodeFromPage();
}
url = pgcApiUrl + 'RemoveFromVGPSList?listId=' + listId + '&gccode=' + gccode;
GM.xmlHttpRequest({
method: "GET",
url: url,
onload: function(response) {
var result = JSON.parse(response.responseText),
msg = (result.status === 'OK') ? 'Geocache removed from Virtual-GPS!' : 'Geocache not removed from Virtual-GPS :(';
$('#btnAddToVGPS').css('display', '');
$('#btnRemoveFromVGPS').css('display', 'none');
alert(msg);
return true;
},
onerror: function(response) {
console.log(response);
return false;
}
});
}
function Page_Profile() {
// Override gc.com function on alerting for external links to not alert for Project-GC URLs
var gcAlertOverride = document.createElement('script');
gcAlertOverride.type = "text/javascript";
gcAlertOverride.innerHTML = `(function() {
var _old_isGeocachingDomain = isGeocachingDomain;
isGeocachingDomain = function(url) {
return (_old_isGeocachingDomain.apply(this, arguments)
|| url == "project-gc.com"
|| url == "www.project-gc.com");
};
})();`;
document.getElementsByTagName('head')[0].appendChild(gcAlertOverride);
}
/**
* Page_CachePage
*/
function Page_CachePage() {
var gccode = getGcCodeFromPage(),
placedBy = $('#ctl00_ContentBody_mcd1 a').html(),
lastUpdated = $('#ctl00_ContentBody_bottomSection p small time').get(1),
lastFound = $('#ctl00_ContentBody_bottomSection p small time').get(2),
coordinates, latitude, longitude, url;
lastUpdated = (lastUpdated) ? lastUpdated.dateTime : false;
lastFound = (lastFound) ? lastFound.dateTime : false;
if (subscription) {
// Get geocache data from Project-GC
url = pgcApiUrl + 'GetCacheDataFromGccode&gccode=' + gccode;
if (lastUpdated) {
url += '&lastUpdated=' + lastUpdated;
}
if (lastFound) {
url += '&lastFound=' + lastFound;
}
GM.xmlHttpRequest({
method: "GET",
url: url,
onload: function(response) {
var result = JSON.parse(response.responseText),
cacheData = result.data.cacheData,
bearing = result.data.bearing,
cacheOwner = result.data.owner,
challengeCheckerTagIds = result.data.challengeCheckerTagIds,
geocacheLogsPerCountry = result.data.geocacheLogsPerCountry,
myNumberOfLogs = result.data.myNumberOfLogs,
location = [],
fp = 0,
fpp = 0,
fpw = 0,
elevation = '',
html = '';
challengeCheckerResults = result.data.challengeCheckerResults;
// Add an alert in top if there are Found it-logs which doesn't seem to fulfill the requirements
if(challengeCheckerResults !== false) {
var suspiciousFoundItLogs = [];
for(var logId in challengeCheckerResults) {
if(typeof challengeCheckerResults[logId] !== 'undefined' && challengeCheckerResults[logId]['status'] == 'fail') {
suspiciousFoundItLogs.push(logId);
}
}
if(suspiciousFoundItLogs.length != 0) {
var suspiciousFoundItLog = '
Cache Issues:
\
\
The following Found it logs might not fulfill the requirements: ';
for(var i = 0 ; i < suspiciousFoundItLogs.length ; i++) {
suspiciousFoundItLog = suspiciousFoundItLog + ' ' + challengeCheckerResults[suspiciousFoundItLogs[i]]['profileName'] + ' ';
}
suspiciousFoundItLog = suspiciousFoundItLog + 'Please understand that the checker result is a cached result. Also the geocacher might very well have fulfilled it in the past, external factors might have changed.
';
$('div.span-6.right.last').last().next().after(suspiciousFoundItLog);
}
}
//--
if (result.status == 'OK' && typeof cacheData !== 'undefined') {
// If placed by != owner, show the real owner as well.
if (placedBy !== cacheOwner) {
$('#ctl00_ContentBody_mcd1 span.message__owner').before(' (' + cacheOwner + ')');
}
// Append link to Profile Stats for the cache owner
// Need to real cache owner name from PGC since the web only has placed by
if (IsSettingEnabled('profileStatsLinks')) {
$('#ctl00_ContentBody_mcd1 span.message__owner').before('');
}
// Add FP/FP%/FPW below the current FP + mouseover for FP% and FPW with decimals
if (IsSettingEnabled('addPgcFp')) {
fp = (+cacheData.favorite_points),
fpp = (+cacheData.favorite_points_pct),
fpw = (+cacheData.favorite_points_wilson);
$('#uxFavContainerLink').append('
';
for (var i = 0; i < challengeCheckerTagIds.length; i++) {
html += '';
}
html += '
';
$('#ctl00_ContentBody_detailWidget').before(html);
}
// Display warning message if cache is logged and no longer be logged
if (cacheData.locked) {
$('ul.OldWarning').append('
This cache has been locked and can no longer be logged.
');
}
// Add geocache logs per profile country table
if (IsSettingEnabled('addGeocacheLogsPerProfileCountry')) {
html = '
';
html += '' + geocacheLogsPerCountry['willAttend'].length + ' unique countries';
html += 'Event statistics';
}
if(typeof(geocacheLogsPerCountry['found']) != 'undefined' && geocacheLogsPerCountry['found'].length > 0) {
html += '
Found logs per country according to Project-GC.com
';
html += '
';
for (var i = 0; i < geocacheLogsPerCountry['found'].length; i++) {
html += '
' + geocacheLogsPerCountry['found'][i].cnt + '
';
}
html += '
';
html += '' + geocacheLogsPerCountry['found'].length + ' unique countries';
}
html += '
';
$('#ctl00_ContentBody_lblFindCounts').append(html);
}
// Add my number of logs above the log button
if (IsSettingEnabled('addMyNumberOfLogs')) {
$('
You have ' + myNumberOfLogs + ' logs according to Project-GC
').insertBefore('#ctl00_ContentBody_GeoNav_logButton');
}
// Append the same number to the added logbook link
if (IsSettingEnabled('logbookLinks')) {
$('#pgc-logbook-yours').html('Yours (' + myNumberOfLogs + ')')
}
}
// Since everything in the logbook is ajax, we need to wait for the elements
// We also want to wait on challengeCheckerResults
waitForKeyElements('#cache_logs_table tbody tr', Logbook);
}
});
}
// Add weekday of place date
if (IsSettingEnabled('showWeekday')) {
var match = $('meta[name="description"]')[1].content.match(/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/);
if (match) {
var date = new Date(match[3], match[1]-1, match[2]);
var weekday = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var text = $($('#ctl00_ContentBody_mcd2')[0].childNodes[0]).text();
var pos = text.indexOf(':') + 2;
var newText = text.substring(0, pos);
newText += weekday[date.getDay()] + ', ';
newText += text.substring(pos, text.length);
var newNode = document.createTextNode(newText);
$('#ctl00_ContentBody_mcd2')[0].replaceChild(newNode, $('#ctl00_ContentBody_mcd2')[0].childNodes[0]);
}
}
// Tidy the web
if (IsSettingEnabled('tidy')) {
$('#ctl00_divContentMain p.Clear').css('margin', '0');
$('div.Note.PersonalCacheNote').css('margin', '0');
$('h3.CacheDescriptionHeader').remove();
$('#ctl00_ContentBody_EncryptionKey').remove();
$('#ctl00_ContentBody_GeoNav_foundStatus').css('margin-bottom', '0');
}
// Make it easier to copy the gccode
if (IsSettingEnabled('makeCopyFriendly')) {
$('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').
html('
' + gccode + '
' +
'
');
$('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').css('font-weight', 'inherit').css('margin-right', '27px');
$('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel div input').css('padding', '0');
$('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel div').css('margin', '0 0 5px 0');
$('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel div p').css('font-weight', 'bold');
}
// Add PGC Map links
if (IsSettingEnabled('addPgcMapLinks')) {
coordinates = $('#ctl00_ContentBody_MapLinks_MapLinks li a').attr('href'),
latitude = coordinates.replace(/.*lat=([^&]*)&lng=.*/, "$1"),
longitude = coordinates.replace(/.*&lng=(.*)$/, "$1");
// var mapUrl = pgcUrl + 'Maps/mapcompare/?profile_name=' + gccomUsername +
// '&nonefound=on&ownfound=on&location=' + latitude + ',' + longitude +
// '&max_distance=5&submit=Filter';
var mapUrl = pgcUrl + 'LiveMap/#c=' + latitude + ',' + longitude + ';z=14';
// $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').append(
// '
'
);
}
// Remove the UTM coordinates
// $('#ctl00_ContentBody_CacheInformationTable div.LocationData div.span-9 p.NoBottomSpacing br').remove();
if (IsSettingEnabled('removeUTM')) {
$('#ctl00_ContentBody_LocationSubPanel').html('');
// And move the "N 248.3 km from your home location"
$('#ctl00_ContentBody_LocationSubPanel').after($('#lblDistFromHome'));
}
// Remove ads
// PGC can't really do this officially
// $('#ctl00_ContentBody_uxBanManWidget').remove();
// Remove disclaimer
if (IsSettingEnabled('removeDisclaimer')) {
$('#divContentMain div.span-17 div.Note.Disclaimer').remove();
}
// If the first log is a DNF, display a blue warning on top of the page
if($('#cache_logs_table tr:first td div.LogDisplayRight strong img').attr('src') === '/images/logtypes/3.png') {
var htmlFirstLogDnf = '
Cache Issues:
\
\
The latest log for this cache is a DNF, please read the log before your own search.
');
}
// Add link to PGC gallery
if (subscription && IsSettingEnabled('addPgcGalleryLinks')) {
var html = ' ';
$('.CacheDetailNavigation ul li:first').append(html);
}
// Add map links for each bookmarklist
if (IsSettingEnabled('addMapBookmarkListLinks')) {
$('ul.BookmarkList li').each(function() {
var guid = $(this).children(':nth-child(1)').attr('href').replace(/.*\?guid=(.*)/, "$1");
var owner = $(this).children(':nth-child(3)').text();
// Add the map link
url = 'https://project-gc.com/Tools/MapBookmarklist?owner_name=' + encodeURIComponent(owner) + '&guid=' + encodeURIComponent(guid);
$(this).children(':nth-child(1)').append(' ');
// Add gallery link for the bookmark list
url = 'https://project-gc.com/Tools/Gallery?bml_owner=' + encodeURIComponent(owner) + '&bml_guid=' + encodeURIComponent(guid) + '&submit=Filter';
$(this).children(':nth-child(1)').append(' ');
// Add profile stats link to the owner
url = 'https://project-gc.com/ProfileStats/' + encodeURIComponent(owner);
$(this).children(':nth-child(3)').append(' ');
});
}
// Decrypt the hint
if (IsSettingEnabled('decryptHints') && $('#ctl00_ContentBody_lnkDH')[0].title == 'Decrypt') {
$('#ctl00_ContentBody_lnkDH')[0].click();
}
// VGPS form
if (IsSettingEnabled('showVGPS')) {
GM.xmlHttpRequest({
method: "GET",
url: pgcApiUrl + 'GetExistingVGPSLists?gccode=' + gccode,
onload: function(response) {
var result = JSON.parse(response.responseText),
vgpsLists = result.data.lists,
selected = result.data.selected,
existsIn = result.data.existsIn,
selectedContent,
existsContent,
html = '
Add to VGPS ',
listId;
html += '';
if (existsIn.indexOf(String(selected)) == -1) {
html += ' ';
html += ' ';
} else {
html += ' ';
html += ' ';
}
html += '
';
$('div.CacheDetailNavigation ul:first').append(html);
$('#comboVGPS').change(function() {
selected = $(this).find(':selected').val();
if (existsIn.indexOf(String(selected)) == -1) {
$('#btnAddToVGPS').css('display', '');
$('#btnRemoveFromVGPS').css('display', 'none');
} else {
$('#btnAddToVGPS').css('display', 'none');
$('#btnRemoveFromVGPS').css('display', '');
}
});
$('#btnAddToVGPS').click(function(event) {
event.preventDefault();
addToVGPS();
});
$('#btnRemoveFromVGPS').click(function(event) {
event.preventDefault();
removeFromVGPS();
});
}
});
}
// Change font in personal cache note to monospaced
if (IsSettingEnabled('cachenoteFont')) {
$("#viewCacheNote,#cacheNoteText").css("font-family", "monospace").css("font-size", "12px");
$("#viewCacheNote").on("DOMSubtreeModified", function() {
$(".inplace_field").css("font-family", "monospace").css("font-size", "12px");
});
}
if (IsSettingEnabled('logbookLinks')) {
$('\
| Yours\
| Friends\'\
').insertAfter( $('#ctl00_ContentBody_uxLogbookLink') );
}
}
function Page_Logbook() {
// Since everything in the logbook is ajax, we need to wait for the elements
waitForKeyElements('#AllLogs tr', Logbook);
waitForKeyElements('#PersonalLogs tr', Logbook);
waitForKeyElements('#FriendLogs tr', Logbook);
}
function Logbook(jNode) {
// Add Profile stats and gallery links after each user
if (IsSettingEnabled('profileStatsLinks')) {
var profileNameElm = $(jNode).find('a.h5');
var profileName = profileNameElm.html();
if (typeof profileName !== 'undefined') {
profileName = profileNameElm.append('')
.append('');
}
}
if(IsSettingEnabled('parseExifLocation')) {
$(jNode).find('ul.LogImagesTable li>a').each(function() {
var url = $(this).attr('href');
var thumbnailUrl = url.replace('/img.geocaching.com/cache/log/large/', '/img.geocaching.com/cache/log/thumb/');
var imgElm = $(this).find('img');
$(imgElm).attr('src', thumbnailUrl);
$(imgElm).removeAttr('width');
$(imgElm).removeAttr('height');
$(imgElm).next().css('vertical-align', 'top');
$(imgElm).load(function() {
EXIF.getData($(imgElm)[0], function() {
// console.log(EXIF.pretty(this));
var coords = GetCoordinatesFromExif(this);
if(coords != false) {
$('EXIF Location: ' + coords + '').insertAfter($(imgElm).parent());
}
});
});
});
}
if(IsSettingEnabled('addCachedChallengeCheckerResults') && typeof(challengeCheckerResults) !== 'undefined' && challengeCheckerResults !== null) {
var classes = $(jNode).attr('class');
var logId = classes.match(/l-[0-9]+/)[0].replace('l-', '');
if(typeof(challengeCheckerResults[logId]) !== 'undefined') {
if(challengeCheckerResults[logId]['status'] == 'success') {
$(jNode).find('div.LogDisplayLeft').first().append('
Checker result ' + challengeCheckerResults[logId]['lastRun'] + ' UTC: