/* global $: true */
/* global waitForKeyElements: true */
/* global GM_xmlhttpRequest: true */
/* global GM_getValue: true */
// ==UserScript==
// @name Geocaching.com + Project-GC
// @namespace PGC
// @description Adds links and data to Geocaching.com to make it collaborate with PGC
// @include http://www.geocaching.com/*
// @include https://www.geocaching.com/*
// @version 1.1.4
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
// @require https://greasyfork.org/scripts/5392-waitforkeyelements/code/WaitForKeyElements.js?version=19641
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @license The MIT License (MIT)
// @downloadURL none
// ==/UserScript==
'use strict';
(function() {
var pgcUrl = 'http://project-gc.com/',
pgcApiUrl = pgcUrl + 'api/gm/v1/',
externalLinkIcon = 'http://maxcdn.project-gc.com/images/external_small.png',
loggedIn = GM_getValue('loggedIn'),
subscription = GM_getValue('subscription'),
pgcUsername = GM_getValue('pgcUsername'),
gccomUsername = GM_getValue('gccomUsername'),
latestLogs = [],
path = window.location.pathname;
// Don't run the script for iframes
if (window.top == window.self) {
Main();
}
/**
* Router
*/
function Main() {
CheckPGCLogin();
if (path.match(/^\/geocache\/.*/) !== null) {
CachePage();
} else if (path.match(/^\/seek\/cache_logbook\.aspx.*/) !== null) {
Logbook();
}
}
/**
* Check that we are logged in at PGC, and that it's with the same username
*/
function CheckPGCLogin() {
gccomUsername = $('#ctl00_divSignedIn .li-user-info span').html();
GM_setValue('gccomUsername', gccomUsername);
GM_xmlhttpRequest({
method: "GET",
url: pgcApiUrl + 'GetMyUsername',
onload: function(response) {
var result = JSON.parse(response.responseText),
html, loggedInContent, subscriptionContent = '';
if (result.status !== 'OK') {
alert(response.responseText);
return false;
}
pgcUsername = result.data.username;
loggedIn = !!result.data.loggedIn;
subscription = !!result.data.subscription;
if (loggedIn === false) {
loggedInContent = 'Not logged in';
} else if (pgcUsername == gccomUsername) {
loggedInContent = '' + pgcUsername + '';
} else {
loggedInContent = '' + pgcUsername + '';
}
if (subscription) {
subscriptionContent = 'Paid membersip';
} else {
subscriptionContent = 'Missing membership';
}
html = '\
\
\
\
\
';
if ($('#ctl00_divSignedIn ul')) {
$('#ctl00_divSignedIn ul').prepend('
(' + fp + ' FP, ' + fpp + '%, ' + fpw + 'W)
'); // Add challenge checkers if(challengeCheckerTagIds.length > 0) { var html = ''; html += ''; $('#ctl00_ContentBody_CacheInformationTable').append(html) } } }); } // Make it easier to copy the gccode $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel'). html('' + gccode + '
' + '▼Print and Downloads
').insertAfter('#ctl00_ContentBody_CacheInformationTable div.LocationData'); $('#ctl00_divContentMain div.DownloadLinks').hide(); // Turn the coordinates into an address var coordinates = $('#ctl00_ContentBody_lnkConversions').attr('href'), latitude = coordinates.replace(/.*lat=([^&]*)&lon=.*/, "$1"), longitude = coordinates.replace(/.*&lon=([^&]*)&.*/, "$1"), url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng=' + latitude + ',' + longitude + '&sensor=false'; GM_xmlhttpRequest({ method: "GET", url: url, onload: function(response) { var result = JSON.parse(response.responseText); if (result.status !== 'OK') { return false; } var formattedAddress = result.results[0].formatted_address; $('#ctl00_ContentBody_LocationSubPanel').html(formattedAddress + 'Latest logs: ' + images + '
'); } } } function Logbook() { waitForKeyElements('#AllLogs tr', CachePage_Logbook); } // Not used? // function Logbook_Logbook(jNode) { // CachePage_Logbook(jNode); // } }());