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-23 提交的版本,查看 最新版本

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