Geocaching.com + Project-GC

Adds links and data to Geocaching.com to make it collaborate with PGC

As of 2021-10-18. See the latest version.

  1. /* global $: true */
  2. /* global waitForKeyElements: true */
  3. /* global GM_xmlhttpRequest: true */
  4. /* global GM_getValue: true */
  5. /* global GM_setValue: true */
  6. /* global unsafeWindow: true */
  7. // jshint newcap:false
  8. // jshint multistr:true
  9.  
  10. // ==UserScript==
  11. // @author Ground Zero Communications AB
  12. // @license The MIT License (MIT)
  13. // @name Geocaching.com + Project-GC
  14. // @namespace PGC
  15. // @description Adds links and data to Geocaching.com to make it collaborate with PGC
  16. // @icon https://project-gc.com/favicon-32x32.png
  17. // @include http://www.geocaching.com/*
  18. // @include https://www.geocaching.com/*
  19. // @exclude https://www.geocaching.com/profile/profilecontent.html
  20. // @version 2.3.11
  21. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
  22. // @require https://greatest.deepsurf.us/scripts/383527-wait-for-key-elements/code/Wait_for_key_elements.js?version=701631
  23. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
  24. // @grant GM_xmlhttpRequest
  25. // @grant GM_setValue
  26. // @grant GM_getValue
  27. // @grant GM_addStyle
  28. // @grant GM.xmlHttpRequest
  29. // @grant GM.setValue
  30. // @grant GM.getValue
  31. // @connect maps.googleapis.com
  32. // @connect project-gc.com
  33. // @connect img.geocaching.com
  34. // @connect s3.amazonaws.com
  35. // @connect nominatim.openstreetmap.org
  36. // @connect *
  37. // ==/UserScript==
  38.  
  39.  
  40. /*
  41. MIT License
  42.  
  43. Copyright (c) 2014 Ground Zero Communications AB
  44.  
  45. 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:
  46.  
  47. The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
  48.  
  49. 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.
  50. */
  51.  
  52. (function() {
  53.  
  54. 'use strict';
  55.  
  56. var pgcUrl = 'https://project-gc.com/',
  57. cdnDomain = 'https://cdn2.project-gc.com/',
  58. pgcApiUrl = pgcUrl + 'api/gm/v1/',
  59. externalLinkIcon = 'https://cdn2.project-gc.com/images/external_small.png',
  60. galleryLinkIcon = 'https://cdn2.project-gc.com/images/pictures_16.png',
  61. challengeCheckerSuccessIcon = 'https://cdn2.project-gc.com/images/check16.png',
  62. challengeCheckerFailIcon = 'https://cdn2.project-gc.com/images/cancel16.png',
  63. mapLinkIcon = 'https://cdn2.project-gc.com/images/map_app_16.png',
  64. loggedIn = null,
  65. subscription = null,
  66. pgcUsername = null,
  67. gccomUsername = null,
  68. latestLogs = [],
  69. latestLogsAlert = false,
  70. settings = {},
  71. path = window.location.pathname,
  72. challengeCheckerResults = null;
  73.  
  74. // Don't run the script for iframes
  75. if (window.top == window.self) {
  76. Main();
  77. }
  78.  
  79. function Main() {
  80. ReadSettings();
  81. CheckPGCLogin();
  82. }
  83.  
  84. function Router() {
  85. if (path.match(/^\/geocache\/.*/) !== null) {
  86. Page_CachePage();
  87. } else if (path.match(/^\/seek\/cache_details\.aspx.*/) !== null) {
  88. Page_CachePage();
  89. } else if (path.match(/^\/seek\/cache_logbook\.aspx.*/) !== null) {
  90. Page_Logbook();
  91. } else if (path.match(/^\/bookmarks\/.*/) !== null) {
  92. Page_Bookmarks();
  93. } else if (path.match(/^\/map\/.*/) !== null) {
  94. Page_Map();
  95. } else if(path.match(/^\/seek\/gallery\.aspx.*/) !== null) {
  96. Page_Gallery();
  97. } else if(path.match(/^\/profile\/.*/) !== null) {
  98. Page_Profile();
  99. } else if (path.match(/^\/account\/drafts/) !== null) {
  100. Page_Drafts();
  101. } else if (path.match(/^\/account\/messagecenter/) !== null) {
  102. Page_Messagecenter();
  103. } else if (path.match(/^\/seek\/cdpf\.aspx/) !== null) {
  104. Page_PrintCachePage();
  105. }
  106. }
  107.  
  108. function GetSettingsItems() {
  109. var items = {
  110. showVGPS: {
  111. title: 'Show Virtual GPS',
  112. default: true
  113. },
  114. addChallengeCheckers: {
  115. title: 'Add challenge checkers',
  116. default: true
  117. },
  118. makeCopyFriendly: {
  119. title: 'Make copy friendly GC-Code and link',
  120. default: true
  121. },
  122. addPgcMapLinks: {
  123. title: 'Add PGC map links',
  124. default: true
  125. },
  126. addLatestLogs: {
  127. title: 'Add latest logs',
  128. default: true
  129. },
  130. cloneLogsPerType: {
  131. title: 'Clone number of logs per type',
  132. default: true
  133. },
  134. addPGCLocation: {
  135. title: 'Add PGC Location',
  136. default: true
  137. },
  138. addAddress: {
  139. title: 'Add OSM reverse geocoded address',
  140. default: true
  141. },
  142. removeUTM: {
  143. title: 'Remove UTM coordinates',
  144. default: true
  145. },
  146. addPgcFp: {
  147. title: 'Add FP from PGC',
  148. default: true
  149. },
  150. showWeekday: {
  151. title: 'Show weekday of the place date',
  152. default: true
  153. },
  154. profileStatsLinks: {
  155. title: 'Add links to Profile stats',
  156. default: true
  157. },
  158. tidy: {
  159. title: 'Tidy the web a bit',
  160. default: true
  161. },
  162. collapseDownloads: {
  163. title: 'Collapse download links',
  164. default: false
  165. },
  166. addPgcGalleryLinks: {
  167. title: 'Add links to PGC gallery',
  168. default: true
  169. },
  170. addMapBookmarkListLinks: {
  171. title: 'Add links for bookmark lists',
  172. default: true
  173. },
  174. decryptHints: {
  175. title: 'Automatically decrypt hints',
  176. default: true
  177. },
  178. addElevation: {
  179. title: 'Add elevation',
  180. default: true
  181. },
  182. imperial: {
  183. title: 'Use imperial units',
  184. default: false
  185. },
  186. removeDisclaimer: {
  187. title: 'Remove disclaimer',
  188. default: false
  189. },
  190. parseExifLocation: {
  191. title: 'Parse Exif location',
  192. default: true
  193. },
  194. addGeocacheLogsPerProfileCountry: {
  195. title: 'Geocachelogs per profile country',
  196. default: true
  197. },
  198. openDraftLogInSameWindow: {
  199. title: 'Open <em>Compose Log</em> entries in <em>Drafts</em> in same window',
  200. default: true
  201. },
  202. cachenoteFont: {
  203. title: 'Change personal cache note font to monospaced',
  204. default: true
  205. },
  206. logbookLinks: {
  207. title: 'Add links to logbook tabs',
  208. default: true
  209. },
  210. addMyNumberOfLogs: {
  211. title: 'Add my number of logs above log button',
  212. default: true
  213. },
  214. hideMapFromPrintCachePage: {
  215. title: 'Hide map from print cache page',
  216. default: true
  217. },
  218. addCachedChallengeCheckerResults: {
  219. title: 'Add icons for cached Challenge checker results',
  220. default: true
  221. },
  222. hideLogVoting: {
  223. title: 'Hide log upvote buttons and sorting options',
  224. default: false
  225. }
  226. };
  227. return items;
  228. }
  229.  
  230. async function ReadSettings() {
  231. settings = await GM.getValue('settings');
  232. if (typeof(settings) != 'undefined') {
  233. settings = JSON.parse(settings);
  234. if (settings === null) {
  235. settings = [];
  236. }
  237. } else {
  238. settings = [];
  239. }
  240.  
  241. var items = GetSettingsItems();
  242. for (var item in items) {
  243. if (typeof(settings[item]) == 'undefined') {
  244. settings[item] = items[item].default;
  245. }
  246. }
  247. }
  248.  
  249. function SaveSettings(e) {
  250. e.preventDefault();
  251. settings = {};
  252.  
  253. for (var item in GetSettingsItems()) {
  254. settings[item] = Boolean($('#pgcUserMenuForm input[name="' + item + '"]').is(':checked'));
  255. }
  256.  
  257. var json = JSON.stringify(settings);
  258. GM.setValue('settings', json);
  259.  
  260. $('#pgcUserMenuWarning').css('display', 'inherit');
  261. }
  262.  
  263. function IsSettingEnabled(setting) {
  264. return settings[setting];
  265. }
  266.  
  267. function MetersToFeet(meters) {
  268. return Math.round(meters * 3.28084);
  269. }
  270.  
  271. function FormatDistance(distance) {
  272. distance = parseInt(distance, 10);
  273. distance = IsSettingEnabled('imperial') ? MetersToFeet(distance) : distance;
  274. distance = distance.toLocaleString();
  275.  
  276. return distance;
  277. }
  278.  
  279. function GetCoordinatesFromExif(exif) {
  280. var GPSLatitudeRef = EXIF.getTag(exif, "GPSLatitudeRef"),
  281. GPSLatitude = EXIF.getTag(exif, "GPSLatitude"),
  282. GPSLongitudeRef = EXIF.getTag(exif, "GPSLongitudeRef"),
  283. GPSLongitude = EXIF.getTag(exif, "GPSLongitude");
  284.  
  285. if (typeof(GPSLatitude) === 'undefined' || isNaN(GPSLatitude[0]) || isNaN(GPSLatitude[1]) || isNaN(GPSLatitude[1]) ||
  286. isNaN(GPSLongitude[0]) || isNaN(GPSLongitude[1]) || isNaN(GPSLongitude[1])) {
  287. return false;
  288. }
  289.  
  290. // Create a latitude DD.DDD
  291. var tmp = Number(GPSLatitude[0]) + Number(GPSLatitude[1]) / 60 + Number(GPSLatitude[2]) / 60 / 60,
  292. coords = '';
  293.  
  294. coords += GPSLatitudeRef;
  295. var d = Math.floor(tmp);
  296. if (d < 10) {
  297. coords += '0' + d;
  298. } else {
  299. coords += d;
  300. }
  301. tmp = (tmp - d) * 60;
  302. coords += ' ' + padLeft(tmp.toFixed(3), 6);
  303.  
  304. coords += ' ';
  305.  
  306. // Create a longitude DD.DDD
  307. var tmp = Number(GPSLongitude[0]) + Number(GPSLongitude[1]) / 60 + Number(GPSLongitude[2]) / 60 / 60;
  308.  
  309. coords += GPSLongitudeRef;
  310. var d = Math.floor(tmp);
  311. if (d < 10) {
  312. coords += '00' + d;
  313. } else if (GPSLongitude[0] < 100) {
  314. coords += '0' + d;
  315. } else {
  316. coords += d;
  317. }
  318. tmp = (tmp - d) * 60;
  319. coords += ' ' + padLeft(tmp.toFixed(3), 6);
  320.  
  321. return coords;
  322. }
  323.  
  324. /**
  325. * Check that we are authenticated at Project-GC.com, and that it's with the same username
  326. */
  327. function CheckPGCLogin() {
  328. GM.xmlHttpRequest({
  329. method: "GET",
  330. url: pgcApiUrl + 'GetMyUsername',
  331. onload: function(response) {
  332. var result = JSON.parse(response.responseText);
  333.  
  334. if (result.status !== 'OK') {
  335. alert(response.responseText);
  336. return false;
  337. }
  338.  
  339. pgcUsername = result.data.username;
  340. loggedIn = Boolean(result.data.loggedIn);
  341. subscription = Boolean(result.data.subscription);
  342.  
  343. function waitForHeader(waitCount) {
  344. if ($('.user-menu')[0]) BuildPGCUserMenu();
  345. else {waitCount++; if (waitCount <= 1000) setTimeout(function(){waitForHeader(waitCount);}, 10);}
  346. }
  347. waitForHeader(0);
  348. Router();
  349. },
  350. onerror: function(response) {
  351. alert(response);
  352. return false;
  353. }
  354. });
  355. }
  356.  
  357. function BuildPGCUserMenu() {
  358. var loggedInContent, subscriptionContent = '';
  359.  
  360. gccomUsername = false;
  361. if ($('.username')[0]) {
  362. gccomUsername = $('.username').html();
  363. }
  364.  
  365. if (loggedIn === false) {
  366. loggedInContent = '<a href="' + pgcUrl + 'User/Login" target="_blank">Not logged in</a>';
  367. } else {
  368. loggedInContent = '<a href="' + pgcUrl + 'ProfileStats/' + pgcUsername + '"><strong' + (pgcUsername != gccomUsername ? ' style="color: red;"' : '') + '>' + pgcUsername + '</strong></a>';
  369. subscriptionContent = '<a href="https://project-gc.com/Home/Membership" target="_blank">' + (subscription ? 'Paid' : 'Missing') + ' membership</a>';
  370. }
  371.  
  372. GM_addStyle('\
  373. #pgc .player-profile, #pgc_gclh .li-user-info {width: auto;}\
  374. #pgc .player-profile:hover {text-decoration: none;}\
  375. #pgc .player-profile a:hover {text-decoration: underline;}\
  376. #pgc .player-profile a {text-decoration: none;color: white;}\
  377. #pgc_gclh img:hover {cursor:pointer;}\
  378. #pgc_gclh .draft-indicator {display: none;}\
  379. #pgcUserMenuForm > li:hover, #pgcUserMenuForm_gclh > li:hover { background-color: #e3dfc9; }\
  380. #pgcUserMenuForm > li, #pgcUserMenuForm_gclh > li { display: block; }\
  381. #pgcUserMenuForm input[type="checkbox"], #pgcUserMenuForm_gclh input[type="checkbox"] { opacity: inherit; width: inherit; height:inherit; overflow:inherit; position:inherit; }\
  382. #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;}\
  383. #pgcUserMenuForm button:hover, #pgcUserMenuForm_gclh button:hover { background: #e4d8cb url(images/ui-bgflag_100_e4d8cb_40x100.png) 50% 50% repeat-x !important; }\
  384. #pgcUserMenu, #pgcUserMenu_gclh { right: 19rem; }\
  385. #pgcUserMenu > form, #pgcUserMenu_gclh > form { background-color: white; color: #5f452a; }\
  386. .profile-panel .li-user-info {min-width: 160px;}\
  387. ');
  388.  
  389. var settings = '<ul id="pgcUserMenu" class="dropdown-menu menu-user submenu" style="display:none; z-index: 1005;"><form id="pgcUserMenuForm" style="display: block; columns: 2; font-size: 14px; background-color: #fff !important;">';
  390.  
  391. var items = GetSettingsItems();
  392. for (var item in items) {
  393. let isChecked = IsSettingEnabled(item) ? ' checked="checked"' : '';
  394. // Explicitly set the styles as some pages (i.e. https://www.geocaching.com/account/settings/profile) are missing the required css.
  395. settings += '<li style="margin: .2em 1em; white-space: nowrap; display: flex;"><label style="font-weight: inherit; margin-bottom: 0" for="' + item + '"><input type="checkbox" id="' + item + '" name="' + item + '"' + isChecked + ' >&nbsp;' + items[item].title + '</label>&nbsp;<small>(default: ' + items[item].default + ')</small></li>';
  396. }
  397.  
  398. settings += '\
  399. <li style="margin: .2em 1em; background: 0;">\
  400. <button onclick="document.getElementById(\'pgcUserMenuForm\').reset(); document.getElementById(\'pgcUserMenu\').style.display=\"none\"; return false;">Cancel</button>\
  401. <button onclick="document.getElementById(\'pgcUserMenuForm\').reset(); return false;">Reset</button>\
  402. <button id="pgcUserMenuSave">Save</button>\
  403. </li>\
  404. <li id="pgcUserMenuWarning" style="display: none; margin: .5em 1em; color: red; background: 0;"><a href="#" onclick="location.reload();" style="color: red; padding: 0; text-decoration: underline; display: inline;">Reload</a> the page to activate the new settings.</li>\
  405. </form>\
  406. </ul>';
  407.  
  408. let pgc = '<li id="pgc"><div class="player-profile">' + $('#gc-header .player-profile').html() + '</div></li>';
  409. $('.user-menu').prepend(pgc);
  410. // Icon
  411. $('#pgc div').prepend('<a href="' + pgcUrl + '"></a>');
  412. $('#pgc img').attr('src', 'https://cdn2.project-gc.com/favicon.ico');
  413. $('#pgc img').attr('style', 'border-radius:100%;');
  414. $('#pgc img').appendTo('#pgc a');
  415. // Username
  416. $('#pgc .username').html(loggedInContent);
  417. // Subscription
  418. $('#pgc .username + span').html(subscriptionContent);
  419.  
  420. // Menu Toggle
  421. let button = $('.toggle-user-menu').last().parent().clone();
  422. $(button).find('button').attr('id', 'pgcUserMenuButton');
  423. $(button).attr('id', 'pgcButton');
  424. $(button).append(settings);
  425. // Add Toggle Button
  426. $('#pgc').after(button);
  427.  
  428. $("#pgcUserMenuButton").click(function(e) {
  429. $('#pgcUserMenu').show();
  430. })
  431. $('body').click(function(e) {
  432. if (!$(e.target).parents('#pgcUserMenu')[0] && (!$(e.target).parents('#pgcButton')[0] && $("#pgcUserMenu").css('display') != 'none')) {
  433. $("#pgcUserMenu").hide();
  434. }
  435. })
  436.  
  437. $('#pgcUserMenuSave').click(function(e) {
  438. SaveSettings(e);
  439. });
  440.  
  441. // Workaround for users that also use the GClh
  442. function checkForGClh(waitCount) {
  443. if ($('#GClh_II_running')[0] && $('gclh_nav#ctl00_gcNavigation')[0]) {
  444. let gclh_pgc = '<li id="pgc_gclh" class="li-user"><div class="li-user-info">' + $($('.li-user')[0]).find('a').html() + '</div>'
  445. + '<button id="pgcUserMenuButton_gclh" class="li-user-toggle dropdown">' + $($('.li-user')[0]).find('button').html() + '</button>'
  446. + settings + '</li>';
  447. $('#ctl00_uxLoginStatus_divSignedIn').prepend(gclh_pgc);
  448. // Icon
  449. $('#pgc_gclh img').attr('src', 'https://cdn2.project-gc.com/favicon.ico');
  450. $('#pgc_gclh img').attr('style', 'border-radius:100%;');
  451. $('#pgc_gclh img')[0].onclick = function() {open(pgcUrl);};
  452. // User
  453. $('#pgc_gclh .user-name').html(loggedInContent);
  454. // Subscription
  455. $('#pgc_gclh .cache-count').html(subscriptionContent);
  456.  
  457.  
  458. // Rename the settings
  459. $('#pgc_gclh .dropdown-menu.menu-user').attr('id', 'pgcUserMenu_gclh');
  460. $('#pgc_gclh .dropdown-menu.menu-user form').attr('id', 'pgcUserMenuForm_gclh');
  461. $('#pgc_gclh .dropdown-menu.menu-user form li:nth-last-child(2) button:nth-last-child(1)').attr('id', 'pgcUserMenuSave_gclh');
  462. $('#pgc_gclh .dropdown-menu.menu-user form li:nth-last-child(1)').attr('id', 'pgcUserMenuWarning_gclh');
  463.  
  464. $("#pgcUserMenuButton_gclh").click(function(e) {
  465. $('#pgcUserMenu_gclh').toggle();
  466. })
  467.  
  468. $('#pgcUserMenuSave_gclh').click(function(e) {
  469. SaveSettings(e);
  470. });
  471.  
  472. } else {waitCount++; if (waitCount <= 1000) setTimeout(function(){checkForGClh(waitCount);}, 10);}
  473. }
  474. checkForGClh(0);
  475. }
  476.  
  477. /**
  478. * getGcCodeFromPage
  479. * @return string
  480. */
  481. function getGcCodeFromPage() {
  482. return $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoCode').html();
  483. }
  484.  
  485. /**
  486. * addToVGPS
  487. */
  488. function addToVGPS(gccode) {
  489. var listId = $('#comboVGPS').val(),
  490. url = null;
  491.  
  492. if (typeof(gccode) === 'undefined') { // The map provides the gccode itself
  493. gccode = getGcCodeFromPage();
  494. }
  495.  
  496. url = pgcApiUrl + 'AddToVGPSList?listId=' + listId + '&gccode=' + gccode + '&sectionName=GM-script';
  497.  
  498.  
  499. GM.xmlHttpRequest({
  500. method: "GET",
  501. url: url,
  502. onload: function(response) {
  503. var result = JSON.parse(response.responseText),
  504. msg = (result.status === 'OK') ? 'Geocache added to Virtual-GPS!' : 'Geocache not added to Virtual-GPS :(';
  505.  
  506. $('#btnAddToVGPS').css('display', 'none');
  507. $('#btnRemoveFromVGPS').css('display', '');
  508.  
  509. alert(msg);
  510.  
  511. return true;
  512. },
  513. onerror: function(response) {
  514. console.log(response);
  515. return false;
  516. }
  517. });
  518. return true;
  519. }
  520.  
  521. /**
  522. * removeFromVGPS
  523. */
  524. function removeFromVGPS(gccode) {
  525. var listId = $('#comboVGPS').val(),
  526. url = null;
  527.  
  528. if (typeof(gccode) === 'undefined') { // The map provides the gccode itself
  529. gccode = getGcCodeFromPage();
  530. }
  531.  
  532. url = pgcApiUrl + 'RemoveFromVGPSList?listId=' + listId + '&gccode=' + gccode;
  533.  
  534.  
  535. GM.xmlHttpRequest({
  536. method: "GET",
  537. url: url,
  538. onload: function(response) {
  539. var result = JSON.parse(response.responseText),
  540. msg = (result.status === 'OK') ? 'Geocache removed from Virtual-GPS!' : 'Geocache not removed from Virtual-GPS :(';
  541.  
  542. $('#btnAddToVGPS').css('display', '');
  543. $('#btnRemoveFromVGPS').css('display', 'none');
  544.  
  545. alert(msg);
  546.  
  547. return true;
  548. },
  549. onerror: function(response) {
  550. console.log(response);
  551. return false;
  552. }
  553. });
  554. }
  555.  
  556. function Page_Profile() {
  557. // Override gc.com function on alerting for external links to not alert for Project-GC URLs
  558. var gcAlertOverride = document.createElement('script');
  559. gcAlertOverride.type = "text/javascript";
  560. gcAlertOverride.innerHTML = `(function() {
  561. var _old_isGeocachingDomain = isGeocachingDomain;
  562. isGeocachingDomain = function(url) {
  563. return (_old_isGeocachingDomain.apply(this, arguments)
  564. || url == "project-gc.com"
  565. || url == "www.project-gc.com");
  566. };
  567. })();`;
  568. document.getElementsByTagName('head')[0].appendChild(gcAlertOverride);
  569. }
  570.  
  571. /**
  572. * Page_CachePage
  573. */
  574. function Page_CachePage() {
  575. var gccode = getGcCodeFromPage(),
  576. placedBy = $('#ctl00_ContentBody_mcd1 a').html(),
  577. lastUpdated = $('#ctl00_ContentBody_bottomSection p small time').get(1),
  578. lastFound = $('#ctl00_ContentBody_bottomSection p small time').get(2),
  579. coordinates, latitude, longitude, url;
  580.  
  581. lastUpdated = (lastUpdated) ? lastUpdated.dateTime : false;
  582. lastFound = (lastFound) ? lastFound.dateTime : false;
  583.  
  584. if (subscription) {
  585.  
  586. // Get geocache data from Project-GC
  587. url = pgcApiUrl + 'GetCacheDataFromGccode&gccode=' + gccode;
  588. if (lastUpdated) {
  589. url += '&lastUpdated=' + lastUpdated;
  590. }
  591. if (lastFound) {
  592. url += '&lastFound=' + lastFound;
  593. }
  594.  
  595. GM.xmlHttpRequest({
  596. method: "GET",
  597. url: url,
  598. onload: function(response) {
  599. var result = JSON.parse(response.responseText),
  600. cacheData = result.data.cacheData,
  601. bearing = result.data.bearing,
  602. cacheOwner = result.data.owner,
  603. challengeCheckerTagIds = result.data.challengeCheckerTagIds,
  604. geocacheLogsPerCountry = result.data.geocacheLogsPerCountry,
  605. myNumberOfLogs = result.data.myNumberOfLogs,
  606. location = [],
  607. fp = 0,
  608. fpp = 0,
  609. fpw = 0,
  610. elevation = '',
  611. html = '';
  612.  
  613.  
  614. challengeCheckerResults = result.data.challengeCheckerResults;
  615.  
  616. // Add an alert in top if there are Found it-logs which doesn't seem to fulfill the requirements
  617. if(challengeCheckerResults !== false) {
  618. var suspiciousFoundItLogs = [];
  619. for(var logId in challengeCheckerResults) {
  620. if(typeof challengeCheckerResults[logId] !== 'undefined' && challengeCheckerResults[logId]['status'] == 'fail') {
  621. suspiciousFoundItLogs.push(logId);
  622. }
  623. }
  624.  
  625. if(suspiciousFoundItLogs.length != 0) {
  626. var suspiciousFoundItLog = '<p style="color: #ff6c00;" class=" NoBottomSpacing"><strong>Cache Issues:</strong></p>\
  627. <ul style="color: #ff6c00;" class="">\
  628. <li>The following Found it logs might not fulfill the requirements:<br>';
  629.  
  630. for(var i = 0 ; i < suspiciousFoundItLogs.length ; i++) {
  631. suspiciousFoundItLog = suspiciousFoundItLog + ' <a href="https://www.geocaching.com/seek/log.aspx?LID=' + suspiciousFoundItLogs[i] + '">' + challengeCheckerResults[suspiciousFoundItLogs[i]]['profileName'] + '</a><br>';
  632. }
  633. 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.</li></ul>';
  634.  
  635. $('div.span-6.right.last').last().next().after(suspiciousFoundItLog);
  636. }
  637. }
  638. //--
  639.  
  640.  
  641. if (result.status == 'OK' && typeof cacheData !== 'undefined') {
  642.  
  643. // If placed by != owner, show the real owner as well.
  644. if (placedBy !== cacheOwner) {
  645. $('#ctl00_ContentBody_mcd1 span.message__owner').before(' (' + cacheOwner + ')');
  646. }
  647.  
  648. // Append link to Profile Stats for the cache owner
  649. // Need to real cache owner name from PGC since the web only has placed by
  650. if (IsSettingEnabled('profileStatsLinks')) {
  651. $('#ctl00_ContentBody_mcd1 span.message__owner').before('<a href="' + pgcUrl + 'ProfileStats/' + encodeURIComponent(cacheOwner) + '"><img src="' + externalLinkIcon + '" title="PGC Profile Stats"></a>');
  652. }
  653.  
  654. // Add FP/FP%/FPW below the current FP + mouseover for FP% and FPW with decimals
  655. if (IsSettingEnabled('addPgcFp')) {
  656. fp = (+cacheData.favorite_points),
  657. fpp = (+cacheData.favorite_points_pct),
  658. fpw = (+cacheData.favorite_points_wilson);
  659. $('#uxFavContainerLink').append('<p title= "' + parseFloat(fpp) + '%, ' + parseFloat(fpw) + 'W" style="text-align: center; background-color: #f0edeb;border-bottom-left-radius: 5px;border-bottom-right-radius:5px;">PGC: ' + parseInt(fp) + ' FP, ' + Math.round(fpp) + '%, ' + Math.round(fpw) + 'W</p>');
  660. $('.favorite-container').css({
  661. "border-bottom-left-radius": "0",
  662. "border-bottom-right-radius": "0"
  663. });
  664. }
  665.  
  666. // Add elevation (Metres above mean sea level = mamsl)
  667. if (IsSettingEnabled('addElevation')) {
  668. var formattedElevation = FormatDistance(cacheData.elevation),
  669. elevationUnit = IsSettingEnabled('imperial') ? 'ft' : 'm',
  670. elevationArrow = (cacheData.elevation >= 0) ? '&#x21a5;' : '&#x21a7;';
  671. elevation = formattedElevation + ' ' + elevationUnit + ' ' + elevationArrow;
  672.  
  673. if (cacheData.elevation >= 0) {
  674. html = '<span> (' + elevation + ')</span>';
  675. } else {
  676. html = '<span class="OldWarning"> (' + elevation + ')</span>';
  677. }
  678.  
  679. ($('#uxLatLonLink').length > 0 ? $('#uxLatLonLink') : $('#uxLatLon').parent()).after(html);
  680. }
  681.  
  682. // Add PGC location
  683. if (IsSettingEnabled('addPGCLocation')) {
  684. if (cacheData.country.length > 0) {
  685. location.push(cacheData.country);
  686. }
  687. if (cacheData.region !== null && cacheData.region.length > 0) {
  688. location.push(cacheData.region);
  689. }
  690. if (cacheData.county !== null && cacheData.county.length > 0) {
  691. location.push(cacheData.county);
  692. }
  693. location = location.join(' / ');
  694.  
  695. var gccomLocationData = $('#ctl00_ContentBody_Location').html();
  696. $('#ctl00_ContentBody_Location').html('<span style="text-decoration: line-through;">' + gccomLocationData + '</span><br><span>' + location + '</span>');
  697. }
  698.  
  699. // Add bearing from home
  700. $('#lblDistFromHome').append(' <span>(' + Math.round(bearing*10)/10 + '&deg;)</span>');
  701.  
  702. // Add challenge checkers
  703. if (IsSettingEnabled('addChallengeCheckers') && challengeCheckerTagIds.length > 0) {
  704. html = '<div id="checkerWidget" class="CacheDetailNavigationWidget TopSpacing BottomSpacing"><h3 class="WidgetHeader">Challenge checker(s)</h3><div class="WidgetBody" id="PGC_ChallengeCheckers">';
  705. for (var i = 0; i < challengeCheckerTagIds.length; i++) {
  706. html += '<a href="https://project-gc.com/Challenges/' + gccode + '/' + challengeCheckerTagIds[i] + '" style="display: block; width: 200px; margin: 0 auto;"><img src="https://cdn2.project-gc.com/Images/Checker/' + challengeCheckerTagIds[i] + '" title="Project-GC Challenge checker" alt="PGC Checker"></a>';
  707. }
  708. html += '</div></div>';
  709. $('#ctl00_ContentBody_detailWidget').before(html);
  710. }
  711.  
  712. // Display warning message if cache is logged and no longer be logged
  713. if (cacheData.locked) {
  714. $('ul.OldWarning').append('<li>This cache has been locked and can no longer be logged.</li>');
  715. }
  716.  
  717. // Add geocache logs per profile country table
  718. if (IsSettingEnabled('addGeocacheLogsPerProfileCountry')) {
  719. html = '<div id="geocacheLogsPerCountry" style="border: dashed; border-color: #aaa; border-width: thin;">';
  720.  
  721. if(typeof(geocacheLogsPerCountry['willAttend']) != 'undefined' && geocacheLogsPerCountry['willAttend'].length > 0) {
  722. html += '<p style="margin-left: 10px; margin-bottom: 0;"><strong>Will attend logs per country</strong> <small>according to Project-GC.com</small></p>';
  723. html += '<ul style="list-style: none; margin-left: 0; margin-bottom: 0;">';
  724. for (var i = 0; i < geocacheLogsPerCountry['willAttend'].length; i++) {
  725. html += '<li style="display: inline; padding-right: 20px;"><span style="display: inline-block;"><img src="' + cdnDomain + geocacheLogsPerCountry['willAttend'][i].flagIcon + '" alt="' + $('<div/>').text(geocacheLogsPerCountry['willAttend'][i].country).html() + '" title="' + $('<div/>').text(geocacheLogsPerCountry['willAttend'][i].country).html() + '"> ' + geocacheLogsPerCountry['willAttend'][i].cnt + '</span></li>';
  726. }
  727. html += '</ul>';
  728. html += '<span style="display: block; text-align: right; padding-right: 10px;"><small>' + geocacheLogsPerCountry['willAttend'].length + ' unique countries</small></span>';
  729. html += '<span style="display: block; text-align: right; padding-right: 10px;"><small><a href="https://project-gc.com/Tools/EventStatistics?gccode=' + encodeURIComponent(gccode) + '">Event statistics</a></small></span>';
  730. }
  731.  
  732. if(typeof(geocacheLogsPerCountry['found']) != 'undefined' && geocacheLogsPerCountry['found'].length > 0) {
  733. html += '<p style="margin-left: 10px; margin-bottom: 0;"><strong>Found logs per country</strong> <small>according to Project-GC.com</small></p>';
  734. html += '<ul style="list-style: none; margin-left: 0; margin-bottom: 0;">';
  735. for (var i = 0; i < geocacheLogsPerCountry['found'].length; i++) {
  736. html += '<li style="display: inline; padding-right: 20px;"><span style="display: inline-block;"><img src="' + cdnDomain + geocacheLogsPerCountry['found'][i].flagIcon + '" alt="' + $('<div/>').text(geocacheLogsPerCountry['found'][i].country).html() + '" title="' + $('<div/>').text(geocacheLogsPerCountry['found'][i].country).html() + '"> ' + geocacheLogsPerCountry['found'][i].cnt + '</span></li>';
  737. }
  738. html += '</ul>';
  739. html += '<span style="display: block; text-align: right; padding-right: 10px;"><small>' + geocacheLogsPerCountry['found'].length + ' unique countries</small></span>';
  740. }
  741.  
  742. html += '</div>';
  743.  
  744. $('#ctl00_ContentBody_lblFindCounts').append(html);
  745. }
  746.  
  747. // Add my number of logs above the log button
  748. if (IsSettingEnabled('addMyNumberOfLogs')) {
  749. $('<p style="margin: 0;"><small>You have ' + myNumberOfLogs + ' logs according to Project-GC</small></p>').insertBefore('#ctl00_ContentBody_GeoNav_logButton');
  750. }
  751.  
  752. // Append the same number to the added logbook link
  753. if (IsSettingEnabled('logbookLinks')) {
  754. $('#pgc-logbook-yours').html('Yours (' + myNumberOfLogs + ')')
  755.  
  756. }
  757. }
  758.  
  759.  
  760. // Since everything in the logbook is ajax, we need to wait for the elements
  761. // We also want to wait on challengeCheckerResults
  762. waitForKeyElements('#cache_logs_table tbody tr', Logbook);
  763. }
  764. });
  765. }
  766.  
  767. // Add weekday of place date
  768. if (IsSettingEnabled('showWeekday')) {
  769. var match = $('meta[name="description"]')[1].content.match(/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/);
  770. if (match) {
  771. var date = new Date(match[3], match[1]-1, match[2]);
  772. var weekday = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
  773. var text = $($('#ctl00_ContentBody_mcd2')[0].childNodes[0]).text();
  774. var pos = text.indexOf(':') + 2;
  775. var newText = text.substring(0, pos);
  776. newText += weekday[date.getDay()] + ', ';
  777. newText += text.substring(pos, text.length);
  778. var newNode = document.createTextNode(newText);
  779. $('#ctl00_ContentBody_mcd2')[0].replaceChild(newNode, $('#ctl00_ContentBody_mcd2')[0].childNodes[0]);
  780. }
  781. }
  782.  
  783. // Tidy the web
  784. if (IsSettingEnabled('tidy')) {
  785. $('#ctl00_divContentMain p.Clear').css('margin', '0');
  786. $('div.Note.PersonalCacheNote').css('margin', '0');
  787. $('h3.CacheDescriptionHeader').remove();
  788. $('#ctl00_ContentBody_EncryptionKey').remove();
  789. $('#ctl00_ContentBody_GeoNav_foundStatus').css('margin-bottom', '0');
  790. }
  791.  
  792. // Make it easier to copy the gccode
  793. if (IsSettingEnabled('makeCopyFriendly')) {
  794. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').
  795. html('<div style="margin-right: 15px; margin-bottom: 10px;"><p id="ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoCode" style="font-size: 125%; margin-bottom: 0">' + gccode + '</p>' +
  796. '<input size="25" type="text" value="https://coord.info/' + encodeURIComponent(gccode) + '" onclick="this.setSelectionRange(0, this.value.length);"></div>');
  797. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').css('font-weight', 'inherit').css('margin-right', '27px');
  798. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel div input').css('padding', '0');
  799. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel div').css('margin', '0 0 5px 0');
  800. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel div p').css('font-weight', 'bold');
  801. }
  802.  
  803. // Add PGC Map links
  804. if (IsSettingEnabled('addPgcMapLinks')) {
  805. coordinates = $('#ctl00_ContentBody_MapLinks_MapLinks li a').attr('href'),
  806. latitude = coordinates.replace(/.*lat=([^&]*)&lng=.*/, "$1"),
  807. longitude = coordinates.replace(/.*&lng=(.*)$/, "$1");
  808. // var mapUrl = pgcUrl + 'Maps/mapcompare/?profile_name=' + gccomUsername +
  809. // '&nonefound=on&ownfound=on&location=' + latitude + ',' + longitude +
  810. // '&max_distance=5&submit=Filter';
  811. var mapUrl = pgcUrl + 'LiveMap/#c=' + latitude + ',' + longitude + ';z=14';
  812.  
  813. // $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').append(
  814. // '<div style="margin-bottom: 8px;"><a target="_blank" href="' + mapUrl + '">Project-GC map</a> (<a target="_blank" href="' + mapUrl + '&onefound=on">incl found</a>)</div>'
  815. // );
  816. $('#ctl00_ContentBody_CoordInfoLinkControl1_uxCoordInfoLinkPanel').append(
  817. '<div style="margin-bottom: 8px;"><a target="_blank" href="' + mapUrl + '">Project-GC Live map</a></div>'
  818. );
  819. }
  820.  
  821. // Remove the UTM coordinates
  822. // $('#ctl00_ContentBody_CacheInformationTable div.LocationData div.span-9 p.NoBottomSpacing br').remove();
  823. if (IsSettingEnabled('removeUTM')) {
  824. $('#ctl00_ContentBody_LocationSubPanel').html('');
  825.  
  826. // And move the "N 248.3 km from your home location"
  827. $('#ctl00_ContentBody_LocationSubPanel').after($('#lblDistFromHome'));
  828. }
  829.  
  830. // Remove ads
  831. // PGC can't really do this officially
  832. // $('#ctl00_ContentBody_uxBanManWidget').remove();
  833.  
  834. // Remove disclaimer
  835. if (IsSettingEnabled('removeDisclaimer')) {
  836. $('#divContentMain div.span-17 div.Note.Disclaimer').remove();
  837. }
  838.  
  839. // If the first log is a DNF, display a blue warning on top of the page
  840. if($('#cache_logs_table tr:first td div.LogDisplayRight strong img').attr('src') === '/images/logtypes/3.png') {
  841. var htmlFirstLogDnf = '<p style="color: #006cff;" class=" NoBottomSpacing"><strong>Cache Issues:</strong></p>\
  842. <ul style="color: #006cff;" class="">\
  843. <li>The latest log for this cache is a DNF, <a href="#cache_logs_table">please read the log</a> before your own search.</li>\
  844. </ul>';
  845. $('div.span-6.right.last').last().next().after(htmlFirstLogDnf);
  846.  
  847. }
  848.  
  849. // Collapse download links
  850. // http://www.w3schools.com/charsets/ref_utf_geometric.asp (x25BA, x25BC)
  851. if (IsSettingEnabled('collapseDownloads')) {
  852. $('<p style="cursor: pointer; margin: 0;" id="DownloadLinksToggle" onclick="$(\'#divContentMain div.DownloadLinks, #DownloadLinksToggle .arrow\').toggle();"><span class="arrow">&#x25BA;</span><span class="arrow open">&#x25BC;</span>Print and Downloads</p>').insertBefore('#divContentMain div.DownloadLinks');
  853. $('#divContentMain div.DownloadLinks, #DownloadLinksToggle .arrow.open').hide();
  854. }
  855.  
  856. // Resolve the coordinates into an address
  857. if (IsSettingEnabled('addAddress')) {
  858. coordinates = $('#ctl00_ContentBody_MapLinks_MapLinks li a').attr('href'),
  859. latitude = coordinates.replace(/.*lat=([^&]*)&lng=.*/, "$1"),
  860. longitude = coordinates.replace(/.*&lng=(.*)$/, "$1"),
  861. url = 'https://nominatim.openstreetmap.org/reverse?lat=' + latitude + '&lon=' + longitude + '&format=json';
  862.  
  863. GM.xmlHttpRequest({
  864. method: "GET",
  865. url: url,
  866. onload: function(response) {
  867. var result = JSON.parse(response.responseText);
  868. if (!result.display_name) {
  869. return false;
  870. }
  871. var formattedAddress = result.address.road;
  872. if (result.address.house_number) {
  873. formattedAddress = formattedAddress + ' ' + result.address.house_number;
  874. }
  875. if (result.address.city) {
  876. formattedAddress = formattedAddress + ', ' + result.address.city;
  877. }
  878. $('#ctl00_ContentBody_LocationSubPanel').append(formattedAddress + '<br />');
  879. }
  880. });
  881. }
  882.  
  883. // Add number of finds per type to the top
  884. if (IsSettingEnabled('cloneLogsPerType') && typeof $('#ctl00_ContentBody_lblFindCounts').html() !== 'undefined') {
  885. $('#ctl00_ContentBody_CacheInformationTable').before('<div>' + $('#ctl00_ContentBody_lblFindCounts').html() + '</div>');
  886. }
  887.  
  888. // Add link to PGC gallery
  889. if (subscription && IsSettingEnabled('addPgcGalleryLinks')) {
  890. var html = '<a href="' + pgcUrl + 'Tools/Gallery?gccode=' + gccode + '&submit=Filter"><img src="' + galleryLinkIcon + '" title="Project-GC Gallery"></a> ';
  891. $('.CacheDetailNavigation ul li:first').append(html);
  892. }
  893.  
  894. // Add map links for each bookmarklist
  895. if (IsSettingEnabled('addMapBookmarkListLinks')) {
  896. $('ul.BookmarkList li').each(function() {
  897. var guid = $(this).children(':nth-child(1)').attr('href').replace(/.*\?guid=(.*)/, "$1");
  898. var owner = $(this).children(':nth-child(3)').text();
  899.  
  900. // Add the map link
  901. url = 'https://project-gc.com/Tools/MapBookmarklist?owner_name=' + encodeURIComponent(owner) + '&guid=' + encodeURIComponent(guid);
  902. $(this).children(':nth-child(1)').append('&nbsp;<a href="' + url + '"><img src="' + mapLinkIcon + '" title="Map with Project-GC"></a>');
  903.  
  904. // Add gallery link for the bookmark list
  905. url = 'https://project-gc.com/Tools/Gallery?bml_owner=' + encodeURIComponent(owner) + '&bml_guid=' + encodeURIComponent(guid) + '&submit=Filter';
  906. $(this).children(':nth-child(1)').append('&nbsp;<a href="' + url + '"><img src="' + galleryLinkIcon + '" title="Project-GC Gallery"></a>');
  907.  
  908. // Add profile stats link to the owner
  909. url = 'https://project-gc.com/ProfileStats/' + encodeURIComponent(owner);
  910. $(this).children(':nth-child(3)').append('&nbsp;<a href="' + url + '"><img src="' + externalLinkIcon + '" title="Project-GC Profile stats"></a>');
  911. });
  912. }
  913.  
  914. // Decrypt the hint
  915. if (IsSettingEnabled('decryptHints') && $('#ctl00_ContentBody_lnkDH')[0].title == 'Decrypt') {
  916. $('#ctl00_ContentBody_lnkDH')[0].click();
  917. }
  918.  
  919. // VGPS form
  920. if (IsSettingEnabled('showVGPS')) {
  921. GM.xmlHttpRequest({
  922. method: "GET",
  923. url: pgcApiUrl + 'GetExistingVGPSLists?gccode=' + gccode,
  924. onload: function(response) {
  925. var result = JSON.parse(response.responseText),
  926. vgpsLists = result.data.lists,
  927. selected = result.data.selected,
  928. existsIn = result.data.existsIn,
  929. selectedContent,
  930. existsContent,
  931. html = '<li><img width="16" height="16" src="https://cdn2.project-gc.com/images/mobile_telephone_32.png"> <strong>Add to VGPS</strong><br />',
  932. listId;
  933.  
  934. html += '<select id="comboVGPS" style="width: 138px;">';
  935. for (listId in vgpsLists) {
  936. selectedContent = '';
  937. if (+selected === +listId) {
  938. selectedContent = ' selected="selected"';
  939. }
  940.  
  941. existsContent = '';
  942. if (existsIn.indexOf(listId) > -1) {
  943. existsContent = ' data-exists="true"';
  944. }
  945. html += '<option value="' + listId + '"' + selectedContent + existsContent + '>' + vgpsLists[listId].name + '</option>';
  946. }
  947. html += '</select>';
  948. if (existsIn.indexOf(String(selected)) == -1) {
  949. html += '&nbsp;<button id="btnAddToVGPS">+</button>';
  950. html += '&nbsp;<button id="btnRemoveFromVGPS" style="display: none;">-</button>';
  951. } else {
  952. html += '&nbsp;<button id="btnAddToVGPS" style="display: none;">+</button>';
  953. html += '&nbsp;<button id="btnRemoveFromVGPS">-</button>';
  954. }
  955. html += '</li>';
  956.  
  957. $('div.CacheDetailNavigation ul:first').append(html);
  958.  
  959. $('#comboVGPS').change(function() {
  960. selected = $(this).find(':selected').val();
  961. if (existsIn.indexOf(String(selected)) == -1) {
  962. $('#btnAddToVGPS').css('display', '');
  963. $('#btnRemoveFromVGPS').css('display', 'none');
  964. } else {
  965. $('#btnAddToVGPS').css('display', 'none');
  966. $('#btnRemoveFromVGPS').css('display', '');
  967. }
  968. });
  969. $('#btnAddToVGPS').click(function(event) {
  970. event.preventDefault();
  971. addToVGPS();
  972. });
  973. $('#btnRemoveFromVGPS').click(function(event) {
  974. event.preventDefault();
  975. removeFromVGPS();
  976. });
  977. }
  978. });
  979. }
  980.  
  981. // Change font in personal cache note to monospaced
  982. if (IsSettingEnabled('cachenoteFont')) {
  983. $("#viewCacheNote,#cacheNoteText").css("font-family", "monospace").css("font-size", "12px");
  984. $("#viewCacheNote").on("DOMSubtreeModified", function() {
  985. $(".inplace_field").css("font-family", "monospace").css("font-size", "12px");
  986. });
  987. }
  988.  
  989.  
  990. if (IsSettingEnabled('logbookLinks')) {
  991. $('\
  992. <span>&nbsp;|&nbsp;</span><a id="pgc-logbook-yours" href="' + $('#ctl00_ContentBody_uxLogbookLink').attr('href') + '#tabs-2">Yours</a>\
  993. <span>&nbsp;|&nbsp;</span><a href="' + $('#ctl00_ContentBody_uxLogbookLink').attr('href') + '#tabs-3">Friends\'</a>\
  994. ').insertAfter( $('#ctl00_ContentBody_uxLogbookLink') );
  995. }
  996. }
  997.  
  998. function Page_Logbook() {
  999. // Since everything in the logbook is ajax, we need to wait for the elements
  1000. waitForKeyElements('#AllLogs tr', Logbook);
  1001. waitForKeyElements('#PersonalLogs tr', Logbook);
  1002. waitForKeyElements('#FriendLogs tr', Logbook);
  1003. }
  1004.  
  1005. function Logbook(jNode) {
  1006. // Add Profile stats and gallery links after each user
  1007. if (IsSettingEnabled('profileStatsLinks')) {
  1008. var profileNameElm = $(jNode).find('a.h5');
  1009. var profileName = profileNameElm.html();
  1010.  
  1011. if (typeof profileName !== 'undefined') {
  1012. profileName = profileNameElm.append('<a href="' + pgcUrl + 'ProfileStats/' + encodeURIComponent(profileName) + '"><img src="' + externalLinkIcon + '" title="PGC Profile Stats"></a>')
  1013. .append('<a href="' + pgcUrl + 'Tools/Gallery?profile_name=' + encodeURIComponent(profileName) + '&submit=Filter"><img src="' + galleryLinkIcon + '" title="PGC Gallery"></a>');
  1014. }
  1015. }
  1016.  
  1017. if(IsSettingEnabled('parseExifLocation')) {
  1018. $(jNode).find('ul.LogImagesTable li>a').each(function() {
  1019. var url = $(this).attr('href');
  1020. var thumbnailUrl = url.replace('/img.geocaching.com/cache/log/large/', '/img.geocaching.com/cache/log/thumb/');
  1021.  
  1022. var imgElm = $(this).find('img');
  1023. $(imgElm).attr('src', thumbnailUrl);
  1024. $(imgElm).removeAttr('width');
  1025. $(imgElm).removeAttr('height');
  1026. $(imgElm).next().css('vertical-align', 'top');
  1027.  
  1028. $(imgElm).load(function() {
  1029. EXIF.getData($(imgElm)[0], function() {
  1030. // console.log(EXIF.pretty(this));
  1031. var coords = GetCoordinatesFromExif(this);
  1032. if(coords != false) {
  1033. $('<span style="color: #8c0b0b; font-weight: bold; float: right;">EXIF Location: <a href="https://maps.google.com/?q=' + coords + '" target="_blank">' + coords + '</a></span>').insertAfter($(imgElm).parent());
  1034. }
  1035. });
  1036. });
  1037.  
  1038. });
  1039. }
  1040.  
  1041. if(IsSettingEnabled('addCachedChallengeCheckerResults') && typeof(challengeCheckerResults) !== 'undefined' && challengeCheckerResults !== null) {
  1042. var classes = $(jNode).attr('class');
  1043. var logId = classes.match(/l-[0-9]+/)[0].replace('l-', '');
  1044. if(typeof(challengeCheckerResults[logId]) !== 'undefined') {
  1045. if(challengeCheckerResults[logId]['status'] == 'success') {
  1046. $(jNode).find('div.LogDisplayLeft').first().append('<hr style="margin-top: 12px; margin-bottom: 12px;"><p>Checker result<br>' + challengeCheckerResults[logId]['lastRun'] + ' UTC: <img src="' + challengeCheckerSuccessIcon + '"></p>');
  1047. }
  1048. else if(challengeCheckerResults[logId]['status'] == 'fail') {
  1049. $(jNode).find('div.LogDisplayLeft').first().append('<hr style="margin-top: 12px; margin-bottom: 12px;"><p>Checker result<br>' + challengeCheckerResults[logId]['lastRun'] + ' UTC: <img src="' + challengeCheckerFailIcon + '"></p>');
  1050. }
  1051. }
  1052. }
  1053.  
  1054. if(IsSettingEnabled('hideLogVoting')) {
  1055. $('div.upvotes').css('display','none');
  1056. $('div.sort-logs').css('display','none');
  1057. }
  1058.  
  1059.  
  1060. // Save to latest logs
  1061. if (latestLogs.length < 5) {
  1062. var node = $(jNode).find('div.HalfLeft.LogType h4 img[src]'),
  1063. logType = {};
  1064.  
  1065. if (node.length === 0)
  1066. return false;
  1067.  
  1068. logType = {
  1069. 'src': node.attr('src'),
  1070. 'alt': node.attr('alt'),
  1071. 'title': node.attr('title')
  1072. };
  1073.  
  1074. logType.id = +logType.src.replace(/.*logtypes\/(\d+)\.png/, "$1");
  1075.  
  1076. // First entry is undefined, due to ajax
  1077. if (logType.src) {
  1078. latestLogs.push('<img src="' + logType.src + '" alt="' + logType.alt + '" title="' + logType.title + '" style="margin-bottom: -4px; margin-right: 1px;">');
  1079. // 2 = found, 3 = dnf, 4 = note, 5 = archive, 22 = disable, 24 = publish, 45 = nm, 46 = owner maintenance, 68 = reviewer note
  1080. if ($.inArray(logType.id, [3, 5, 22, 45, 68]) !== -1) {
  1081. latestLogsAlert = true;
  1082. }
  1083. }
  1084.  
  1085. // Show latest logs
  1086. // Enhanced Nov 2016 to show icons for up to 5 of the latest logs
  1087. if (IsSettingEnabled('addLatestLogs') && latestLogs.length <= 5) {
  1088. var images = latestLogs.join('');
  1089.  
  1090. $('#latestLogIcons').remove();
  1091. $('#ctl00_ContentBody_size p').removeClass('AlignCenter').addClass('NoBottomSpacing');
  1092.  
  1093. if (latestLogsAlert) {
  1094. $('#ctl00_ContentBody_size').append('<p class="NoBottomSpacing OldWarning" id="latestLogIcons"><strong>Latest logs:</strong> <span>' + images + '</span></p>');
  1095. } else {
  1096. $('#ctl00_ContentBody_size').append('<p class="NoBottomSpacing" id="latestLogIcons">Latest logs: <span>' + images + '</span></p>');
  1097. }
  1098. }
  1099. }
  1100. }
  1101.  
  1102. function Page_Map() {
  1103. if (IsSettingEnabled('showVGPS')) {
  1104.  
  1105. setTimeout(function() {
  1106. $('#map_canvas div.leaflet-popup-pane').bind('DOMSubtreeModified', function() {
  1107. if ($('#pgc_vgps').length === 0) {
  1108. var gccode = $('#gmCacheInfo div.code').text();
  1109.  
  1110. $('#gmCacheInfo div.links').after('<div id="pgc_vgps"></div>');
  1111.  
  1112. GM.xmlHttpRequest({
  1113. method: "GET",
  1114. url: pgcApiUrl + 'GetExistingVGPSLists?gccode=' + gccode,
  1115. onload: function(response) {
  1116.  
  1117. var result = JSON.parse(response.responseText),
  1118. vgpsLists = result.data.lists,
  1119. selected = result.data.selected,
  1120. existsIn = result.data.existsIn,
  1121. selectedContent,
  1122. existsContent,
  1123. html,
  1124. listId;
  1125.  
  1126.  
  1127. html = '<img src="https://cdn2.project-gc.com/images/mobile_telephone_32.png" style="width: 24px; height: 24px; margin-bottom: -6px;">';
  1128.  
  1129. html += '<select id="comboVGPS" style="margin-bottom: 4px;">';
  1130. for (listId in vgpsLists) {
  1131. selectedContent = '';
  1132. if (+selected === +listId) {
  1133. selectedContent = ' selected="selected"';
  1134. }
  1135.  
  1136. html += '<option value="' + listId + '"' + selectedContent + existsContent + '>' + vgpsLists[listId].name + '</option>';
  1137. }
  1138. html += '</select>';
  1139.  
  1140. if (existsIn.indexOf(String(selected)) == -1) {
  1141. html += '&nbsp;<button id="btnAddToVGPS">+</button>';
  1142. html += '&nbsp;<button id="btnRemoveFromVGPS" style="display: none;">-</button>';
  1143. } else {
  1144. html += '&nbsp;<button id="btnAddToVGPS" style="display: none;">+</button>';
  1145. html += '&nbsp;<button id="btnRemoveFromVGPS">-</button>';
  1146. }
  1147.  
  1148. $('#pgc_vgps').html(html);
  1149.  
  1150.  
  1151. $('#btnAddToVGPS').click(function(event) {
  1152. event.preventDefault();
  1153. addToVGPS(gccode);
  1154. });
  1155. $('#btnRemoveFromVGPS').click(function(event) {
  1156. event.preventDefault();
  1157. removeFromVGPS(gccode);
  1158. });
  1159. }
  1160. });
  1161. }
  1162. });
  1163. }, 500);
  1164. }
  1165.  
  1166. }
  1167.  
  1168. function Page_Gallery() {
  1169. // Find location data in exif tags
  1170. if(IsSettingEnabled('parseExifLocation')) {
  1171. $(window).load(function() { // Wait until page is loaded. If the images aren't loaded before this starts it will fail.
  1172. $('#ctl00_ContentBody_GalleryItems_DataListGallery img').each(function() {
  1173. EXIF.getData($(this)[0], function() {
  1174. // console.log(EXIF.pretty(this));
  1175. var coords = GetCoordinatesFromExif(this);
  1176. if(coords != false) {
  1177. $('<span class="OldWarning">EXIF Location<br><a href="https://maps.google.com/?q=' + coords + '" target="_blank">' + coords + '</a></span>').insertAfter(this.parentNode);
  1178. }
  1179. });
  1180. });
  1181. });
  1182. }
  1183. }
  1184.  
  1185. function Page_Bookmarks() {
  1186. var owner_name = $("#ctl00_ContentBody_ListInfo_uxListOwner").text();
  1187.  
  1188. var search = window.location.search;
  1189. var guid_start = search.indexOf("guid=");
  1190. if (guid_start == -1) {
  1191. /* the guid= not found in URL
  1192. * something is wrong so we will not generate bad URL
  1193. */
  1194. return;
  1195. }
  1196. var guid = search.substr(guid_start + 5/*, eof */);
  1197.  
  1198. var url = "https://project-gc.com/Tools/MapBookmarklist?owner_name=" + owner_name + "&guid=" + guid;
  1199. var icon = "https://cdn2.project-gc.com/images/map_app_16.png";
  1200.  
  1201. /* Heading link */
  1202. var html = ' <a href="' + url + '" title="Map this Bookmark list using Project-GC" style="padding-left:20px;"><img src="' + icon + '" /> Map this!</a>';
  1203.  
  1204. $("#ctl00_ContentBody_lbHeading").after(html);
  1205.  
  1206. /* Footer button */
  1207. var html2 = '<p><input type="button" onclick="window.location.href= \'' + url + '\'" value="Map this Bookmark list on Project-GC" /></p>';
  1208.  
  1209. $("#ctl00_ContentBody_ListInfo_btnDownload").parent().before(html2);
  1210. }
  1211.  
  1212. function Page_Drafts() {
  1213. if (IsSettingEnabled("openDraftLogInSameWindow")) {
  1214. waitForKeyElements('#draftsHub > ul.draft-list > li.draft-item', Draft);
  1215. }
  1216. }
  1217.  
  1218. function Draft(jNode) {
  1219. $(jNode).find(".draft-content > a").removeAttr('target');
  1220. }
  1221.  
  1222. function Page_Messagecenter() {
  1223. var target = document.getElementById('currentMessage');
  1224. var observer = new MutationObserver(function(mutations) {
  1225. mutations.forEach(function(mutation) {
  1226. if(mutation.type === "childList") {
  1227. var userlink = $(".user-meta a.current-user-image").attr("href"), username = $(".user-meta span.current-user-name").html();
  1228. $(".user-meta span.current-user-name").html("<a href='"+userlink+"'>"+username+"</a>");
  1229. }
  1230. });
  1231. });
  1232.  
  1233. var config = { childList: true };
  1234. observer.observe(target, config);
  1235. }
  1236.  
  1237. function Page_PrintCachePage() {
  1238. // Remove the disclaimer
  1239. $('div.TermsWidget').css('display', 'none');
  1240.  
  1241.  
  1242. // Get rid of the Logs section if it's not asked for. But keep it if we asked for it, even though there are 0 logs.
  1243. if( getUrlParameter('lc') === false ) {
  1244. $('div.item.ui-widget > div.item-header > h2.ui-sortable-handle').each(function() {
  1245. if( $(this).html() == 'Logs' ) { // Will only work with English
  1246. $(this).parent().parent().addClass('no-print').css('display', 'none');
  1247. return false; // Break .each loop
  1248. }
  1249. });
  1250. }
  1251.  
  1252.  
  1253. if(IsSettingEnabled('hideMapFromPrintCachePage')) {
  1254. $('#map').parent().parent().addClass('no-print');
  1255. $('#map').parent().prev().children('span.ui-icon').removeClass('ui-icon-minusthick').addClass('ui-icon-plusthick');
  1256. $('#map').parent().css('display', 'none');
  1257. }
  1258. }
  1259.  
  1260.  
  1261. function padLeft(str, n, padstr){
  1262. return Array(n-String(str).length+1).join(padstr||'0')+str;
  1263. }
  1264.  
  1265. function getUrlParameter(sParam) {
  1266. var sPageURL = decodeURIComponent(window.location.search.substring(1)),
  1267. sURLVariables = sPageURL.split('&'),
  1268. sParameterName,
  1269. i;
  1270.  
  1271. for (i = 0; i < sURLVariables.length; i++) {
  1272. sParameterName = sURLVariables[i].split('=');
  1273.  
  1274. if (sParameterName[0] === sParam) {
  1275. return sParameterName[1] === undefined ? true : sParameterName[1];
  1276. }
  1277. }
  1278.  
  1279. return false;
  1280. }
  1281. }());
  1282.  
  1283.  
  1284.  
  1285. // https://github.com/exif-js/exif-js adjusted to use GM.xmlHttpRequest
  1286. // Original license:
  1287. /*
  1288. The MIT License (MIT)
  1289.  
  1290. Copyright (c) 2008 Jacob Seidelin
  1291.  
  1292. 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:
  1293.  
  1294. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  1295.  
  1296. 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.
  1297. */
  1298. (function() {
  1299. var debug = false;
  1300.  
  1301. var root = this;
  1302.  
  1303. var EXIF = function(obj) {
  1304. if (obj instanceof EXIF) return obj;
  1305. if (!(this instanceof EXIF)) return new EXIF(obj);
  1306. this.EXIFwrapped = obj;
  1307. };
  1308.  
  1309. if (typeof exports !== 'undefined') {
  1310. if (typeof module !== 'undefined' && module.exports) {
  1311. exports = module.exports = EXIF;
  1312. }
  1313. exports.EXIF = EXIF;
  1314. } else {
  1315. root.EXIF = EXIF;
  1316. }
  1317.  
  1318. var ExifTags = EXIF.Tags = {
  1319.  
  1320. // version tags
  1321. 0x9000 : "ExifVersion", // EXIF version
  1322. 0xA000 : "FlashpixVersion", // Flashpix format version
  1323.  
  1324. // colorspace tags
  1325. 0xA001 : "ColorSpace", // Color space information tag
  1326.  
  1327. // image configuration
  1328. 0xA002 : "PixelXDimension", // Valid width of meaningful image
  1329. 0xA003 : "PixelYDimension", // Valid height of meaningful image
  1330. 0x9101 : "ComponentsConfiguration", // Information about channels
  1331. 0x9102 : "CompressedBitsPerPixel", // Compressed bits per pixel
  1332.  
  1333. // user information
  1334. 0x927C : "MakerNote", // Any desired information written by the manufacturer
  1335. 0x9286 : "UserComment", // Comments by user
  1336.  
  1337. // related file
  1338. 0xA004 : "RelatedSoundFile", // Name of related sound file
  1339.  
  1340. // date and time
  1341. 0x9003 : "DateTimeOriginal", // Date and time when the original image was generated
  1342. 0x9004 : "DateTimeDigitized", // Date and time when the image was stored digitally
  1343. 0x9290 : "SubsecTime", // Fractions of seconds for DateTime
  1344. 0x9291 : "SubsecTimeOriginal", // Fractions of seconds for DateTimeOriginal
  1345. 0x9292 : "SubsecTimeDigitized", // Fractions of seconds for DateTimeDigitized
  1346.  
  1347. // picture-taking conditions
  1348. 0x829A : "ExposureTime", // Exposure time (in seconds)
  1349. 0x829D : "FNumber", // F number
  1350. 0x8822 : "ExposureProgram", // Exposure program
  1351. 0x8824 : "SpectralSensitivity", // Spectral sensitivity
  1352. 0x8827 : "ISOSpeedRatings", // ISO speed rating
  1353. 0x8828 : "OECF", // Optoelectric conversion factor
  1354. 0x9201 : "ShutterSpeedValue", // Shutter speed
  1355. 0x9202 : "ApertureValue", // Lens aperture
  1356. 0x9203 : "BrightnessValue", // Value of brightness
  1357. 0x9204 : "ExposureBias", // Exposure bias
  1358. 0x9205 : "MaxApertureValue", // Smallest F number of lens
  1359. 0x9206 : "SubjectDistance", // Distance to subject in meters
  1360. 0x9207 : "MeteringMode", // Metering mode
  1361. 0x9208 : "LightSource", // Kind of light source
  1362. 0x9209 : "Flash", // Flash status
  1363. 0x9214 : "SubjectArea", // Location and area of main subject
  1364. 0x920A : "FocalLength", // Focal length of the lens in mm
  1365. 0xA20B : "FlashEnergy", // Strobe energy in BCPS
  1366. 0xA20C : "SpatialFrequencyResponse", //
  1367. 0xA20E : "FocalPlaneXResolution", // Number of pixels in width direction per FocalPlaneResolutionUnit
  1368. 0xA20F : "FocalPlaneYResolution", // Number of pixels in height direction per FocalPlaneResolutionUnit
  1369. 0xA210 : "FocalPlaneResolutionUnit", // Unit for measuring FocalPlaneXResolution and FocalPlaneYResolution
  1370. 0xA214 : "SubjectLocation", // Location of subject in image
  1371. 0xA215 : "ExposureIndex", // Exposure index selected on camera
  1372. 0xA217 : "SensingMethod", // Image sensor type
  1373. 0xA300 : "FileSource", // Image source (3 == DSC)
  1374. 0xA301 : "SceneType", // Scene type (1 == directly photographed)
  1375. 0xA302 : "CFAPattern", // Color filter array geometric pattern
  1376. 0xA401 : "CustomRendered", // Special processing
  1377. 0xA402 : "ExposureMode", // Exposure mode
  1378. 0xA403 : "WhiteBalance", // 1 = auto white balance, 2 = manual
  1379. 0xA404 : "DigitalZoomRation", // Digital zoom ratio
  1380. 0xA405 : "FocalLengthIn35mmFilm", // Equivalent foacl length assuming 35mm film camera (in mm)
  1381. 0xA406 : "SceneCaptureType", // Type of scene
  1382. 0xA407 : "GainControl", // Degree of overall image gain adjustment
  1383. 0xA408 : "Contrast", // Direction of contrast processing applied by camera
  1384. 0xA409 : "Saturation", // Direction of saturation processing applied by camera
  1385. 0xA40A : "Sharpness", // Direction of sharpness processing applied by camera
  1386. 0xA40B : "DeviceSettingDescription", //
  1387. 0xA40C : "SubjectDistanceRange", // Distance to subject
  1388.  
  1389. // other tags
  1390. 0xA005 : "InteroperabilityIFDPointer",
  1391. 0xA420 : "ImageUniqueID" // Identifier assigned uniquely to each image
  1392. };
  1393.  
  1394. var TiffTags = EXIF.TiffTags = {
  1395. 0x0100 : "ImageWidth",
  1396. 0x0101 : "ImageHeight",
  1397. 0x8769 : "ExifIFDPointer",
  1398. 0x8825 : "GPSInfoIFDPointer",
  1399. 0xA005 : "InteroperabilityIFDPointer",
  1400. 0x0102 : "BitsPerSample",
  1401. 0x0103 : "Compression",
  1402. 0x0106 : "PhotometricInterpretation",
  1403. 0x0112 : "Orientation",
  1404. 0x0115 : "SamplesPerPixel",
  1405. 0x011C : "PlanarConfiguration",
  1406. 0x0212 : "YCbCrSubSampling",
  1407. 0x0213 : "YCbCrPositioning",
  1408. 0x011A : "XResolution",
  1409. 0x011B : "YResolution",
  1410. 0x0128 : "ResolutionUnit",
  1411. 0x0111 : "StripOffsets",
  1412. 0x0116 : "RowsPerStrip",
  1413. 0x0117 : "StripByteCounts",
  1414. 0x0201 : "JPEGInterchangeFormat",
  1415. 0x0202 : "JPEGInterchangeFormatLength",
  1416. 0x012D : "TransferFunction",
  1417. 0x013E : "WhitePoint",
  1418. 0x013F : "PrimaryChromaticities",
  1419. 0x0211 : "YCbCrCoefficients",
  1420. 0x0214 : "ReferenceBlackWhite",
  1421. 0x0132 : "DateTime",
  1422. 0x010E : "ImageDescription",
  1423. 0x010F : "Make",
  1424. 0x0110 : "Model",
  1425. 0x0131 : "Software",
  1426. 0x013B : "Artist",
  1427. 0x8298 : "Copyright"
  1428. };
  1429.  
  1430. var GPSTags = EXIF.GPSTags = {
  1431. 0x0000 : "GPSVersionID",
  1432. 0x0001 : "GPSLatitudeRef",
  1433. 0x0002 : "GPSLatitude",
  1434. 0x0003 : "GPSLongitudeRef",
  1435. 0x0004 : "GPSLongitude",
  1436. 0x0005 : "GPSAltitudeRef",
  1437. 0x0006 : "GPSAltitude",
  1438. 0x0007 : "GPSTimeStamp",
  1439. 0x0008 : "GPSSatellites",
  1440. 0x0009 : "GPSStatus",
  1441. 0x000A : "GPSMeasureMode",
  1442. 0x000B : "GPSDOP",
  1443. 0x000C : "GPSSpeedRef",
  1444. 0x000D : "GPSSpeed",
  1445. 0x000E : "GPSTrackRef",
  1446. 0x000F : "GPSTrack",
  1447. 0x0010 : "GPSImgDirectionRef",
  1448. 0x0011 : "GPSImgDirection",
  1449. 0x0012 : "GPSMapDatum",
  1450. 0x0013 : "GPSDestLatitudeRef",
  1451. 0x0014 : "GPSDestLatitude",
  1452. 0x0015 : "GPSDestLongitudeRef",
  1453. 0x0016 : "GPSDestLongitude",
  1454. 0x0017 : "GPSDestBearingRef",
  1455. 0x0018 : "GPSDestBearing",
  1456. 0x0019 : "GPSDestDistanceRef",
  1457. 0x001A : "GPSDestDistance",
  1458. 0x001B : "GPSProcessingMethod",
  1459. 0x001C : "GPSAreaInformation",
  1460. 0x001D : "GPSDateStamp",
  1461. 0x001E : "GPSDifferential"
  1462. };
  1463.  
  1464. var StringValues = EXIF.StringValues = {
  1465. ExposureProgram : {
  1466. 0 : "Not defined",
  1467. 1 : "Manual",
  1468. 2 : "Normal program",
  1469. 3 : "Aperture priority",
  1470. 4 : "Shutter priority",
  1471. 5 : "Creative program",
  1472. 6 : "Action program",
  1473. 7 : "Portrait mode",
  1474. 8 : "Landscape mode"
  1475. },
  1476. MeteringMode : {
  1477. 0 : "Unknown",
  1478. 1 : "Average",
  1479. 2 : "CenterWeightedAverage",
  1480. 3 : "Spot",
  1481. 4 : "MultiSpot",
  1482. 5 : "Pattern",
  1483. 6 : "Partial",
  1484. 255 : "Other"
  1485. },
  1486. LightSource : {
  1487. 0 : "Unknown",
  1488. 1 : "Daylight",
  1489. 2 : "Fluorescent",
  1490. 3 : "Tungsten (incandescent light)",
  1491. 4 : "Flash",
  1492. 9 : "Fine weather",
  1493. 10 : "Cloudy weather",
  1494. 11 : "Shade",
  1495. 12 : "Daylight fluorescent (D 5700 - 7100K)",
  1496. 13 : "Day white fluorescent (N 4600 - 5400K)",
  1497. 14 : "Cool white fluorescent (W 3900 - 4500K)",
  1498. 15 : "White fluorescent (WW 3200 - 3700K)",
  1499. 17 : "Standard light A",
  1500. 18 : "Standard light B",
  1501. 19 : "Standard light C",
  1502. 20 : "D55",
  1503. 21 : "D65",
  1504. 22 : "D75",
  1505. 23 : "D50",
  1506. 24 : "ISO studio tungsten",
  1507. 255 : "Other"
  1508. },
  1509. Flash : {
  1510. 0x0000 : "Flash did not fire",
  1511. 0x0001 : "Flash fired",
  1512. 0x0005 : "Strobe return light not detected",
  1513. 0x0007 : "Strobe return light detected",
  1514. 0x0009 : "Flash fired, compulsory flash mode",
  1515. 0x000D : "Flash fired, compulsory flash mode, return light not detected",
  1516. 0x000F : "Flash fired, compulsory flash mode, return light detected",
  1517. 0x0010 : "Flash did not fire, compulsory flash mode",
  1518. 0x0018 : "Flash did not fire, auto mode",
  1519. 0x0019 : "Flash fired, auto mode",
  1520. 0x001D : "Flash fired, auto mode, return light not detected",
  1521. 0x001F : "Flash fired, auto mode, return light detected",
  1522. 0x0020 : "No flash function",
  1523. 0x0041 : "Flash fired, red-eye reduction mode",
  1524. 0x0045 : "Flash fired, red-eye reduction mode, return light not detected",
  1525. 0x0047 : "Flash fired, red-eye reduction mode, return light detected",
  1526. 0x0049 : "Flash fired, compulsory flash mode, red-eye reduction mode",
  1527. 0x004D : "Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",
  1528. 0x004F : "Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",
  1529. 0x0059 : "Flash fired, auto mode, red-eye reduction mode",
  1530. 0x005D : "Flash fired, auto mode, return light not detected, red-eye reduction mode",
  1531. 0x005F : "Flash fired, auto mode, return light detected, red-eye reduction mode"
  1532. },
  1533. SensingMethod : {
  1534. 1 : "Not defined",
  1535. 2 : "One-chip color area sensor",
  1536. 3 : "Two-chip color area sensor",
  1537. 4 : "Three-chip color area sensor",
  1538. 5 : "Color sequential area sensor",
  1539. 7 : "Trilinear sensor",
  1540. 8 : "Color sequential linear sensor"
  1541. },
  1542. SceneCaptureType : {
  1543. 0 : "Standard",
  1544. 1 : "Landscape",
  1545. 2 : "Portrait",
  1546. 3 : "Night scene"
  1547. },
  1548. SceneType : {
  1549. 1 : "Directly photographed"
  1550. },
  1551. CustomRendered : {
  1552. 0 : "Normal process",
  1553. 1 : "Custom process"
  1554. },
  1555. WhiteBalance : {
  1556. 0 : "Auto white balance",
  1557. 1 : "Manual white balance"
  1558. },
  1559. GainControl : {
  1560. 0 : "None",
  1561. 1 : "Low gain up",
  1562. 2 : "High gain up",
  1563. 3 : "Low gain down",
  1564. 4 : "High gain down"
  1565. },
  1566. Contrast : {
  1567. 0 : "Normal",
  1568. 1 : "Soft",
  1569. 2 : "Hard"
  1570. },
  1571. Saturation : {
  1572. 0 : "Normal",
  1573. 1 : "Low saturation",
  1574. 2 : "High saturation"
  1575. },
  1576. Sharpness : {
  1577. 0 : "Normal",
  1578. 1 : "Soft",
  1579. 2 : "Hard"
  1580. },
  1581. SubjectDistanceRange : {
  1582. 0 : "Unknown",
  1583. 1 : "Macro",
  1584. 2 : "Close view",
  1585. 3 : "Distant view"
  1586. },
  1587. FileSource : {
  1588. 3 : "DSC"
  1589. },
  1590.  
  1591. Components : {
  1592. 0 : "",
  1593. 1 : "Y",
  1594. 2 : "Cb",
  1595. 3 : "Cr",
  1596. 4 : "R",
  1597. 5 : "G",
  1598. 6 : "B"
  1599. }
  1600. };
  1601.  
  1602. function addEvent(element, event, handler) {
  1603. if (element.addEventListener) {
  1604. element.addEventListener(event, handler, false);
  1605. } else if (element.attachEvent) {
  1606. element.attachEvent("on" + event, handler);
  1607. }
  1608. }
  1609.  
  1610. function imageHasData(img) {
  1611. return !!(img.exifdata);
  1612. }
  1613.  
  1614.  
  1615. function base64ToArrayBuffer(base64, contentType) {
  1616. contentType = contentType || base64.match(/^data\:([^\;]+)\;base64,/mi)[1] || ''; // e.g. 'data:image/jpeg;base64,...' => 'image/jpeg'
  1617. base64 = base64.replace(/^data\:([^\;]+)\;base64,/gmi, '');
  1618. var binary = atob(base64);
  1619. var len = binary.length;
  1620. var buffer = new ArrayBuffer(len);
  1621. var view = new Uint8Array(buffer);
  1622. for (var i = 0; i < len; i++) {
  1623. view[i] = binary.charCodeAt(i);
  1624. }
  1625. return buffer;
  1626. }
  1627.  
  1628. function objectURLToBlob(url, callback) {
  1629. // var http = new XMLHttpRequest();
  1630. // http.open("GET", url, true);
  1631. // http.responseType = "blob";
  1632. // http.onload = function(e) {
  1633. // if (this.status == 200 || this.status === 0) {
  1634. // callback(this.response);
  1635. // }
  1636. // };
  1637. // http.send();
  1638.  
  1639. // GM.xmlHttpRequest({
  1640. // method: "GET",
  1641. // url: url,
  1642. // onload: function(e) {
  1643. // if (this.status == 200 || this.status === 0) {
  1644. // callback(this.response);
  1645. // }
  1646. // }
  1647. // });
  1648. }
  1649.  
  1650. function getImageData(img, callback) {
  1651. function handleBinaryFile(binFile) {
  1652. var data = findEXIFinJPEG(binFile);
  1653. var iptcdata = findIPTCinJPEG(binFile);
  1654. img.exifdata = data || {};
  1655. img.iptcdata = iptcdata || {};
  1656. if (callback) {
  1657. callback.call(img);
  1658. }
  1659. }
  1660.  
  1661. if (img.src) {
  1662. if (/^data\:/i.test(img.src)) { // Data URI
  1663. var arrayBuffer = base64ToArrayBuffer(img.src);
  1664. handleBinaryFile(arrayBuffer);
  1665.  
  1666. } else if (/^blob\:/i.test(img.src)) { // Object URL
  1667. var fileReader = new FileReader();
  1668. fileReader.onload = function(e) {
  1669. handleBinaryFile(e.target.result);
  1670. };
  1671. objectURLToBlob(img.src, function (blob) {
  1672. fileReader.readAsArrayBuffer(blob);
  1673. });
  1674. } else {
  1675. // var http = new XMLHttpRequest();
  1676. // http.onload = function() {
  1677. // if (this.status == 200 || this.status === 0) {
  1678. // handleBinaryFile(http.response);
  1679. // } else {
  1680. // throw "Could not load image";
  1681. // }
  1682. // http = null;
  1683. // };
  1684. // http.open("GET", img.src, true);
  1685. // http.responseType = "arraybuffer";
  1686. // http.send(null);
  1687.  
  1688. GM.xmlHttpRequest({
  1689. method: "GET",
  1690. url: img.src,
  1691. responseType: 'arraybuffer',
  1692. onload: function(response) {
  1693. if (response.status == 200 || response.status === 0) {
  1694. handleBinaryFile(response.response);
  1695. }
  1696. }
  1697. });
  1698. }
  1699. } else if (window.FileReader && (img instanceof window.Blob || img instanceof window.File)) {
  1700. var fileReader = new FileReader();
  1701. fileReader.onload = function(e) {
  1702. if (debug) console.log("Got file of length " + e.target.result.byteLength);
  1703. handleBinaryFile(e.target.result);
  1704. };
  1705.  
  1706. fileReader.readAsArrayBuffer(img);
  1707. }
  1708. }
  1709.  
  1710. function findEXIFinJPEG(file) {
  1711. var dataView = new DataView(file);
  1712.  
  1713. if (debug) console.log("Got file of length " + file.byteLength);
  1714. if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) {
  1715. if (debug) console.log("Not a valid JPEG");
  1716. return false; // not a valid jpeg
  1717. }
  1718.  
  1719. var offset = 2,
  1720. length = file.byteLength,
  1721. marker;
  1722.  
  1723. while (offset < length) {
  1724. if (dataView.getUint8(offset) != 0xFF) {
  1725. if (debug) console.log("Not a valid marker at offset " + offset + ", found: " + dataView.getUint8(offset));
  1726. return false; // not a valid marker, something is wrong
  1727. }
  1728.  
  1729. marker = dataView.getUint8(offset + 1);
  1730. if (debug) console.log(marker);
  1731.  
  1732. // we could implement handling for other markers here,
  1733. // but we're only looking for 0xFFE1 for EXIF data
  1734.  
  1735. if (marker == 225) {
  1736. if (debug) console.log("Found 0xFFE1 marker");
  1737.  
  1738. return readEXIFData(dataView, offset + 4, dataView.getUint16(offset + 2) - 2);
  1739.  
  1740. // offset += 2 + file.getShortAt(offset+2, true);
  1741.  
  1742. } else {
  1743. offset += 2 + dataView.getUint16(offset+2);
  1744. }
  1745.  
  1746. }
  1747.  
  1748. }
  1749.  
  1750. function findIPTCinJPEG(file) {
  1751. var dataView = new DataView(file);
  1752.  
  1753. if (debug) console.log("Got file of length " + file.byteLength);
  1754. if ((dataView.getUint8(0) != 0xFF) || (dataView.getUint8(1) != 0xD8)) {
  1755. if (debug) console.log("Not a valid JPEG");
  1756. return false; // not a valid jpeg
  1757. }
  1758.  
  1759. var offset = 2,
  1760. length = file.byteLength;
  1761.  
  1762.  
  1763. var isFieldSegmentStart = function(dataView, offset){
  1764. return (
  1765. dataView.getUint8(offset) === 0x38 &&
  1766. dataView.getUint8(offset+1) === 0x42 &&
  1767. dataView.getUint8(offset+2) === 0x49 &&
  1768. dataView.getUint8(offset+3) === 0x4D &&
  1769. dataView.getUint8(offset+4) === 0x04 &&
  1770. dataView.getUint8(offset+5) === 0x04
  1771. );
  1772. };
  1773.  
  1774. while (offset < length) {
  1775.  
  1776. if ( isFieldSegmentStart(dataView, offset )){
  1777.  
  1778. // Get the length of the name header (which is padded to an even number of bytes)
  1779. var nameHeaderLength = dataView.getUint8(offset+7);
  1780. if(nameHeaderLength % 2 !== 0) nameHeaderLength += 1;
  1781. // Check for pre photoshop 6 format
  1782. if(nameHeaderLength === 0) {
  1783. // Always 4
  1784. nameHeaderLength = 4;
  1785. }
  1786.  
  1787. var startOffset = offset + 8 + nameHeaderLength;
  1788. var sectionLength = dataView.getUint16(offset + 6 + nameHeaderLength);
  1789.  
  1790. return readIPTCData(file, startOffset, sectionLength);
  1791.  
  1792. break;
  1793.  
  1794. }
  1795.  
  1796.  
  1797. // Not the marker, continue searching
  1798. offset++;
  1799.  
  1800. }
  1801.  
  1802. }
  1803. var IptcFieldMap = {
  1804. 0x78 : 'caption',
  1805. 0x6E : 'credit',
  1806. 0x19 : 'keywords',
  1807. 0x37 : 'dateCreated',
  1808. 0x50 : 'byline',
  1809. 0x55 : 'bylineTitle',
  1810. 0x7A : 'captionWriter',
  1811. 0x69 : 'headline',
  1812. 0x74 : 'copyright',
  1813. 0x0F : 'category'
  1814. };
  1815. function readIPTCData(file, startOffset, sectionLength){
  1816. var dataView = new DataView(file);
  1817. var data = {};
  1818. var fieldValue, fieldName, dataSize, segmentType, segmentSize;
  1819. var segmentStartPos = startOffset;
  1820. while(segmentStartPos < startOffset+sectionLength) {
  1821. if(dataView.getUint8(segmentStartPos) === 0x1C && dataView.getUint8(segmentStartPos+1) === 0x02){
  1822. segmentType = dataView.getUint8(segmentStartPos+2);
  1823. if(segmentType in IptcFieldMap) {
  1824. dataSize = dataView.getInt16(segmentStartPos+3);
  1825. segmentSize = dataSize + 5;
  1826. fieldName = IptcFieldMap[segmentType];
  1827. fieldValue = getStringFromDB(dataView, segmentStartPos+5, dataSize);
  1828. // Check if we already stored a value with this name
  1829. if(data.hasOwnProperty(fieldName)) {
  1830. // Value already stored with this name, create multivalue field
  1831. if(data[fieldName] instanceof Array) {
  1832. data[fieldName].push(fieldValue);
  1833. }
  1834. else {
  1835. data[fieldName] = [data[fieldName], fieldValue];
  1836. }
  1837. }
  1838. else {
  1839. data[fieldName] = fieldValue;
  1840. }
  1841. }
  1842.  
  1843. }
  1844. segmentStartPos++;
  1845. }
  1846. return data;
  1847. }
  1848.  
  1849.  
  1850.  
  1851. function readTags(file, tiffStart, dirStart, strings, bigEnd) {
  1852. var entries = file.getUint16(dirStart, !bigEnd),
  1853. tags = {},
  1854. entryOffset, tag,
  1855. i;
  1856.  
  1857. for (i=0;i<entries;i++) {
  1858. entryOffset = dirStart + i*12 + 2;
  1859. tag = strings[file.getUint16(entryOffset, !bigEnd)];
  1860. if (!tag && debug) console.log("Unknown tag: " + file.getUint16(entryOffset, !bigEnd));
  1861. tags[tag] = readTagValue(file, entryOffset, tiffStart, dirStart, bigEnd);
  1862. }
  1863. return tags;
  1864. }
  1865.  
  1866.  
  1867. function readTagValue(file, entryOffset, tiffStart, dirStart, bigEnd) {
  1868. var type = file.getUint16(entryOffset+2, !bigEnd),
  1869. numValues = file.getUint32(entryOffset+4, !bigEnd),
  1870. valueOffset = file.getUint32(entryOffset+8, !bigEnd) + tiffStart,
  1871. offset,
  1872. vals, val, n,
  1873. numerator, denominator;
  1874.  
  1875. switch (type) {
  1876. case 1: // byte, 8-bit unsigned int
  1877. case 7: // undefined, 8-bit byte, value depending on field
  1878. if (numValues == 1) {
  1879. return file.getUint8(entryOffset + 8, !bigEnd);
  1880. } else {
  1881. offset = numValues > 4 ? valueOffset : (entryOffset + 8);
  1882. vals = [];
  1883. for (n=0;n<numValues;n++) {
  1884. vals[n] = file.getUint8(offset + n);
  1885. }
  1886. return vals;
  1887. }
  1888.  
  1889. case 2: // ascii, 8-bit byte
  1890. offset = numValues > 4 ? valueOffset : (entryOffset + 8);
  1891. return getStringFromDB(file, offset, numValues-1);
  1892.  
  1893. case 3: // short, 16 bit int
  1894. if (numValues == 1) {
  1895. return file.getUint16(entryOffset + 8, !bigEnd);
  1896. } else {
  1897. offset = numValues > 2 ? valueOffset : (entryOffset + 8);
  1898. vals = [];
  1899. for (n=0;n<numValues;n++) {
  1900. vals[n] = file.getUint16(offset + 2*n, !bigEnd);
  1901. }
  1902. return vals;
  1903. }
  1904.  
  1905. case 4: // long, 32 bit int
  1906. if (numValues == 1) {
  1907. return file.getUint32(entryOffset + 8, !bigEnd);
  1908. } else {
  1909. vals = [];
  1910. for (n=0;n<numValues;n++) {
  1911. vals[n] = file.getUint32(valueOffset + 4*n, !bigEnd);
  1912. }
  1913. return vals;
  1914. }
  1915.  
  1916. case 5: // rational = two long values, first is numerator, second is denominator
  1917. if (numValues == 1) {
  1918. numerator = file.getUint32(valueOffset, !bigEnd);
  1919. denominator = file.getUint32(valueOffset+4, !bigEnd);
  1920. val = new Number(numerator / denominator);
  1921. val.numerator = numerator;
  1922. val.denominator = denominator;
  1923. return val;
  1924. } else {
  1925. vals = [];
  1926. for (n=0;n<numValues;n++) {
  1927. numerator = file.getUint32(valueOffset + 8*n, !bigEnd);
  1928. denominator = file.getUint32(valueOffset+4 + 8*n, !bigEnd);
  1929. vals[n] = new Number(numerator / denominator);
  1930. vals[n].numerator = numerator;
  1931. vals[n].denominator = denominator;
  1932. }
  1933. return vals;
  1934. }
  1935.  
  1936. case 9: // slong, 32 bit signed int
  1937. if (numValues == 1) {
  1938. return file.getInt32(entryOffset + 8, !bigEnd);
  1939. } else {
  1940. vals = [];
  1941. for (n=0;n<numValues;n++) {
  1942. vals[n] = file.getInt32(valueOffset + 4*n, !bigEnd);
  1943. }
  1944. return vals;
  1945. }
  1946.  
  1947. case 10: // signed rational, two slongs, first is numerator, second is denominator
  1948. if (numValues == 1) {
  1949. return file.getInt32(valueOffset, !bigEnd) / file.getInt32(valueOffset+4, !bigEnd);
  1950. } else {
  1951. vals = [];
  1952. for (n=0;n<numValues;n++) {
  1953. vals[n] = file.getInt32(valueOffset + 8*n, !bigEnd) / file.getInt32(valueOffset+4 + 8*n, !bigEnd);
  1954. }
  1955. return vals;
  1956. }
  1957. }
  1958. }
  1959.  
  1960. function getStringFromDB(buffer, start, length) {
  1961. var outstr = "";
  1962. for (n = start; n < start+length; n++) {
  1963. outstr += String.fromCharCode(buffer.getUint8(n));
  1964. }
  1965. return outstr;
  1966. }
  1967.  
  1968. function readEXIFData(file, start) {
  1969. if (getStringFromDB(file, start, 4) != "Exif") {
  1970. if (debug) console.log("Not valid EXIF data! " + getStringFromDB(file, start, 4));
  1971. return false;
  1972. }
  1973.  
  1974. var bigEnd,
  1975. tags, tag,
  1976. exifData, gpsData,
  1977. tiffOffset = start + 6;
  1978.  
  1979. // test for TIFF validity and endianness
  1980. if (file.getUint16(tiffOffset) == 0x4949) {
  1981. bigEnd = false;
  1982. } else if (file.getUint16(tiffOffset) == 0x4D4D) {
  1983. bigEnd = true;
  1984. } else {
  1985. if (debug) console.log("Not valid TIFF data! (no 0x4949 or 0x4D4D)");
  1986. return false;
  1987. }
  1988.  
  1989. if (file.getUint16(tiffOffset+2, !bigEnd) != 0x002A) {
  1990. if (debug) console.log("Not valid TIFF data! (no 0x002A)");
  1991. return false;
  1992. }
  1993.  
  1994. var firstIFDOffset = file.getUint32(tiffOffset+4, !bigEnd);
  1995.  
  1996. if (firstIFDOffset < 0x00000008) {
  1997. if (debug) console.log("Not valid TIFF data! (First offset less than 8)", file.getUint32(tiffOffset+4, !bigEnd));
  1998. return false;
  1999. }
  2000.  
  2001. tags = readTags(file, tiffOffset, tiffOffset + firstIFDOffset, TiffTags, bigEnd);
  2002.  
  2003. if (tags.ExifIFDPointer) {
  2004. exifData = readTags(file, tiffOffset, tiffOffset + tags.ExifIFDPointer, ExifTags, bigEnd);
  2005. for (tag in exifData) {
  2006. switch (tag) {
  2007. case "LightSource" :
  2008. case "Flash" :
  2009. case "MeteringMode" :
  2010. case "ExposureProgram" :
  2011. case "SensingMethod" :
  2012. case "SceneCaptureType" :
  2013. case "SceneType" :
  2014. case "CustomRendered" :
  2015. case "WhiteBalance" :
  2016. case "GainControl" :
  2017. case "Contrast" :
  2018. case "Saturation" :
  2019. case "Sharpness" :
  2020. case "SubjectDistanceRange" :
  2021. case "FileSource" :
  2022. exifData[tag] = StringValues[tag][exifData[tag]];
  2023. break;
  2024.  
  2025. case "ExifVersion" :
  2026. case "FlashpixVersion" :
  2027. exifData[tag] = String.fromCharCode(exifData[tag][0], exifData[tag][1], exifData[tag][2], exifData[tag][3]);
  2028. break;
  2029.  
  2030. case "ComponentsConfiguration" :
  2031. exifData[tag] =
  2032. StringValues.Components[exifData[tag][0]] +
  2033. StringValues.Components[exifData[tag][1]] +
  2034. StringValues.Components[exifData[tag][2]] +
  2035. StringValues.Components[exifData[tag][3]];
  2036. break;
  2037. }
  2038. tags[tag] = exifData[tag];
  2039. }
  2040. }
  2041.  
  2042. if (tags.GPSInfoIFDPointer) {
  2043. gpsData = readTags(file, tiffOffset, tiffOffset + tags.GPSInfoIFDPointer, GPSTags, bigEnd);
  2044. for (tag in gpsData) {
  2045. switch (tag) {
  2046. case "GPSVersionID" :
  2047. gpsData[tag] = gpsData[tag][0] +
  2048. "." + gpsData[tag][1] +
  2049. "." + gpsData[tag][2] +
  2050. "." + gpsData[tag][3];
  2051. break;
  2052. }
  2053. tags[tag] = gpsData[tag];
  2054. }
  2055. }
  2056.  
  2057. return tags;
  2058. }
  2059.  
  2060. EXIF.getData = function(img, callback) {
  2061. if ((img instanceof Image || img instanceof HTMLImageElement) && !img.complete) return false;
  2062.  
  2063. if (!imageHasData(img)) {
  2064. getImageData(img, callback);
  2065. } else {
  2066. if (callback) {
  2067. callback.call(img);
  2068. }
  2069. }
  2070. return true;
  2071. }
  2072.  
  2073. EXIF.getTag = function(img, tag) {
  2074. if (!imageHasData(img)) return;
  2075. return img.exifdata[tag];
  2076. }
  2077.  
  2078. EXIF.getAllTags = function(img) {
  2079. if (!imageHasData(img)) return {};
  2080. var a,
  2081. data = img.exifdata,
  2082. tags = {};
  2083. for (a in data) {
  2084. if (data.hasOwnProperty(a)) {
  2085. tags[a] = data[a];
  2086. }
  2087. }
  2088. return tags;
  2089. }
  2090.  
  2091. EXIF.pretty = function(img) {
  2092. if (!imageHasData(img)) return "";
  2093. var a,
  2094. data = img.exifdata,
  2095. strPretty = "";
  2096. for (a in data) {
  2097. if (data.hasOwnProperty(a)) {
  2098. if (typeof data[a] == "object") {
  2099. if (data[a] instanceof Number) {
  2100. strPretty += a + " : " + data[a] + " [" + data[a].numerator + "/" + data[a].denominator + "]\r\n";
  2101. } else {
  2102. strPretty += a + " : [" + data[a].length + " values]\r\n";
  2103. }
  2104. } else {
  2105. strPretty += a + " : " + data[a] + "\r\n";
  2106. }
  2107. }
  2108. }
  2109. return strPretty;
  2110. }
  2111.  
  2112. EXIF.readFromBinaryFile = function(file) {
  2113. return findEXIFinJPEG(file);
  2114. }
  2115.  
  2116. if (typeof define === 'function' && define.amd) {
  2117. define('exif-js', [], function() {
  2118. return EXIF;
  2119. });
  2120. }
  2121. }.call(this));
  2122. // -- https://github.com/exif-js/exif-js
  2123.