Geocaching.com + Project-GC

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

La data de 01-12-2016. Vezi ultima versiune.

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