Stig's Flickr Fixr

Show photographer's albums on photostream-pages, Increase display-size and quality of "old" uploads, Photographer's other photos by tag-links, Links to album-map and album-comments, Actually show a geotagged photo on the associated map, Top-pagers - And more to come?...

目前为 2018-05-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Stig's Flickr Fixr
  3. // @namespace dk.rockland.userscript.flickr.fixr
  4. // @description Show photographer's albums on photostream-pages, Increase display-size and quality of "old" uploads, Photographer's other photos by tag-links, Links to album-map and album-comments, Actually show a geotagged photo on the associated map, Top-pagers - And more to come?...
  5. // @author Stig Nygaard, http://www.rockland.dk, https://www.flickr.com/photos/stignygaard/
  6. // @homepageURL http://www.rockland.dk/userscript/flickr/fixr/
  7. // @supportURL https://www.flickr.com/groups/flickrhacks/discuss/72157655601688753/
  8. // @icon https://raw.githubusercontent.com/StigNygaard/Stigs_Flickr_Fixr/master/icons/fixr32.png
  9. // @icon64 https://raw.githubusercontent.com/StigNygaard/Stigs_Flickr_Fixr/master/icons/fixr64.png
  10. // @match https://*.flickr.com/*
  11. // @version 2018.04.19.0
  12. // @run-at document-start
  13. // @grant none
  14. // @noframes
  15. // ==/UserScript==
  16.  
  17. // CHANGELOG - The most important updates/versions:
  18. var changelog = [
  19. {version: '2018.04.19.0', description: 'More reliable map-link fix when Flickr is slow to build a photopage.'},
  20. {version: '2017.10.30.0', description: 'Revert one of two Greasemonkey 4 workarounds. A "@grant none" issue seems to be fixed from GM version 4.0alpha11 ...'},
  21. {version: '2017.10.28.0', description: 'Workarounds for a couple of shortcomings in early versions of new/upcoming Greasemonkey 4 WebExtension.'},
  22. {version: '2017.07.31.0', description: 'New feature: Adding a Google Maps link on geotagged photos. Also: Removing unused code. Development code now in GitHub repository: https://github.com/StigNygaard/Stigs_Flickr_Fixr'},
  23. {version: '2016.06.12.3', description: 'An "un-scale button" to align image-size with (native) notes (on photo-pages, but not in lightbox mode).'},
  24. {version: '2016.06.07.1', description: 'Disabling the script\'s notes-feature, because OFFICIAL NATIVE NOTES-SUPPORT is back on Flickr! :-)'},
  25. {version: '2016.03.11.1', description: 'A link to "recent uploads page" added on the Explore page. Ctrl-click fix for opening tabs in background on search pages (Firefox-only problem?).'},
  26. {version: '2016.02.09.0', description: 'New feature: Link to Explore Calendar added to Explore page.'},
  27. {version: '2016.02.06.2', description: 'New feature: Top-pagers! Hover the mouse in the center just above photostreams to show a pagination-bar.'},
  28. {version: '2016.01.30.0', description: 'Killing the terrible annoying sign-up box that keeps popping up if you are *not* logged in on Flickr. Also fixes for and fine-tuning of the notes-support.'},
  29. {version: '2016.01.24.3', description: 'New feature: Updating notes on photos! Besides displaying, you can now also Create, Edit and Delete notes (in a "hacky" and slightly restricted but generally usable way)'},
  30. {version: '2015.12.05.2', description: 'Photo-notes support now includes displaying formatting and active links.'},
  31. {version: '2015.12.03.2', description: 'New feature: Basic "beta" support for the good old photo-notes (read-only, no formatting/links).'},
  32. {version: '2015.11.28.1', description: 'New feature: Album-headers are now updated with links to album-map and album-comments.'},
  33. {version: '2015.08.26.4', description: 'Initial release version. Photo scale/replace, album column and tag-feature.'}
  34. ];
  35.  
  36. var DEBUG = false;
  37. function log(s) {
  38. if (DEBUG && window.console) {
  39. window.console.log(s);
  40. }
  41. }
  42. if (DEBUG) {
  43. if ('loading' === document.readyState) {
  44. log("This userscript is running at document-start time.");
  45. } else {
  46. log("This userscript is running with document.readyState: " + document.readyState);
  47. }
  48. window.addEventListener('DOMContentLoaded', function(){log('(onDOMContentLoaded)');}, false);
  49. window.addEventListener('focus', function(){log('(onfocus)');}, false);
  50. window.addEventListener('load', function(){log('(onload)');}, false);
  51. window.addEventListener('pageshow', function(){log('(onpageshow)');}, false);
  52. window.addEventListener('resize', function(){log('(onresize)');}, false);
  53. window.addEventListener('hashchange', function(){log('(onhashchange)');}, false);
  54. window.addEventListener('blur', function(){log('(onblur)');}, false);
  55. }
  56.  
  57.  
  58. // FIXR page-tracker
  59. var fixr = fixr || {
  60. context: {
  61. pageType: '',
  62. pageSubType: '',
  63. userId: '',
  64. photographerId: '', // value might be delayed (If uninitialized, try call initPhotographerId())
  65. photographerIcon: '',
  66. photographerAlias: '', // (pathalias) bonus-info sometimes initialized (from url) when initializing photoId or albumId
  67. photographerName: '',
  68. photoId: '',
  69. albumId: '',
  70. groupId: '',
  71. galleryId: ''
  72. },
  73. content: null,
  74. pageactionsCount: 0,
  75. timerResizeActionDelayed: 0,
  76. onPageHandlers: [],
  77. onResizeHandlers: [],
  78. onFocusHandlers: [],
  79. runningDirty: function() { // In-development and extra experiments enabled?
  80. return (DEBUG && (fixr.context.userId==='10259776@N00'));
  81. },
  82. timer: {
  83. _test: 0 // TODO
  84. },
  85. clock: {
  86. _d: null,
  87. _pst: null, // Pacific Standard Time
  88. _explore: null,
  89. tick: function () {
  90. this._d = new Date();
  91. this._pst = new Date(this._d);
  92. this._pst.setHours(this._d.getHours() - 8); // PST = UTC-08
  93. this._explore = new Date(this._d);
  94. this._explore.setHours(this._d.getHours() - 28); // Explore beat, yesterday UTC-4
  95. // this._y.setDate(this._y.getDate() - 1);
  96. return this._pst;
  97. },
  98. pst: function () { // yyyy-mm-dd tt:mm PST
  99. return (this._pst || this.tick()).toISOString().substring(0,16).replace('T',' ')+' PST';
  100. },
  101. explore: function () { // yyyy-mm-dd tt:mm Explore beat!
  102. if (this._explore===null) {
  103. this.tick();
  104. }
  105. return this._explore.toISOString().substring(0,16).replace('T',' ')+' Explore beat!';
  106. }
  107. },
  108. initUserId: function () {
  109. if (window.auth && window.auth.user && window.auth.user.nsid) {
  110. fixr.context.userId = window.auth.user.nsid;
  111. return true;
  112. }
  113. return false;
  114. },
  115. initPhotographerName: function () {
  116. if (fixr.content.querySelector('a.owner-name')) {
  117. fixr.context.photographerName = fixr.content.querySelector('a.owner-name').textContent;
  118. return true;
  119. }
  120. return false;
  121. },
  122. initPhotographerId: function () { // photographer/attribution id
  123. var elem;
  124. if (document.querySelector('div.photostream-page-view')) {
  125. // photostream
  126. elem = document.querySelector('div.photostream-page-view div.fluid-photostream-coverphoto-view div.avatar.person');
  127. } else if (document.querySelector('div.photo-page-scrappy-view')) {
  128. // photopage
  129. elem = document.querySelector('div.photo-page-scrappy-view div.sub-photo-view div.avatar.person');
  130. } else if (document.querySelector('div.photo-page-lightbox-scrappy-view')) {
  131. // photopage lightbox
  132. elem = document.querySelector('div.photo-page-lightbox-scrappy-view div.photo-well-view div.photo-attribution div.avatar.person');
  133. } else if (document.querySelector('div.album-page-view')) {
  134. // album page
  135. elem = document.querySelector('div.album-page-view div.album-container div.album-header-view div.album-attribution div.avatar.person');
  136. } else {
  137. log('we do not look for photographerId on this page');
  138. return true;
  139. }
  140. // album oversigt
  141. // etc...
  142. // men minus f.eks. favorites oversigt!
  143. if (!elem) {
  144. log('fixr.initPhotographerId() - Attribution elem NOT found - returning false');
  145. return false;
  146. } // re-run a little later???
  147. log('fixr.initPhotographerId() - Attribution elem found');
  148. // (div.avatar.person).style.backgroundImage=url(https://s.yimg.com/pw/images/buddyicon07_r.png#44504567@N00)
  149. // .style.backgroundImage=url(//c4.staticflickr.com/8/7355/buddyicons/10259776@N00_r.jpg?1372021232#10259776@N00)
  150. if (elem.style.backgroundImage) {
  151. log('fixr.initPhotographerId() - elem has style.backgroundImage "' + elem.style.backgroundImage + '", now looking for the attribution id...');
  152. var pattern = /url[^#\?]+(\/\/[^#\?]+\.com\/[^#\?]+\/buddyicon[^\?\#]+)[^#]*#(\d+\@N\d{2})/i;
  153. // var pattern = /\/buddyicons\/(\d+\@N\d{2})\D+/i;
  154. var result = elem.style.backgroundImage.match(pattern);
  155. if (result) {
  156. log('fixr.initPhotographerId() - Attribution pattern match found: ' + result[0]);
  157. log('fixr.initPhotographerId() - the attribution icon is ' + result[1]);
  158. log('fixr.initPhotographerId() - the attribution id is ' + result[2]);
  159. fixr.context.photographerIcon = result[1];
  160. fixr.context.photographerId = result[2];
  161. } else {
  162. log('fixr.initPhotographerId() - attribution pattern match not found');
  163. return false;
  164. }
  165. } else {
  166. log('fixr.initPhotographerId() - elem.style.backgroundImage not found');
  167. return false;
  168. }
  169. log('fixr.initPhotographerId() - returning true...');
  170. return true;
  171. },
  172. initPhotoId: function () { // Photo Id
  173. // *flickr.com/photos/user/PId/*
  174. var pattern = /^\/photos\/([^\/]+)\/([\d]{2,})/i;
  175. var result = window.location.pathname.match(pattern);
  176. if (result) {
  177. log('url match med photoId=' + result[2]);
  178. log('url match med photographerAlias=' + result[1]);
  179. fixr.context.photoId = result[2];
  180. fixr.context.photographerAlias = result[1];
  181. return true;
  182. } else {
  183. log('*** initPhotoId() returnerer false! reg-pattern fandt ikke match i pathname='+window.location.pathname);
  184. }
  185. return false;
  186. },
  187. initAlbumId: function () {
  188. // *flickr.com/photos/user/albums/AId/*
  189. // *flickr.com/photos/user/sets/AId/*
  190. var pattern = /^\/photos\/([^\/]+)\/albums\/([\d]{2,})/i;
  191. var result = window.location.pathname.match(pattern);
  192. if (!result) {
  193. pattern = /^\/photos\/([^\/]+)\/sets\/([\d]{2,})/i;
  194. result = window.location.pathname.match(pattern);
  195. }
  196. if (result) {
  197. log('url match med albumId=' + result[2]);
  198. log('url match med photographerAlias=' + result[1]);
  199. fixr.context.albumId = result[2];
  200. fixr.context.photographerAlias = result[1];
  201. return true;
  202. }
  203. return false;
  204. },
  205. pageActions: function () {
  206. fixr.clock.tick();
  207. if (fixr.content) {
  208. log('fixr.pageActions() has started with fixr.content defined');
  209. } else {
  210. log('fixr.pageActions() was called, but fixr.content NOT defined');
  211. return;
  212. }
  213. fixr.pageactionsCount++;
  214. for (var p in fixr.context) { // reset context on new page
  215. if (fixr.context.hasOwnProperty(p)) {
  216. fixr.context[p] = '';
  217. }
  218. }
  219. if (fixr.content.querySelector('div.photostream-page-view')) {
  220. if (fixr.content.querySelector('div.slideshow-view')) {
  221. fixr.context.pageType = 'PHOTOSTREAM SLIDESHOW';
  222. } else {
  223. fixr.context.pageType = 'PHOTOSTREAM';
  224. }
  225. } else if (fixr.content.querySelector('div.photo-page-scrappy-view')) {
  226. fixr.context.pageType = 'PHOTOPAGE';
  227. if (fixr.content.querySelector('div.vr-overlay-view') && fixr.content.querySelector('div.vr-overlay-view').hasChildNodes()) {
  228. fixr.context.pageSubType = 'VR'; // maybe I can find a better way to detect, not sure how reliable this is?
  229. } else if (fixr.content.querySelector('div.videoplayer')) {
  230. fixr.context.pageSubType='VIDEO';
  231. } else {
  232. fixr.context.pageSubType='PHOTO';
  233. }
  234. } else if (fixr.content.querySelector('div.photo-page-lightbox-scrappy-view')) {
  235. fixr.context.pageType = 'PHOTOPAGE LIGHTBOX';
  236. if (fixr.content.querySelector('div.vr-overlay-view') && fixr.content.querySelector('div.vr-overlay-view').hasChildNodes()) {
  237. fixr.context.pageSubType='VR'; // VR-mode currently not supported in lightbox?
  238. } else if (fixr.content.querySelector('div.videoplayer')) {
  239. fixr.context.pageSubType='VIDEO';
  240. } else {
  241. fixr.context.pageSubType='PHOTO';
  242. }
  243. } else if (fixr.content.querySelector('div.albums-list-page-view')) {
  244. fixr.context.pageType = 'ALBUMSLIST';
  245. } else if (fixr.content.querySelector('div.album-page-view')) {
  246. if (fixr.content.querySelector('div.slideshow-view')) {
  247. fixr.context.pageType = 'ALBUM SLIDESHOW';
  248. } else {
  249. fixr.context.pageType = 'ALBUM';
  250. }
  251. } else if (fixr.content.querySelector('div.cameraroll-page-view')) {
  252. fixr.context.pageType = 'CAMERAROLL';
  253. } else if (fixr.content.querySelector('div.explore-page-view')) {
  254. fixr.context.pageType = 'EXPLORE';
  255. } else if (fixr.content.querySelector('div.favorites-page-view')) {
  256. if (fixr.content.querySelector('div.slideshow-view')) {
  257. fixr.context.pageType = 'FAVORITES SLIDESHOW';
  258. } else {
  259. fixr.context.pageType = 'FAVORITES';
  260. }
  261. } else if (fixr.content.querySelector('div.groups-list-view')) {
  262. fixr.context.pageType = 'GROUPSLIST'; // personal grouplist
  263. } else if (fixr.content.querySelector('div#activityFeed')) { // id=main i stedet for id=fixr.content
  264. fixr.context.pageType = 'ACTIVITYFEED'; // aka. front page -> UPDATES ?
  265. } else if (fixr.content.querySelector('div#allsizes-photo')) {
  266. fixr.context.pageType = 'SIZES'; // View all sizes - page
  267. } else {
  268. // fixr.context.pageType = ''; // unknown
  269. }
  270.  
  271. log('fixr.context.pageType = ' + fixr.context.pageType);
  272. log('fixr.context.pageSubType = '+fixr.context.pageSubType);
  273. if (fixr.initUserId()) {
  274. log('fixr.initUserId() returned with succes: '+fixr.context.userId);
  275. } else {
  276. log('fixr.initUserId() returned FALSE!');
  277. }
  278. if (fixr.initPhotographerId()) {
  279. log('fixr.initPhotographerId() returned true in first try...');
  280. } else {
  281. log('fixr.initPhotographerId() returned false - re-running delayed...');
  282. setTimeout(fixr.initPhotographerId, 1800);
  283. }
  284. if (fixr.initPhotoId()) {
  285. log('fixr.initPhotoId() returned true in first try...');
  286. } else {
  287. log('fixr.initPhotoId() returned false - re-running delayed...');
  288. setTimeout(fixr.initPhotoId, 1500);
  289. }
  290. if (fixr.initAlbumId()) {
  291. log('fixr.initAlbumId() returned true in first try...');
  292. }
  293. if (fixr.initPhotographerName()) {
  294. log('fixr.initPhotographerName() returned true in first try...');
  295. } else {
  296. setTimeout(fixr.initPhotographerName, 1500);
  297. }
  298.  
  299. // Now run the page handlers....
  300. if (fixr.onPageHandlers && fixr.onPageHandlers !== null && fixr.onPageHandlers.length) {
  301. log('We have ' + fixr.onPageHandlers.length + ' onPage handlers starting now...');
  302. for (var f = 0; f < fixr.onPageHandlers.length; f++) {
  303. fixr.onPageHandlers[f]();
  304. }
  305. }
  306. },
  307. setupContent: function () {
  308. if (document.getElementById('content')) {
  309. fixr.content = document.getElementById('content');
  310. } else if (document.getElementById('main')) {
  311. fixr.content = document.getElementById('main'); // frontpage
  312. }
  313. if (fixr.content && fixr.content.id) {
  314. log('fixr.content.id = ' + fixr.content.id);
  315. } else {
  316. log('content or main element NOT found!');
  317. }
  318. },
  319. runPageActionsIfMissed: function () {
  320. if (fixr.pageactionsCount === 0) {
  321. log('Vi kører fixr.pageActions() på bagkant via onload...');
  322. fixr.setupContent();
  323. if (fixr.content === null) {
  324. log('Vi kan IKKE køre fixr.pageActions() på bagkant, da fixr.content ikke er defineret');
  325. return;
  326. }
  327. fixr.pageActions();
  328. } else {
  329. log('ej nødvendigt at køre fixr.pageActions() på bagkant i dette tilfælde...');
  330. }
  331. },
  332. runDelayedPageActionsIfMissed: function () {
  333. setTimeout(fixr.runPageActionsIfMissed, 2000);
  334. },
  335. resizeActions: function () {
  336. if (fixr.onResizeHandlers && fixr.onResizeHandlers !== null && fixr.onResizeHandlers.length) {
  337. for (var f = 0; f < fixr.onResizeHandlers.length; f++) {
  338. fixr.onResizeHandlers[f]();
  339. }
  340. }
  341. },
  342. resizeActionsDelayed: function () { // or "preburner"
  343. clearTimeout(fixr.timerResizeActionDelayed);
  344. fixr.timerResizeActionDelayed = setTimeout(fixr.resizeActions, 250);
  345. },
  346. focusActions: function () {
  347. if (fixr.onFocusHandlers && fixr.onFocusHandlers !== null && fixr.onFocusHandlers.length) {
  348. for (var f = 0; f < fixr.onFocusHandlers.length; f++) {
  349. fixr.onFocusHandlers[f]();
  350. }
  351. }
  352. },
  353. setupObserver: function () {
  354. log('fixr.setupObserve INITIALIZATION START');
  355. fixr.setupContent();
  356. if (fixr.content === null) {
  357. log('Init fails because content not defined');
  358. return;
  359. }
  360. // create an observer instance
  361. var observer = new MutationObserver(function (mutations) {
  362. log('NEW PAGE MUTATION!');
  363. //mutations.forEach(function(mutation) {
  364. // log('MO: '+mutation.type); // might check for specific type of "mutations" (MutationRecord)
  365. //});
  366. fixr.pageActions();
  367. }); // MutationObserver end
  368. // configuration of the observer:
  369. var config = {attributes: false, childList: true, subtree: false, characterData: false};
  370. observer.observe(fixr.content, config);
  371. log('fixr.setupObserve INITIALIZATION DONE');
  372. },
  373. init: function (runNow, onPageHandlerArray, onResizeHandlerArray, onFocusHandlerArray) {
  374. // General page-change observer setup:
  375. if (document.readyState === 'interactive') { // already late?
  376. fixr.setupObserver();
  377. }
  378. window.addEventListener('DOMContentLoaded', fixr.setupObserver, false); // Page on DOMContentLoaded
  379. window.addEventListener('load', fixr.runDelayedPageActionsIfMissed, false); // Page on load
  380. window.addEventListener('resize', fixr.resizeActionsDelayed, false); // også på resize
  381. window.addEventListener('focus', fixr.focusActions, false);
  382. if (onPageHandlerArray && onPageHandlerArray !== null && onPageHandlerArray.length) {
  383. fixr.onPageHandlers = onPageHandlerArray; // Replace by adding with a one-by-one by "helper" for flexibility?
  384. }
  385. if (onResizeHandlerArray && onResizeHandlerArray !== null && onResizeHandlerArray.length) {
  386. fixr.onResizeHandlers = onResizeHandlerArray; // Replace by adding with a one-by-one by "helper" for flexibility?
  387. }
  388. if (onFocusHandlerArray && onFocusHandlerArray !== null && onFocusHandlerArray.length) {
  389. fixr.onFocusHandlers = onFocusHandlerArray;
  390. }
  391.  
  392. if (runNow && runNow.length) {
  393. log('We have ' + runNow.length + ' early running methods starting now at document.readyState = ' + document.readyState);
  394. for (var f = 0; f < runNow.length; f++) {
  395. runNow[f]();
  396. }
  397. }
  398. }
  399. };
  400. // FIXR page-tracker end
  401.  
  402.  
  403. function updateMapLink() {
  404. if (fixr.context.pageType !== 'PHOTOPAGE') {
  405. return; // exit if not photopage
  406. }
  407. log('updateMapLink() running at readystate=' + document.readyState + ' and with photoId=' + fixr.context.photoId);
  408. if (fixr.context.photoId) {
  409. var maplink = fixr.content.querySelector('a.static-maps');
  410. if (maplink) {
  411. if (maplink.getAttribute('href') && (maplink.getAttribute('href').indexOf('map/?') > 0) && (maplink.getAttribute('href').indexOf('&photo=') === -1)) {
  412. maplink.setAttribute('href', maplink.getAttribute('href') + '&photo=' + fixr.context.photoId);
  413. log('link is updated by updateMapLink() at readystate=' + document.readyState);
  414. try {
  415. var lat = maplink.getAttribute('href').match(/Lat=(\-?[\d\.]+)/i)[1];
  416. var lon = maplink.getAttribute('href').match(/Lon=(\-?[\d\.]+)/i)[1];
  417. fixr.content.querySelector('li.c-charm-item-location').insertAdjacentHTML('beforeend', '<div class="location-data-container"><a href="https://www.google.com/maps/search/?api=1&amp;query=' + lat + ',' + lon + '">Show location on Google Maps</a></div>');
  418. }
  419. catch (e) {
  420. log('Failed creating Google Maps link: ' + e);
  421. }
  422. } else {
  423. log('link NOT updated by updateMapLink(). Invalid element or already updated. readystate=' + document.readyState);
  424. }
  425. } else {
  426. log('NO maplink found at readystate=' + document.readyState + '. Re-try later?');
  427. }
  428. } else {
  429. log('NO photoId found at readystate=' + document.readyState);
  430. }
  431. }
  432. function updateMapLinkDelayed() {
  433. if (fixr.context.pageType === 'PHOTOPAGE') {
  434. log('updateMapLinkDelayed() running... with pageType=' + fixr.context.pageType);
  435. setTimeout(updateMapLink, 2000); // make maplink work better on photopage
  436. setTimeout(updateMapLink, 4000); // Twice. Photopage is sometimes a bit slow building
  437. setTimeout(updateMapLink, 8000); // Triple. Photopage is sometimes very slow building
  438. }
  439. }
  440.  
  441. var album = { // cache to avoid repeating requests
  442. albumId: '',
  443. commentCount: 0
  444. };
  445. function updateAlbumCommentCount() {
  446. var _reqAlbumComments = null;
  447. if (window.XMLHttpRequest) {
  448. _reqAlbumComments = new XMLHttpRequest();
  449. if (typeof _reqAlbumComments.overrideMimeType !== 'undefined') {
  450. _reqAlbumComments.overrideMimeType('text/html');
  451. }
  452.  
  453. _reqAlbumComments.onreadystatechange = function () {
  454. if (_reqAlbumComments.readyState === 4 && _reqAlbumComments.status === 200) {
  455. log('_reqAlbumComments returned status=' + _reqAlbumComments.status);
  456. var doc = document.implementation.createHTMLDocument("sizeDoc");
  457. doc.documentElement.innerHTML = _reqAlbumComments.responseText;
  458. album.albumId = fixr.context.albumId;
  459. album.commentCount = -1;
  460. var e = doc.body.querySelectorAll('span.LinksNew b.Here');
  461. if (e && e.length === 1) {
  462. var n = parseInt(e[0].textContent, 10);
  463. if (isNaN(n)) {
  464. album.commentCount = 0;
  465. } else {
  466. album.commentCount = n;
  467. }
  468. } else {
  469. album.commentCount = -1;
  470. log('b.Here??? ');
  471. }
  472. if (document.getElementById('albumCommentCount')) {
  473. if (album.commentCount === -1) {
  474. document.getElementById('albumCommentCount').innerHTML = '?';
  475. } else {
  476. document.getElementById('albumCommentCount').innerHTML = String(album.commentCount);
  477. }
  478. } else {
  479. log('albumCommentCount element not found');
  480. }
  481. } else {
  482. // wait for the call to complete
  483. }
  484. };
  485.  
  486. if (fixr.context.albumId === album.albumId && fixr.context.albumId !== '' && album.commentCount !== -1) {
  487. log('Usinging CACHED album count!...');
  488. document.getElementById('albumCommentCount').innerHTML = String(album.commentCount);
  489. } else if (fixr.context.albumId !== '') {
  490. var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/' + fixr.context.albumId + '/comments/';
  491. _reqAlbumComments.open('GET', url, true);
  492. _reqAlbumComments.send(null);
  493. } else {
  494. log('albumId not initialized');
  495. }
  496. } else {
  497. log('understøtter ikke XMLHttpRequest');
  498. }
  499. }
  500.  
  501. var albums = { // cache albums to avoid repeating requests
  502. ownerId: '',
  503. html: '',
  504. count: 0
  505. };
  506. function getAlbumlist() {
  507. var _reqAlbumlist = null;
  508. if (window.XMLHttpRequest) {
  509. _reqAlbumlist = new XMLHttpRequest();
  510. if (typeof _reqAlbumlist.overrideMimeType !== 'undefined') {
  511. _reqAlbumlist.overrideMimeType('text/html');
  512. }
  513.  
  514. _reqAlbumlist.onreadystatechange = function () {
  515. if (_reqAlbumlist.readyState === 4 && _reqAlbumlist.status === 200) {
  516. log('_reqAlbumlist returned status=' + _reqAlbumlist.status); // + ', \ntext:\n' + _reqAlbumlist.responseText);
  517. var doc = document.implementation.createHTMLDocument("sizeDoc");
  518. doc.documentElement.innerHTML = _reqAlbumlist.responseText;
  519.  
  520. albums.ownerId = fixr.context.photographerId;
  521. albums.html = '';
  522. albums.count = 0;
  523. var e = doc.body.querySelectorAll('div.photo-list-album-view');
  524. var imgPattern = /url\([\'\"]*([^\)\'\"]+)(\.[jpgtifn]{3,4})[\'\"]*\)/i;
  525. if (e && e.length > 0) {
  526. albums.count = e.length;
  527. for (var i = 0; i < Math.min(10, e.length); i++) {
  528. var imgUrl = '';
  529. //log(e[i].outerHTML);
  530. //log('A7 (' + i + ') : ' + e[i].style.backgroundImage);
  531. // var result = e[i].style.backgroundImage.match(imgPattern); // strangely not working in Chrome
  532. var result = (e[i].outerHTML).match(imgPattern); // quick work-around for above (works for now)
  533. if (result) {
  534. // imgUrl = result[1].replace(/_[a-z]$/, '') + '_s' + result[2];
  535. imgUrl = result[1].replace(/_[a-z]$/, '') + '_q' + result[2];
  536. log('imgUrl=' + imgUrl);
  537. } else {
  538. log('No match on imgPattern');
  539. }
  540. var a = e[i].querySelector('a[href][title]'); // sub-element
  541. if (a && a !== null) {
  542. log('Album title: ' + a.title);
  543. log('Album url: ' + a.getAttribute('href'));
  544. albums.html += '<div><a href="//www.flickr.com' + a.getAttribute('href') + '"><img src="' + imgUrl + '" class="asquare" alt="" /><div style="margin:0 0 .8em 0">' + a.title + '</div></a></div>';
  545. } else {
  546. log('a element not found?');
  547. }
  548. }
  549. } else if (e) {
  550. if (doc.body.querySelector('h3')) {
  551. albums.html = '<div style="margin:0 0 .8em 0">'+doc.body.querySelector('h3').textContent+'</div>';
  552. }
  553. } else {
  554. log('(e UNdefined) Problem reading albums or no albums??? : ' + _reqAlbumlist.responseText );
  555. }
  556. if (document.getElementById('albumTeaser')) {
  557. document.getElementById('albumTeaser').innerHTML = '<div style="margin:0 0 .8em 0">Albums</div>' + albums.html + '<div><i><a href="/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/">' + (albums.count > 10 ? 'More albums...' : (albums.count === 0 ? 'No albums found...' : '')) + '</a></i></div>';
  558. } else {
  559. log('albumTeaser NOT FOUND!?!');
  560. }
  561. } else {
  562. // wait for the call to complete
  563. }
  564. };
  565.  
  566. if (fixr.context.photographerId === albums.ownerId && fixr.context.photographerId !== '') {
  567. log('Using CACHED albumlist!...');
  568. document.getElementById('albumTeaser').innerHTML = '<div style="margin:0 0 .8em 0">Albums</div>' + albums.html + '<div><i><a href="/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/">' + (albums.count > 10 ? 'More albums...' : (albums.count === 0 ? 'No albums found...' : '')) + '</a></i></div>';
  569. } else if (fixr.context.photographerId) {
  570. var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums';
  571. _reqAlbumlist.open('GET', url, true);
  572. _reqAlbumlist.send(null);
  573. } else {
  574. log('Attribution user (photographer) not found');
  575. }
  576. } else {
  577. log('understøtter ikke XMLHttpRequest');
  578. }
  579. }
  580. function albumTeaser() {
  581. if (fixr.context.pageType !== 'PHOTOSTREAM') {
  582. return; // exit if not photostream
  583. }
  584. log('albumTeaser() running');
  585. var dpc = document.querySelector('div.photolist-container');
  586. if (!dpc) {
  587. return;
  588. }
  589. // to-do: check om personlig photostream?
  590. // to-do: check padding-right er mindst 130px?
  591. log('AlbumTeaser found div.photolist-container');
  592. if (!document.getElementById('albumTeaser')) {
  593. dpc.style.position = "relative";
  594. dpc.insertAdjacentHTML('afterbegin', '<div id="albumTeaser" style="border:none;margin:0;padding:0;position:absolute;top:0;right:10px;width:100px"></div>');
  595. }
  596. if (document.getElementById('albumTeaser')) {
  597. getAlbumlist(); // også check på fixr.context.photographerId ?
  598. }
  599. }
  600. var _timerAlbumTeaserDelayed;
  601. function albumTeaserDelayed() {
  602. if (fixr.context.pageType !== 'PHOTOSTREAM') {
  603. return; // exit if not photostream
  604. }
  605. log('albumTeaserDelayed() running...');
  606. clearTimeout(_timerAlbumTeaserDelayed);
  607. _timerAlbumTeaserDelayed = setTimeout(albumTeaser, 1500);
  608. }
  609.  
  610. function exploreCalendar() {
  611. if (fixr.context.pageType !== 'EXPLORE') {
  612. return; // exit if not explore/interestingness
  613. }
  614. log('exploreCalendar() running');
  615. var dtr = document.querySelector('div.title-row');
  616. if (!dtr) {
  617. return;
  618. }
  619. log('exploreCalendar found div.photo-list-view');
  620. if (!document.getElementById('exploreCalendar')) {
  621. dtr.style.position = "relative";
  622. var exploreMonth = fixr.clock.explore().substring(0,7).replace('-','/');
  623. dtr.insertAdjacentHTML('afterbegin', '<div id="exploreCalendar" style="border:none;margin:0;padding:0;position:absolute;top:38px;right:-120px;width:100px"><div style="margin:0 0 .8em 0">Explore more...</div><a title="Explore Calendar" href="https://www.flickr.com/explore/interesting/' + exploreMonth + '/"><img src="https://c2.staticflickr.com/2/1701/24895062996_78719dec15_o.jpg" class="asquare" style="width:75px;height:59px" alt="" /><div style="margin:0 0 .8em 0">Explore Calendar</div></a><a title="If you are an adventurer and want to explore something different than everybody else..." href="https://www.flickr.com/search/?text=&view_all=1&media=photos&content_type=1&dimension_search_mode=min&height=640&width=640&safe_search=2&sort=date-posted-desc&min_upload_date='+(Math.floor(Date.now()/1000)-7200)+'"><img src="https://c2.staticflickr.com/2/1617/25534100345_b4a3fe78f1_o.jpg" class="asquare" style="width:75px;height:59px" alt="" /><div style="margin:0 0 .8em 0">Fresh uploads</div></a></div>');
  624. log('San Francisco UTC-8: ' + fixr.clock.pst());
  625. log('Explore Beat (Yesterday, UTC-4): ' + fixr.clock.explore());
  626. if (document.querySelector('div.title-row h3')) {
  627. document.querySelector('div.title-row h3').title = fixr.clock.explore() + ' - ' + fixr.clock.pst();
  628. }
  629. }
  630. }
  631. var _timerExploreCalendarDelayed;
  632. function exploreCalendarDelayed() {
  633. if (fixr.context.pageType !== 'EXPLORE') {
  634. return; // exit if not explore/interestingness
  635. }
  636. log('albumTeaserDelayed() running...');
  637. clearTimeout(_timerExploreCalendarDelayed);
  638. _timerExploreCalendarDelayed = setTimeout(exploreCalendar, 1500);
  639. }
  640.  
  641. function ctrlClick(e) {
  642. var elem, evt = e ? e : event;
  643. if (evt.srcElement) elem = evt.srcElement;
  644. else if (evt.target) elem = evt.target;
  645. if (evt.ctrlKey) {
  646. log('Ctrl clicked. Further scripted click-event handling canceled. Allow the default ctrl-click handling in my browser.');
  647. evt.stopPropagation();
  648. }
  649. }
  650. function ctrlClicking() {
  651. // if (navigator.userAgent.search(/gecko\/20/i)>-1) { // Firefox/gecko-only ctrl click tab fix
  652. var plv = document.querySelectorAll('div.photo-list-view');
  653. for (var i = 0; i < plv.length; i++) {
  654. log('ctrlClicking(): plv['+i+'] found!');
  655. // Allow me to open tabs in background by ctrl-click in Firefox:
  656. plv[i].parentNode.addEventListener('click', ctrlClick, true);
  657. }
  658. // }
  659. }
  660. var _timerCtrlClicking;
  661. function ctrlClickingDelayed() {
  662. log('ctrlClickingDelayed() running...');
  663. clearTimeout(_timerCtrlClicking);
  664. _timerCtrlClicking = setTimeout(ctrlClicking, 1500);
  665. }
  666.  
  667. var scaler = {
  668. photoId: '',
  669. photoOrientation: '',
  670. mf: null, // document.querySelector('img.main-photo') for (re-)re-scale
  671. lrf: null, // document.querySelector('img.low-res-photo') for (re-)re-scale
  672. maxSizeUrl: '',
  673. orgUrl: '',
  674. hasOriginal: false,
  675. scaleToWidth: 0,
  676. scaleToHeight: 0,
  677. postAction: function() {
  678. log('scaler.postAction'); // dummy-function to be replaced
  679. },
  680. run: function () {
  681. if (fixr.context.pageType !== 'PHOTOPAGE' && fixr.context.pageType !== 'PHOTOPAGE LIGHTBOX') {
  682. return; // exit if not photopage or lightbox
  683. }
  684. if (fixr.context.pageSubType !== 'PHOTO') {
  685. log('Exiting scaler because fixr.context.pageSubType='+fixr.context.pageSubType);
  686. return; // exit if subtype VR or VIDEO
  687. }
  688. log('scaler.run() running...');
  689. // var that = this;
  690. var unscale = function () {
  691. log('Unscale button clicked!...');
  692. // sizes (and position?) from div.photo-notes-scrappy-view
  693. var dims = document.querySelector('div.photo-notes-scrappy-view');
  694. scaler.mf.width = parseInt(dims.style.width,10);
  695. scaler.mf.height = parseInt(dims.style.height,10);
  696. // unscale/rest, and...
  697. var trash = document.querySelector('div.unscaleBtn');
  698. if (trash && trash.parentNode) {
  699. trash.removeEventListener('click',unscale);
  700. trash.parentNode.removeChild(trash);
  701. }
  702. };
  703. var addUnscaleBtn = function() {
  704. if (fixr.context.pageType !== 'PHOTOPAGE') {
  705. return; // exit if not photopage
  706. }
  707. /*
  708. if (!notes.photo.allowNotes) {
  709. log('Notes not supported on this photo');
  710. return;
  711. }
  712. */
  713. if (!document.querySelector('.show-add-tags')) {
  714. log('Adding notes (and tagging) apparently not allowed/possible'); // photographer doesn't allow, user not logged in, or...?
  715. // return;
  716. }
  717. log('scaler.addUnscaleBtn() running');
  718. var panel = document.querySelector('div.photo-well-media-scrappy-view');
  719. var notesview = document.querySelector('div.photo-notes-scrappy-view');
  720. if (panel && !panel.querySelector('div.unscaleBtn')) {
  721. log('scaler.addUnscaleBtn: adding option to div.height-controller');
  722. panel.insertAdjacentHTML('afterbegin', '<div class="unscaleBtn" style="position:absolute;right:20px;top:15px;font-size:16px;margin-right:16px;color:#FFF;z-index:3000"><img id="unscaleBtnId" src="https://farm9.staticflickr.com/8566/28150041264_a8b591c2a6_o.png" alt="Un-scale" title="This photo has been up-scaled by Flickr Fixr. Click here to be sure image-size is aligned with notes area" /></div>');
  723. log ('scaler.addUnscaleBtn: adding click event listner on div.unscaleBtn');
  724. panel.querySelector('div.unscaleBtn').addEventListener('click',unscale, false);
  725. } else {
  726. log('scaler.addUnscaleBtn: div.height-controller not found OR unscaleBtn already defined');
  727. }
  728. var unscaleBtnElem = document.getElementById('unscaleBtnId');
  729. if (unscaleBtnElem && parseInt(notesview.style.width,10)) {
  730. if (scaler.mf.width === parseInt(notesview.style.width, 10)) { // Green icon
  731. unscaleBtnElem.title = "This photo has been up-scaled by Flickr Fixr. It appears Flickr was able to align the notes-area with scaled photo. You should be able to view and create notes correctly scaled and aligned on the upscaled photo.";
  732. unscaleBtnElem.src = 'https://farm9.staticflickr.com/8879/28767704565_17560d791f_o.png';
  733. } else { // Orange icon/button
  734. unscaleBtnElem.title = "This photo has been up-scaled by Flickr Fixr. It appears the notes-area is UNALIGNED with the upscaled image. Please click here to align image-size to the notes-area before studying or creating notes on this image.";
  735. unscaleBtnElem.src = 'https://farm9.staticflickr.com/8687/28690535161_19b3a34578_o.png';
  736. }
  737. }
  738. };
  739. var scale = function () { // Do the actual scaling
  740. if (fixr.context.pageType !== 'PHOTOPAGE' && fixr.context.pageType !== 'PHOTOPAGE LIGHTBOX') {
  741. return;
  742. } // exit if not photopage or lightbox
  743. log('scaler.scale() running... (scale to:' + scaler.scaleToWidth + 'x' + scaler.scaleToHeight + ')');
  744. scaler.mf = document.querySelector('img.main-photo'); // for en sikkerheds skyld
  745. scaler.lrf = document.querySelector('img.low-res-photo'); // for en sikkerheds skyld
  746. if (scaler.mf && scaler.mf !== null && scaler.lrf && scaler.lrf !== null && scaler.scaleToWidth > 0 && scaler.scaleToHeight > 0) {
  747. log('[scaler] do scaling WORK. Height from ' + scaler.mf.height + ' to ' + scaler.scaleToHeight);
  748. scaler.mf.height = scaler.scaleToHeight;
  749. log('[scaler] do scaling WORK. Width from ' + scaler.mf.width + ' to ' + scaler.scaleToWidth);
  750. scaler.mf.width = scaler.scaleToWidth;
  751. scaler.lrf.height = scaler.mf.height;
  752. scaler.lrf.width = scaler.mf.width;
  753. }
  754. addUnscaleBtn();
  755. scaler.postAction('notes on scaled photo');
  756. };
  757. var replace = function () { // and (re-)scale?
  758. if (fixr.context.pageType !== 'PHOTOPAGE' && fixr.context.pageType !== 'PHOTOPAGE LIGHTBOX') {
  759. return; // exit if not photopage or lightbox
  760. }
  761. log('[scaler] scaler.run.replace() running...');
  762. scaler.mf = document.querySelector('img.main-photo'); // for en sikkerheds skyld
  763. if (scaler.mf && scaler.mf !== null && scaler.maxSizeUrl !== '') {
  764. if (scaler.mf.height>=640 || scaler.mf.width>=640) { // dirty hack to work-around a bug
  765. scaler.mf.src = scaler.maxSizeUrl; // Replace! only if original (maxSizeUrl should be orgUrl)
  766. } else {
  767. log('[scaler] Second thoughts. Do not replace this photo with original because unlikely needed here (bug work-around for small screens).');
  768. }
  769. scale();
  770. }
  771. };
  772. var getSizes = function () {
  773. log('[scaler] scaler.run.getSizes() running...');
  774. var _reqAllSizes = null;
  775. if (window.XMLHttpRequest) {
  776. _reqAllSizes = new XMLHttpRequest();
  777. if (typeof _reqAllSizes.overrideMimeType !== 'undefined') {
  778. _reqAllSizes.overrideMimeType('text/html');
  779. }
  780. _reqAllSizes.onreadystatechange = function () {
  781. if (_reqAllSizes.readyState === 4 && _reqAllSizes.status === 200) {
  782. log('[scaler] _reqAllSizes returned status=' + _reqAllSizes.status); // + ', \ntext:\n' + _reqAllSizes.responseText);
  783. var doc = document.implementation.createHTMLDocument("sizeDoc");
  784. doc.documentElement.innerHTML = _reqAllSizes.responseText;
  785.  
  786. var sizelist = doc.body.querySelectorAll('ol.sizes-list li ol li');
  787. var largest = null;
  788. var largesttext = '';
  789. while(!largest && sizelist.length>0) {
  790. if (sizelist[sizelist.length-1].textContent.replace(/\s+/g,'')==='') {
  791. sizelist.pop(); // remove last
  792. } else {
  793. log('[scaler] Found LARGEST size: '+sizelist[sizelist.length-1].textContent.replace(/\s+/g,''));
  794. largest = sizelist[sizelist.length-1];
  795. largesttext = largest.textContent.replace(/\s+/g,'');
  796. }
  797. }
  798. if (largest.querySelector('a')) {
  799. // list has link to _PAGE_ for showing largest image, thus it cannot be the original we already see ON the page!
  800. log ('[scaler] Sizes-page/o has link to _PAGE_ for showing largest image, thus it cannot be the largest/original we already see ON the page!');
  801. scaler.orgUrl = '';
  802. scaler.maxSizeUrl = '';
  803. scaler.hasOriginal = false;
  804. } else if (doc.body.querySelector('div#allsizes-photo>img')) {
  805. scaler.orgUrl = doc.body.querySelector('div#allsizes-photo>img').src;
  806. scaler.hasOriginal = true;
  807. scaler.maxSizeUrl = doc.body.querySelector('div#allsizes-photo>img').src;
  808. log('[scaler] Largest/original image: ' + scaler.maxSizeUrl);
  809. } else {
  810. log('[scaler] UNEXPECTED situation. Assuming NO original available');
  811. scaler.orgUrl = '';
  812. scaler.maxSizeUrl = '';
  813. scaler.hasOriginal = false;
  814. }
  815. var r = /\((\d+)x(\d+)\)$/;
  816. var res = largesttext.match(r);
  817. if (res !== null) {
  818. if (scaler.photoOrientation === 'h' && parseInt(res[1],10)<parseInt(res[2],10)) {
  819. log('[scaler] Photo has been rotated from vertical to horizontal - Should NOT use the original here!');
  820. scaler.orgUrl = '';
  821. scaler.maxSizeUrl = '';
  822. scaler.hasOriginal = false;
  823. } else if (scaler.photoOrientation === 'v' && parseInt(res[1],10)>parseInt(res[2],10)) {
  824. log('[scaler] Photo has been rotated from horizontal to vertical - Should NOT use the original here!');
  825. scaler.orgUrl = '';
  826. scaler.maxSizeUrl = '';
  827. scaler.hasOriginal = false;
  828. }
  829. } else {
  830. log('[scaler] No match???');
  831. }
  832. if (scaler.hasOriginal) {
  833. log('[scaler] Scale and replace using Original found from XMLHttpRequest');
  834. // do some caching here?...
  835. replace();
  836. }
  837. } else {
  838. // wait for the call to complete
  839. }
  840. };
  841. var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/' + fixr.context.photoId + '/sizes/o';
  842. _reqAllSizes.open('GET', url, true);
  843. _reqAllSizes.send(null);
  844. } else {
  845. log('[scaler] understøtter ikke XMLHttpRequest');
  846. }
  847. };
  848. if (scaler.photoId === '') {
  849. scaler.photoId = fixr.context.photoId;
  850. } else if (scaler.photoId !== fixr.context.photoId) {
  851. scaler.photoId = fixr.context.photoId;
  852. scaler.photoOrientation = '';
  853. scaler.mf = null;
  854. scaler.lrf = null;
  855. scaler.maxSizeUrl = '';
  856. scaler.orgUrl = '';
  857. scaler.hasOriginal = false;
  858. scaler.scaleToWidth = 0;
  859. scaler.scaleToHeight = 0;
  860. }
  861. var roomHeight = 0;
  862. var roomWidth = 0;
  863. var roomPaddingHeight = 0;
  864. var roomPaddingWidth = 0;
  865.  
  866. // Fortsæt kun hvis PhotoId!!!?
  867.  
  868. var dpev = document.querySelector('div.photo-engagement-view');
  869. var pwv = document.querySelector('div.photo-well-view');
  870. if (pwv) {
  871. log('[scaler] height-controller: height=' + pwv.clientHeight + ' (padding=70?), width=' + pwv.clientWidth + ' (padding=80?).'); // hc.style.padding: 20px 40px 50px
  872. if (roomHeight === 0) {
  873. roomHeight = pwv.clientHeight;
  874. }
  875. if (roomWidth === 0) {
  876. roomWidth = pwv.clientWidth;
  877. }
  878. roomPaddingHeight += (parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-top'), 10) + parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-bottom'), 10));
  879. roomPaddingWidth += (parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-left'), 10) + parseInt(window.getComputedStyle(pwv, null).getPropertyValue('padding-right'), 10));
  880. }
  881. var hc = document.querySelector('div.height-controller');
  882. if (hc) {
  883. log('[scaler] height-controller: height=' + hc.clientHeight + ' (padding=70?), width=' + hc.clientWidth + ' (padding=80?).'); // hc.style.padding: 20px 40px 50px
  884. if (roomHeight === 0) {
  885. roomHeight = hc.clientHeight;
  886. }
  887. if (roomWidth === 0) {
  888. roomWidth = hc.clientWidth;
  889. }
  890. roomPaddingHeight += (parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-top'), 10) + parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-bottom'), 10));
  891. roomPaddingWidth += (parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-left'), 10) + parseInt(window.getComputedStyle(hc, null).getPropertyValue('padding-right'), 10));
  892. }
  893. var pwmsv = document.querySelector('div.photo-well-media-scrappy-view');
  894. if (pwmsv) {
  895. log('[scaler] div.photo-well-media-scrappy-view: height=' + pwmsv.clientHeight + ' (padding=70?), width=' + pwmsv.clientWidth + ' (padding=80?).'); // pwmsv.style.padding: 20px 40px 50px
  896. if (roomHeight === 0) {
  897. roomHeight = pwmsv.clientHeight;
  898. }
  899. if (roomWidth === 0) {
  900. roomWidth = pwmsv.clientWidth;
  901. }
  902. roomPaddingHeight += (parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-top'), 10) + parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-bottom'), 10));
  903. roomPaddingWidth += (parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-left'), 10) + parseInt(window.getComputedStyle(pwmsv, null).getPropertyValue('padding-right'), 10));
  904. }
  905. scaler.mf = document.querySelector('img.main-photo');
  906. scaler.lrf = document.querySelector('img.low-res-photo');
  907. // var zl = document.querySelector('img.zoom-large'); // currently not used
  908. // var zs = document.querySelector('img.zoom-small'); // currently not used
  909. if (scaler.mf) {
  910. log('[scaler] main-photo: h=' + scaler.mf.height + ', w=' + scaler.mf.width + '. - Room: (h=' + (roomHeight - roomPaddingHeight) + ',w=' + (roomWidth - roomPaddingWidth) + ')');
  911. if (scaler.mf.width>scaler.mf.height) {
  912. scaler.photoOrientation = 'h'; // horisontal
  913. } else {
  914. scaler.photoOrientation = 'v'; // vertical
  915. }
  916. if (roomPaddingWidth === 0) { // hack
  917. roomPaddingWidth = 120;
  918. log('[scaler] roomPaddingWidth=120 hack used');
  919. }
  920. if (((roomHeight - roomPaddingHeight) > scaler.mf.height + 5) && ((roomWidth - roomPaddingWidth) > scaler.mf.width + 5)) {
  921. log('[scaler] ALLRIGHT - WE ARE READY FOR SCALING!...');
  922. if (((roomHeight - roomPaddingHeight) / scaler.mf.height) < ((roomWidth - roomPaddingWidth) / scaler.mf.width)) {
  923. scaler.scaleToWidth = Math.floor(scaler.mf.width * ((roomHeight - roomPaddingHeight) / scaler.mf.height));
  924. scaler.scaleToHeight = roomHeight - roomPaddingHeight;
  925. } else {
  926. scaler.scaleToHeight = Math.floor(scaler.mf.height * ((roomWidth - roomPaddingWidth) / scaler.mf.width));
  927. scaler.scaleToWidth = roomWidth - roomPaddingWidth;
  928. }
  929. log('[scaler] now calling scale()... [' + scaler.scaleToWidth + ', ' + scaler.scaleToWidth + ']');
  930. scale();
  931. log('[scaler] ...AND CONTINUE LOOKING FOR ORIGINAL...');
  932. if (dpev && scaler.photoOrientation==='h' && document.querySelector('ul.sizes')) { // if (document.querySelector('ul.sizes')) -> PHOTOPAGE in normal mode (if vertical (bigger) risk for rotated, which are better handled by getSizes())
  933. var org = document.querySelector('ul.sizes li.Original a.download-image-size');
  934. if (org) { // quick access når vi bladrer?
  935. scaler.hasOriginal = true; // ??? kun hvis original
  936. scaler.maxSizeUrl = (org.href).replace(/^https\:/i, '').replace(/_d\./i, '.');
  937. // ... do some scaling here?...
  938. replace();
  939. } else {
  940. // vi kan finde original "inline"
  941. var target = document.querySelector('div.photo-engagement-view');
  942. // if(!target) return; ???
  943. if (target) {
  944. var observer = new MutationObserver(function (mutations) {
  945. mutations.forEach(function (mutation) {
  946. log('[scaler] MO size: ' + mutation.type); // might check for specific "mutations"?
  947. });
  948. var org = document.querySelector('ul.sizes li.Original a.download-image-size');
  949. if (org) {
  950. scaler.hasOriginal = true; // ??? kun hvis original
  951. scaler.maxSizeUrl = (org.href).replace(/^https\:/i, '').replace(/_d\./i, '.');
  952. log('[scaler] Original photo found, now replacing');
  953. // ... do some scaling here?...
  954. replace();
  955. } else {
  956. log('[scaler] Original photo not available for download on this photographer. Re-scale just in case...');
  957. scale(); // ???
  958. }
  959. observer.disconnect();
  960. });
  961. // configuration of the observer:
  962. var config = {attributes: false, childList: true, subtree: false, characterData: false};
  963. observer.observe(target, config);
  964. }
  965. }
  966. } else { // PHOTOPAGE (likely) in LIGHTBOX mode
  967. getSizes(); // resize (& replace) from/when size-list
  968. }
  969. } else {
  970. log('[scaler] Scaling NOT relevant');
  971. }
  972. scaler.postAction('notes on unscaled photo'); // look for notes (not (yet?) scaled)
  973. }
  974. }
  975. };
  976.  
  977. function insertStyle() {
  978. if (!document.getElementById('fixrStyle')) {
  979. var style = document.createElement('style');
  980. style.type = 'text/css';
  981. style.id = 'fixrStyle';
  982. style.innerHTML = 'ul.tags-list>li.tag>a.fixrTag,ul.tags-list>li.autotag>a.fixrTag{display:none;} ul.tags-list>li.tag:hover>a.fixrTag,ul.tags-list>li.autotag:hover>a.fixrTag{display:inline;} ' +
  983. '.album-map-icon{background:url("https://c2.staticflickr.com/6/5654/23426346485_334afa6e8f_o_d.png") no-repeat;height:21px;width:24px;top:6px;left:3px} .album-comments-icon{background:url("https://s.yimg.com/uy/build/images/icons-1x-s2fb29ad15b.png") -32px -460px no-repeat;height:21px;width:24px;top:6px;left:3px} ' +
  984. '.unscaleBtn:hover{cursor:pointer} ' +
  985. 'img.asquare {width:75px;height:75px;border:none;margin:0;padding:0;transition:all 0.3s ease} a:hover>img.asquare{transform:scale(1.3)} ' +
  986. '.signup-footer, .signup-footer-view{display:none} ' +
  987. '#topPaginationContainer{width:250px;height:40px;margin:0 auto;position:absolute;top:0;left:0;right:0;border:none} #topPagination{width:720px;margin:0;position:absolute;top:0;left:-235px;text-align:center;z-index:10;display:none;border:none;padding:10px 0 10px 0;overflow:hidden} .album-toolbar-content #topPagination{top:-16px} .group-pool-subheader-view #topPagination{top:-7px} .title-row #topPagination{width:830px;left:-290px;top:-12px} #topPaginationContainer:hover #topPagination{display:block} ';
  988. document.getElementsByTagName('head')[0].appendChild(style);
  989. log('fixrStyle has been ADDED');
  990. } else {
  991. log('fixrStyle was already present');
  992. }
  993. }
  994.  
  995. function topPagination() {
  996. log('topPagination()');
  997. var bottomPagination = document.querySelector('.pagination-view');
  998. if (!bottomPagination) {
  999. bottomPagination = document.querySelector('.explore-pagination');
  1000. }
  1001. if (bottomPagination && !document.getElementById('topPagination')) {
  1002. if (bottomPagination.childElementCount>0) {
  1003. var topPagination = bottomPagination.cloneNode(true);
  1004. topPagination.id = 'topPagination';
  1005. var topPaginationContainer = document.createElement('div');
  1006. topPaginationContainer.id = 'topPaginationContainer';
  1007. topPaginationContainer.appendChild(topPagination);
  1008. var topbar = document.querySelector('.fluid-magic-tools-view');
  1009. if (!topbar) topbar = document.querySelector('.album-toolbar-content');
  1010. if (!topbar) topbar = document.querySelector('.group-pool-subheader-view');
  1011. if (!topbar) topbar = document.querySelector('.title-row');
  1012. if (topbar) {
  1013. log('topPagination: root found, inserting container');
  1014. topbar.appendChild(topPaginationContainer);
  1015. }
  1016. }
  1017. }
  1018. }
  1019. function albumExtras() { // links to album's map and comments
  1020. if (fixr.context.pageType !== 'ALBUM') {
  1021. return; // exit if not albumpage
  1022. }
  1023. if (fixr.context.albumId) {
  1024. log('albumsExtra() med album=' + fixr.context.albumId);
  1025. } else {
  1026. log('Exit albumsExtra(). Mangler albumId');
  1027. return;
  1028. }
  1029. var elist = document.querySelector('div.album-engagement-view');
  1030. if (elist && !document.getElementById('albumCommentCount')) {
  1031. // map-link:
  1032. var mapdiv = document.createElement('div');
  1033. mapdiv.className = 'create-book-container';
  1034. mapdiv.title = 'Album on map';
  1035. mapdiv.style.textAlign = 'center';
  1036. mapdiv.innerHTML = '<a href="/photos/' + fixr.context.photographerAlias + '/albums/' + fixr.context.albumId + '/map/" style="font-size:14px;color:#FFF;"><span title="Album on map" class="album-map-icon"></span></a>';
  1037. elist.appendChild(mapdiv);
  1038. // comments-link:
  1039. var comurl = '/photos/' + fixr.context.photographerAlias + '/albums/' + fixr.context.albumId + '/comments/';
  1040. var cmdiv = document.createElement('div');
  1041. cmdiv.className = 'create-book-container';
  1042. cmdiv.title = 'Comments';
  1043. cmdiv.style.textAlign = 'center';
  1044. cmdiv.innerHTML = '<a href="' + comurl + '" style="font-size:14px;color:#FFF;"><span title="Album comments" class="album-comments-icon" id="albumCommentCount"></span></a>';
  1045. elist.appendChild(cmdiv);
  1046. updateAlbumCommentCount();
  1047. }
  1048. }
  1049. function updateTags() {
  1050. if (fixr.context.pageType !== 'PHOTOPAGE') {
  1051. return; // exit if not photopage
  1052. }
  1053. if (fixr.context.photographerAlias==='') {
  1054. fixr.initPhotoId();
  1055. }
  1056. if (fixr.context.photographerId==='') {
  1057. fixr.initPhotographerId();
  1058. }
  1059. if (fixr.context.photographerName==='') {
  1060. fixr.initPhotographerName();
  1061. }
  1062. log('updateTags() med photographerAlias='+fixr.context.photographerAlias+', photographerId='+fixr.context.photographerId+' og photographerName='+fixr.context.photographerName);
  1063. if (document.querySelector('ul.tags-list')) {
  1064. var tags = document.querySelectorAll('ul.tags-list>li');
  1065. if (tags && tags !== null && tags.length > 0) {
  1066. for (var i = 0; i < tags.length; i++) {
  1067. var atag = tags[i].querySelector('a[title][href*="/photos/tags/"],a[title][href*="?tags="],a[title][href*="?q="]');
  1068. if (atag) {
  1069. var realtag = (atag.href.match(/((\/tags\/)|(\?tags\=)|(\?q\=))([\S]+)$/i))[5];
  1070. if (!(tags[i].querySelector('a.fixrTag'))) {
  1071. var icon = fixr.context.photographerIcon.match(/^([^_]+)(_\w)?\.[jpgntif]{3,4}$/)[1] + String(fixr.context.photographerIcon.match(/^[^_]+(_\w)?(\.[jpgntif]{3,4})$/)[2]); // do we know for sure it is square?
  1072. tags[i].insertAdjacentHTML('afterbegin', '<a class="fixrTag" href="/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/tags/' + realtag + '/" title="' + atag.title + ' by ' + fixr.context.photographerName + '"><img src="' + icon + '" style="width:1em;height:1em;margin:0;padding:0;position:relative;top:3px" alt="*" /></a>');
  1073. }
  1074. }
  1075. }
  1076. } else {
  1077. log('no tags defined (yet?)');
  1078. }
  1079. } else {
  1080. log('taglist container not found');
  1081. }
  1082. }
  1083. function updateTagsDelayed() {
  1084. log('updateTagsDelayed() running... with pageType=' + fixr.context.pageType);
  1085. if (fixr.context.pageType === 'PHOTOPAGE') {
  1086. setTimeout(updateTags, 2500);
  1087. setTimeout(updateTags, 4500); // Twice. Those tags are sometimes a bit slow emerging
  1088. setTimeout(updateTags, 8500); // Triple. Those tags are sometimes very slow emerging
  1089. }
  1090. }
  1091.  
  1092. function shootingSpaceballs() {
  1093. // Enable image context-menu on "View sizes" page by removing overlaying div.
  1094. // This is *not* meant as a tool for unauthorized copying and distribution of other peoples photos.
  1095. // Please respect image ownership and copyrights!
  1096. if (fixr.context.pageType === 'SIZES') {
  1097. var trash = document.querySelector('div.spaceball');
  1098. while (trash && trash.parentNode) {
  1099. trash.parentNode.removeChild(trash);
  1100. trash = document.querySelector('div.spaceball');
  1101. }
  1102. }
  1103. }
  1104.  
  1105. function runEarly() {
  1106. localStorage.setItem('filterFeedEvents', 'people'); // Try to make People feed default.
  1107. }
  1108.  
  1109. inspect = function(obj) { // for some debugging
  1110. let output='';
  1111. Object.keys(obj).forEach(function(key, idx) {
  1112. output+=key+': ' + typeof obj[key] + ((typeof obj[key] === 'string' || typeof obj[key] === 'boolean' || typeof obj[key] === 'number') ? ' = ' + obj[key] : '') + '\n';
  1113. });
  1114. alert(output);
  1115. };
  1116.  
  1117.  
  1118. if (window.location.href.indexOf('flickr.com\/services\/api\/explore\/')>-1) {
  1119. // We are on Flickr API Explorer (WAS used for note handling before Flickr returned native note-support) and outside "normal" flickr page flow. fixr wont do here...
  1120. } else {
  1121. // FIXR fixr.init([runNow],[onPageHandlers], [onResizeHandlers], [onFocusHandlers])
  1122. fixr.init([/* runEarly */], [scaler.run, insertStyle, ctrlClicking, albumExtras, topPagination, shootingSpaceballs, ctrlClickingDelayed, exploreCalendarDelayed, albumTeaserDelayed, updateMapLinkDelayed, updateTagsDelayed], [scaler.run], []);
  1123. }