// ==UserScript==
// @name Stig's Flickr Fixr
// @namespace dk.rockland.userscript.flickr.fixr
// @description Display and update photo-notes, Show photographer's albums on photostream-pages, Increase display-size and quality of "old" photos, Photographer's other photos by tag-links, Links to album-map and album-comments, Actually show a geotagged photo on the associated map, Top-pager - And more to come?...
// @author Stig Nygaard, http://www.rockland.dk, https://www.flickr.com/photos/stignygaard/
// @homepageURL http://www.rockland.dk/userscript/flickr/fixr/
// @supportURL http://www.rockland.dk/userscript/flickr/fixr/
// @icon http://www.rockland.dk/img/fixr32.png
// @icon64 http://www.rockland.dk/img/fixr64.png
// @include https://www.flickr.com/*
// @include https://flickr.com/*
// @match https://*.flickr.com/*
// @version 2016.03.24.6
// @grant none
// @run-at document-start
// @downloadURL none
// ==/UserScript==
// CHANGELOG - The most important updates/versions:
var changelog = [
{version: '2016.03.24.*', description: 'Various optimizations to make notes-stuff more reliable and smooth.'},
{version: '2016.03.21.1', description: 'Trying to improve the robustness of the tag-links feature.'},
{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?).'},
{version: '2016.02.20.2', description: 'Delete-button now available on ALL notes on YOUR OWN photos. Also a Fixr-button added to note-editor to insert link/hint about using Stigs Flickr Fixr to display notes.'},
{version: '2016.02.14.1', description: 'Fixing a couple of issues related to scale/replace photos (Including avoid using original if photo has been rotated after upload).'},
{version: '2016.02.09.0', description: 'New feature: Link to Explore Calendar added to Explore page (To the right for now, but might move it to top-menu later?).'},
{version: '2016.02.06.2', description: 'New feature: Top-pager! Hover the mouse in the center just above photostreams to show a pagination-bar.'},
{version: '2016.02.05.1', description: 'Adding a little "bling" to the album-column.'},
{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.'},
{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)'},
{version: '2015.12.05.2', description: 'Photo-notes support now includes displaying formatting and active links.'},
{version: '2015.12.03.2', description: 'New feature: Basic "beta" support for the good old photo-notes (read-only, no formatting/links).'},
{version: '2015.11.28.1', description: 'New feature: Album-headers are now updated with links to album-map and album-comments.'},
{version: '2015.08.26.4', description: 'Initial release version. Photo scale/replace, album column and tag-feature.'}
];
var DEBUG = false;
function log(s) {
if (DEBUG && window.console) {
window.console.log(s);
}
}
if (DEBUG) {
if ('loading' === document.readyState) {
log("This userscript is running at document-start time.");
} else {
log("This userscript is running with document.readyState: " + document.readyState);
}
window.addEventListener('DOMContentLoaded', function(){log('(onDOMContentLoaded)');}, false);
window.addEventListener('focus', function(){log('(onfocus)');}, false);
window.addEventListener('load', function(){log('(onload)');}, false);
window.addEventListener('pageshow', function(){log('(onpageshow)');}, false);
window.addEventListener('resize', function(){log('(onresize)');}, false);
window.addEventListener('hashchange', function(){log('(onhashchange)');}, false);
window.addEventListener('blur', function(){log('(onblur)');}, false);
}
var allowUpdateNotesViaAPIExplorer = true; // Allow support for Create, Edit and Delete photo-notes using Flickr's API Explorer
// FIXR page-tracker
var fixr = fixr || {
context: {
pageType: '',
pageSubType: '',
userId: '',
photographerId: '', // value might be delayed (If uninitialized, try call initPhotographerId())
photographerIcon: '',
photographerAlias: '', // (pathalias) bonus-info sometimes initialized (from url) when initializing photoId or albumId
photographerName: '',
photoId: '',
albumId: '',
groupId: '',
galleryId: ''
},
content: null,
pageactionsCount: 0,
timerResizeActionDelayed: 0,
onPageHandlers: [],
onResizeHandlers: [],
onFocusHandlers: [],
runningDirty: function() { // In-development and extra experiments enabled?
return (DEBUG && (fixr.context.userId==='10259776@N00'));
},
timer: {
_test: 0 // TODO
},
clock: {
_d: null,
_pst: null, // Pacific Standard Time
_explore: null,
tick: function () {
this._d = new Date();
this._pst = new Date(this._d);
this._pst.setHours(this._d.getHours() - 8); // PST = UTC-08
this._explore = new Date(this._d);
this._explore.setHours(this._d.getHours() - 28); // Explore beat, yesterday UTC-4
// this._y.setDate(this._y.getDate() - 1);
return this._pst;
},
pst: function () { // yyyy-mm-dd tt:mm PST
return (this._pst || this.tick()).toISOString().substring(0,16).replace('T',' ')+' PST';
},
explore: function () { // yyyy-mm-dd tt:mm Explore beat!
if (this._explore==null) {
this.tick();
}
return this._explore.toISOString().substring(0,16).replace('T',' ')+' Explore beat!';
}
},
initUserId: function () {
if (window.auth && window.auth.user && window.auth.user.nsid) {
fixr.context.userId = window.auth.user.nsid;
return true;
}
return false;
},
initPhotographerName: function () {
if (fixr.content.querySelector('a.owner-name')) {
fixr.context.photographerName = fixr.content.querySelector('a.owner-name').textContent;
return true;
}
return false;
},
initPhotographerId: function () { // photographer/attribution id
var elem;
if (document.querySelector('div.photostream-page-view')) {
// photostream
elem = document.querySelector('div.photostream-page-view div.fluid-photostream-coverphoto-view div.avatar.person');
} else if (document.querySelector('div.photo-page-scrappy-view')) {
// photopage
elem = document.querySelector('div.photo-page-scrappy-view div.sub-photo-view div.avatar.person');
} else if (document.querySelector('div.photo-page-lightbox-scrappy-view')) {
// photopage lightbox
elem = document.querySelector('div.photo-page-lightbox-scrappy-view div.photo-well-view div.photo-attribution div.avatar.person');
} else if (document.querySelector('div.album-page-view')) {
// album page
elem = document.querySelector('div.album-page-view div.album-container div.album-header-view div.album-attribution div.avatar.person');
} else {
log('we do not look for photographerId on this page');
return true;
}
// album oversigt
// etc...
// men minus f.eks. favorites oversigt!
if (!elem) {
log('fixr.initPhotographerId() - Attribution elem NOT found - returning false');
return false;
} // re-run a little later???
log('fixr.initPhotographerId() - Attribution elem found');
// (div.avatar.person).style.backgroundImage=url(https://s.yimg.com/pw/images/buddyicon07_r.png#44504567@N00)
// .style.backgroundImage=url(//c4.staticflickr.com/8/7355/buddyicons/10259776@N00_r.jpg?1372021232#10259776@N00)
if (elem.style.backgroundImage) {
log('fixr.initPhotographerId() - elem has style.backgroundImage "' + elem.style.backgroundImage + '", now looking for the attribution id...');
var pattern = /url[^#\?]+(\/\/[^#\?]+\.com\/[^#\?]+\/buddyicon[^\?\#]+)[^#]*#(\d+\@N\d{2})/i;
// var pattern = /\/buddyicons\/(\d+\@N\d{2})\D+/i;
var result = elem.style.backgroundImage.match(pattern);
if (result) {
log('fixr.initPhotographerId() - Attribution pattern match found: ' + result[0]);
log('fixr.initPhotographerId() - the attribution icon is ' + result[1]);
log('fixr.initPhotographerId() - the attribution id is ' + result[2]);
fixr.context.photographerIcon = result[1];
fixr.context.photographerId = result[2];
} else {
log('fixr.initPhotographerId() - attribution pattern match not found');
return false;
}
} else {
log('fixr.initPhotographerId() - elem.style.backgroundImage not found');
return false;
}
log('fixr.initPhotographerId() - returning true...');
return true;
},
initPhotoId: function () { // Photo Id
// *flickr.com/photos/user/PId/*
var pattern = /^\/photos\/([^\/]+)\/([\d]{2,})/i;
var result = window.location.pathname.match(pattern);
if (result) {
log('url match med photoId=' + result[2]);
log('url match med photographerAlias=' + result[1]);
fixr.context.photoId = result[2];
fixr.context.photographerAlias = result[1];
return true;
} else {
log('*** initPhotoId() returnerer false! reg-pattern fandt ikke match i pathname='+window.location.pathname);
}
return false;
},
initAlbumId: function () {
// *flickr.com/photos/user/albums/AId/*
// *flickr.com/photos/user/sets/AId/*
var pattern = /^\/photos\/([^\/]+)\/albums\/([\d]{2,})/i;
var result = window.location.pathname.match(pattern);
if (!result) {
pattern = /^\/photos\/([^\/]+)\/sets\/([\d]{2,})/i;
result = window.location.pathname.match(pattern);
}
if (result) {
log('url match med albumId=' + result[2]);
log('url match med photographerAlias=' + result[1]);
fixr.context.albumId = result[2];
fixr.context.photographerAlias = result[1];
return true;
}
return false;
},
pageActions: function () {
fixr.clock.tick();
if (fixr.content) {
log('fixr.pageActions() has started with fixr.content defined');
} else {
log('fixr.pageActions() was called, but fixr.content NOT defined');
return;
}
fixr.pageactionsCount++;
for (var p in fixr.context) { // reset context on new page
if (fixr.context.hasOwnProperty(p)) {
fixr.context[p] = '';
}
}
if (fixr.content.querySelector('div.photostream-page-view')) {
if (fixr.content.querySelector('div.slideshow-view')) {
fixr.context.pageType = 'PHOTOSTREAM SLIDESHOW';
} else {
fixr.context.pageType = 'PHOTOSTREAM';
}
} else if (fixr.content.querySelector('div.photo-page-scrappy-view')) {
fixr.context.pageType = 'PHOTOPAGE';
if (fixr.content.querySelector('div.vr-overlay-view') && fixr.content.querySelector('div.vr-overlay-view').hasChildNodes()) {
fixr.context.pageSubType = 'VR'; // maybe I can find a better way to detect, not sure how reliable this is?
} else if (fixr.content.querySelector('div.videoplayer')) {
fixr.context.pageSubType='VIDEO';
} else {
fixr.context.pageSubType='PHOTO';
}
} else if (fixr.content.querySelector('div.photo-page-lightbox-scrappy-view')) {
fixr.context.pageType = 'PHOTOPAGE LIGHTBOX';
if (fixr.content.querySelector('div.vr-overlay-view') && fixr.content.querySelector('div.vr-overlay-view').hasChildNodes()) {
fixr.context.pageSubType='VR'; // VR-mode currently not supported in lightbox?
} else if (fixr.content.querySelector('div.videoplayer')) {
fixr.context.pageSubType='VIDEO';
} else {
fixr.context.pageSubType='PHOTO';
}
} else if (fixr.content.querySelector('div.albums-list-page-view')) {
fixr.context.pageType = 'ALBUMSLIST';
} else if (fixr.content.querySelector('div.album-page-view')) {
if (fixr.content.querySelector('div.slideshow-view')) {
fixr.context.pageType = 'ALBUM SLIDESHOW';
} else {
fixr.context.pageType = 'ALBUM';
}
} else if (fixr.content.querySelector('div.cameraroll-page-view')) {
fixr.context.pageType = 'CAMERAROLL';
} else if (fixr.content.querySelector('div.explore-page-view')) {
fixr.context.pageType = 'EXPLORE';
} else if (fixr.content.querySelector('div.favorites-page-view')) {
if (fixr.content.querySelector('div.slideshow-view')) {
fixr.context.pageType = 'FAVORITES SLIDESHOW';
} else {
fixr.context.pageType = 'FAVORITES';
}
} else if (fixr.content.querySelector('div.groups-list-view')) {
fixr.context.pageType = 'GROUPSLIST'; // personal grouplist
} else if (fixr.content.querySelector('div#activityFeed')) { // id=main i stedet for id=fixr.content
fixr.context.pageType = 'ACTIVITYFEED'; // aka. front page -> UPDATES ?
} else {
// fixr.context.pageType = ''; // unknown
}
log('fixr.context.pageType = ' + fixr.context.pageType);
log('fixr.context.pageSubType = '+fixr.context.pageSubType);
if (fixr.initUserId()) {
log('fixr.initUserId() returned with succes: '+fixr.context.userId);
} else {
log('fixr.initUserId() returned FALSE!');
}
if (fixr.initPhotographerId()) {
log('fixr.initPhotographerId() returned true in first try...');
} else {
log('fixr.initPhotographerId() returned false - re-running delayed...');
setTimeout(fixr.initPhotographerId, 1800);
}
if (fixr.initPhotoId()) {
log('fixr.initPhotoId() returned true in first try...');
} else {
log('fixr.initPhotoId() returned false - re-running delayed...');
setTimeout(fixr.initPhotoId, 1500);
}
if (fixr.initAlbumId()) {
log('fixr.initAlbumId() returned true in first try...');
}
if (fixr.initPhotographerName()) {
log('fixr.initPhotographerName() returned true in first try...');
} else {
setTimeout(fixr.initPhotographerName, 1500);
}
// Now run the page handlers....
if (fixr.onPageHandlers && fixr.onPageHandlers !== null && fixr.onPageHandlers.length) {
log('We have ' + fixr.onPageHandlers.length + ' onPage handlers starting now...');
for (var f = 0; f < fixr.onPageHandlers.length; f++) {
fixr.onPageHandlers[f]();
}
}
},
setupContent: function () {
if (document.getElementById('content')) {
fixr.content = document.getElementById('content');
} else if (document.getElementById('main')) {
fixr.content = document.getElementById('main'); // frontpage
}
if (fixr.content && fixr.content.id) {
log('fixr.content.id = ' + fixr.content.id);
} else {
log('content or main element NOT found!');
}
},
runPageActionsIfMissed: function () {
if (fixr.pageactionsCount === 0) {
log('Vi kører fixr.pageActions() på bagkant via onload...');
fixr.setupContent();
if (fixr.content === null) {
log('Vi kan IKKE køre fixr.pageActions() på bagkant, da fixr.content ikke er defineret');
return;
}
fixr.pageActions();
} else {
log('ej nødvendigt at køre fixr.pageActions() på bagkant i dette tilfælde...');
}
},
runDelayedPageActionsIfMissed: function () {
setTimeout(fixr.runPageActionsIfMissed, 2000);
},
resizeActions: function () {
if (fixr.onResizeHandlers && fixr.onResizeHandlers !== null && fixr.onResizeHandlers.length) {
for (var f = 0; f < fixr.onResizeHandlers.length; f++) {
fixr.onResizeHandlers[f]();
}
}
},
resizeActionsDelayed: function () { // or "preburner"
clearTimeout(fixr.timerResizeActionDelayed);
fixr.timerResizeActionDelayed = setTimeout(fixr.resizeActions, 250);
},
focusActions: function () {
if (fixr.onFocusHandlers && fixr.onFocusHandlers !== null && fixr.onFocusHandlers.length) {
for (var f = 0; f < fixr.onFocusHandlers.length; f++) {
fixr.onFocusHandlers[f]();
}
}
},
setupObserver: function () {
log('fixr.setupObserve INITIALIZATION START');
fixr.setupContent();
if (fixr.content === null) {
log('Init fails because content not defined');
return;
}
// create an observer instance
var observer = new MutationObserver(function (mutations) {
log('NEW PAGE MUTATION!');
//mutations.forEach(function(mutation) {
// log('MO: '+mutation.type); // might check for specific type of "mutations" (MutationRecord)
//});
fixr.pageActions();
}); // MutationObserver end
// configuration of the observer:
var config = {attributes: false, childList: true, subtree: false, characterData: false};
observer.observe(fixr.content, config);
log('fixr.setupObserve INITIALIZATION DONE');
},
init: function (onPageHandlerArray, onResizeHandlerArray, onFocusHandlerArray) {
// General page-change observer setup:
window.addEventListener('DOMContentLoaded', fixr.setupObserver, false); // Page on DOMContentLoaded
window.addEventListener('load', fixr.runDelayedPageActionsIfMissed, false); // Page on load
window.addEventListener('resize', fixr.resizeActionsDelayed, false); // også på resize
window.addEventListener('focus', fixr.focusActions, false);
if (onPageHandlerArray && onPageHandlerArray !== null && onPageHandlerArray.length) {
fixr.onPageHandlers = onPageHandlerArray; // Replace by adding with a one-by-one by "helper" for flexibility?
}
if (onResizeHandlerArray && onResizeHandlerArray !== null && onResizeHandlerArray.length) {
fixr.onResizeHandlers = onResizeHandlerArray; // Replace by adding with a one-by-one by "helper" for flexibility?
}
if (onFocusHandlerArray && onFocusHandlerArray !== null && onFocusHandlerArray.length) {
fixr.onFocusHandlers = onFocusHandlerArray;
}
}
};
// FIXR page-tracker end
var _timerMaplink = 0;
function updateMapLink() {
if (fixr.context.pageType !== 'PHOTOPAGE') {
return; // exit if not photopage
}
log('updateMapLink() running at readystate=' + document.readyState + ' and with photoId=' + fixr.context.photoId);
if (fixr.context.photoId) {
var maplink = fixr.content.querySelector('a.static-maps');
if (maplink) {
if (maplink.getAttribute('href') && (maplink.getAttribute('href').indexOf('map/?') > 0) && (maplink.getAttribute('href').indexOf('&photo=') === -1)) {
maplink.setAttribute('href', maplink.getAttribute('href') + '&photo=' + fixr.context.photoId);
log('link is updated by updateMapLink() at readystate=' + document.readyState);
} else {
log('link NOT updated by updateMapLink(). Invalid element or already updated. readystate=' + document.readyState);
}
} else {
log('NO maplink found at readystate=' + document.readyState + '. Re-try later?');
}
} else {
log('NO photoId found at readystate=' + document.readyState);
}
}
function updateMapLinkDelayed() {
if (fixr.context.pageType !== 'PHOTOPAGE') {
return;
} // exit if not photopage
log('updateMapLinkDelayed() running... with pageType=' + fixr.context.pageType);
//clearTimeout(_timerMaplink);
_timerMaplink = setTimeout(updateMapLink, 2000); // make maplink work better on photopage
}
var album = { // cache to avoid repeating requests
albumId: '',
commentCount: 0
};
function updateAlbumCommentCount() {
var _reqAlbumComments = null;
if (window.XMLHttpRequest) {
_reqAlbumComments = new XMLHttpRequest();
if (typeof _reqAlbumComments.overrideMimeType !== 'undefined') {
_reqAlbumComments.overrideMimeType('text/html');
}
_reqAlbumComments.onreadystatechange = function () {
if (_reqAlbumComments.readyState === 4 && _reqAlbumComments.status === 200) {
log('_reqAlbumComments returned status=' + _reqAlbumComments.status);
var doc = document.implementation.createHTMLDocument("sizeDoc");
doc.documentElement.innerHTML = _reqAlbumComments.responseText;
album.albumId = fixr.context.albumId;
album.commentCount = -1;
var e = doc.body.querySelectorAll('span.LinksNew b.Here');
if (e && e.length === 1) {
var n = parseInt(e[0].textContent, 10);
if (isNaN(n)) {
album.commentCount = 0;
} else {
album.commentCount = n;
}
} else {
album.commentCount = -1;
log('b.Here??? ');
}
if (document.getElementById('albumCommentCount')) {
if (album.commentCount === -1) {
document.getElementById('albumCommentCount').innerHTML = '?';
} else {
document.getElementById('albumCommentCount').innerHTML = '' + album.commentCount;
}
} else {
log('albumCommentCount element not found');
}
} else {
// wait for the call to complete
}
};
if (fixr.context.albumId === album.albumId && fixr.context.albumId !== '' && album.commentCount !== -1) {
log('Usinging CACHED album count!...');
document.getElementById('albumCommentCount').innerHTML = '' + album.commentCount;
} else if (fixr.context.albumId !== '') {
var url = 'https://www.flickr.com/photos/' + (fixr.context.photographerAlias !== '' ? fixr.context.photographerAlias : fixr.context.photographerId) + '/albums/' + fixr.context.albumId + '/comments/';
_reqAlbumComments.open('GET', url, true);
_reqAlbumComments.send(null);
} else {
log('albumId not initialized');
}
} else {
log('understøtter ikke XMLHttpRequest');
}
}
var albums = { // cache albums to avoid repeating requests
ownerId: '',
html: '',
count: 0
};
function getAlbumlist() {
var _reqAlbumlist = null;
if (window.XMLHttpRequest) {
_reqAlbumlist = new XMLHttpRequest();
if (typeof _reqAlbumlist.overrideMimeType !== 'undefined') {
_reqAlbumlist.overrideMimeType('text/html');
}
_reqAlbumlist.onreadystatechange = function () {
if (_reqAlbumlist.readyState === 4 && _reqAlbumlist.status === 200) {
log('_reqAlbumlist returned status=' + _reqAlbumlist.status); // + ', \ntext:\n' + _reqAlbumlist.responseText);
var doc = document.implementation.createHTMLDocument("sizeDoc");
doc.documentElement.innerHTML = _reqAlbumlist.responseText;
albums.ownerId = fixr.context.photographerId;
albums.html = '';
albums.count = 0;
var e = doc.body.querySelectorAll('div.photo-list-album-view');
var imgPattern = /url\([\'\"]*([^\)\'\"]+)(\.[jpgtifn]{3,4})[\'\"]*\)/i;
if (e && e.length > 0) {
albums.count = e.length;
for (var i = 0; i < Math.min(10, e.length); i++) {
var imgUrl = '';
//log(e[i].outerHTML);
//log('A7 (' + i + ') : ' + e[i].style.backgroundImage);
// var result = e[i].style.backgroundImage.match(imgPattern); // strangely not working in Chrome
var result = (e[i].outerHTML).match(imgPattern); // quick work-around for above (works for now)
if (result) {
// imgUrl = result[1].replace(/_[a-z]$/, '') + '_s' + result[2];
imgUrl = result[1].replace(/_[a-z]$/, '') + '_q' + result[2];
log('imgUrl=' + imgUrl);
} else {
log('No match on imgPattern');
}
var a = e[i].querySelector('a[href][title]'); // sub-element
if (a && a !== null) {
log('Album title: ' + a.title);
log('Album url: ' + a.getAttribute('href'));
albums.html += '
';
} else {
log('a element not found?');
}
}
} else if (e) {
if (doc.body.querySelector('h3')) {
albums.html = '
'+doc.body.querySelector('h3').textContent+'
'
}
} else {
log('(e UNdefined) Problem reading albums or no albums??? : ' + _reqAlbumlist.responseText );
}
if (document.getElementById('albumTeaser')) {
document.getElementById('albumTeaser').innerHTML = '
';
div.className = 'ncontent';
div.style.top = Math.floor(parseInt(n.h, 10) * scalefactor) - 2 + 'px';
div.style.left = '2px';
div.id = 'notetext'+i;
if (allowUpdateNotesViaAPIExplorer) {
// For public&safe photos where notes can be read: Create notes on (almost?) any photos, delete any note on own photos(?), edit own notes...
if (fixr.context.userId) {
// Allow create note (however not from here!)
}
if (fixr.context.userId===n.author) {
// Allow update own notes
div.innerHTML += '
';
} else if (fixr.context.photographerId===fixr.context.userId) {
// Allow Delete on any note on own photos
div.innerHTML += '';
}
}
document.querySelector('div.photo-well-media-scrappy-view').insertAdjacentHTML('afterbegin', '
'+ div.outerHTML +'
');
}
notes.showNotes();
// adjust size of note's textboxes:
var im = document.querySelector('img.main-photo');
var tn = 0;
var te= document.getElementById('notetext'+tn);
while(te) {
te.style.visibility = 'hidden';
te.style.display = 'block';
if(te.clientHeight>100 && im.clientWidth>150) {
te.style.width = Math.min(im.clientWidth,250)+'px';
}
if(te.clientHeight>im.clientHeight && im.clientWidth>250) {
te.style.width = Math.min(im.clientWidth,400)+'px';
}
if((te.clientHeight+20)>im.clientHeight) {
te.style.height = (im.clientHeight)-20+'px';
te.style.overflow = 'auto';
}
var tb = (parseInt(te.parentNode.parentNode.style.top,10) + parseInt(te.style.top,10) + te.clientHeight - 50 + 7);
if(tb>im.clientHeight) {
te.style.top = parseInt(te.style.top,10) - (tb - im.clientHeight) + 'px';
}
var tr = (parseInt(te.parentNode.parentNode.style.left,10) + parseInt(te.style.left,10) + te.clientWidth + 7);
if(tr>im.clientWidth) {
te.style.left = parseInt(te.style.left,10) - (tr - im.clientWidth) + 'px';
} te.style.display = '';
te.style.visibility = 'visible';
te = document.getElementById('notetext'+(++tn));
}
setTimeout(notes.hideNotes, 1000);
// click listener on hot rectangles
var bb = document.querySelectorAll('.notebrd1');
for(var b=0; b < bb.length; b++) {
bb[b].addEventListener('click',notes.levelNotesZ,false);
}
// click listener on note Edit buttons
var eb = document.querySelectorAll('.editNoteBtn');
for(b=0; b < eb.length; b++) {
eb[b].addEventListener('click',notes.editNoteDlg,false);
}
// click listener on note Delete buttons
var db = document.querySelectorAll('.deleteNoteBtn');
for(b=0; b < db.length; b++) {
db[b].addEventListener('click',notes.deleteNote,false);
}
},
_wsGetPhotoInfoLock: 0, // Date.now();
wsGetPhotoInfo: function () { // Call Flickr REST API to get photo info incl. eventual photo-notes
var diff = 0 + Date.now() - notes._wsGetPhotoInfoLock;
if ((notes._wsGetPhotoInfoLock > 0) && (diff < 50)) {
log('Skipping wsGetPhotoInfo() because already running?: ' + diff);
// *** maybe add a check to see if we are still on same photo? !!!
return;
}
var _reqGetPhotoInfo = null;
if (window.XMLHttpRequest) {
_reqGetPhotoInfo = new XMLHttpRequest();
if (typeof _reqGetPhotoInfo.overrideMimeType !== 'undefined') {
_reqGetPhotoInfo.overrideMimeType('application/json');
}
_reqGetPhotoInfo.onreadystatechange = function () {
if (_reqGetPhotoInfo.readyState === 4 && _reqGetPhotoInfo.status === 200) {
// do something with the results
log('webservice photos.getInfo returned status=' + _reqGetPhotoInfo.status);
// log('webservice photos.getInfo returned status=' + _reqGetPhotoInfo.status + ', text: ' + _reqGetPhotoInfo.responseText);
notes.photo.json = _reqGetPhotoInfo.responseText;
notes.photo.notes = [];
var obj = JSON.parse(_reqGetPhotoInfo.responseText);
if (obj.stat === "ok") {
log("flickr.photos.getInfo returned ok");
notes.photo.allowNotes = true;
if (obj.photo && obj.photo.id) {
notes.photo.photoId = obj.photo.id;
log('Notes fetched for ' + notes.photo.photoId);
if (obj.photo && obj.photo.notes && obj.photo.notes && obj.photo.notes.note && obj.photo.notes.note.length > 0) {
log("looks like there are " + obj.photo.notes.note.length + " notes on this photo");
notes.photo.notes = obj.photo.notes.note;
setTimeout(notes.renderNotes, 50); // a little delay seems to be good - sometimes
} else {
log('No notes or not accessible');
}
// start initUpdateNotes
if (allowUpdateNotesViaAPIExplorer) {
notes.updateNotesInitDelayed();
}
}
} else {
log('flickr.photos.getInfo returned an ERROR: obj.stat='+obj.stat+', obj.code='+obj.code+', obj.message='+obj.message);
// failed, and notes should probably not be createable either!!!
notes.photo.allowNotes = false;
}
notes._wsGetPhotoInfoLock = 0;
} else {
// wait for the call to complete
}
};
notes._wsGetPhotoInfoLock = Date.now();
_reqGetPhotoInfo.open('GET', 'https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=9b8140dc97b93a5c80751a9dad552bd4&photo_id=' + fixr.context.photoId + '&format=json&nojsoncallback=1', true);
_reqGetPhotoInfo.send(null);
} else {
log('understøtter ikke XMLHttpRequest');
}
},
initNotes: function (logtext) {
if (fixr.context.pageType === 'PHOTOPAGE' && fixr.context.pageSubType === 'PHOTO') { // Photopage with photos only (not video or vr)
log("initNotes(): " + fixr.context.photoId + ( logtext ? ': ' + logtext : '' ));
if (fixr.context.photoId) {
if (fixr.context.photoId === notes.photo.photoId) {
log('render cached notes');
setTimeout(notes.renderNotes, 100); // a little delay seems to be good - sometimes
// start initUpdateNotes
if (allowUpdateNotesViaAPIExplorer) {
notes.updateNotesInitDelayed();
}
} else {
log('render notes via flickr.photos.getInfo api method');
notes.wsGetPhotoInfo(); // wsGetPhotoInfo also calls renderNotes()
}
}
} else {
log('Exiting initNotes() because: fixr.context.pageType='+fixr.context.pageType+' and fixr.context.pageSubType='+fixr.context.pageSubType);
}
}
};
function apiExplorePreburner() {
log('Running apiExplorerPreburner()');
var ss = window.location.search.substring(1);
var pp = ss.split('&');
var fixr = ''; // no, it's another fixr
var fixrr = '';
var i = 0;
for(i=0; i0) {
if(f[0].action.indexOf('?')===-1) {
f[0].action += ('?fixrr='+fixr);
}
}
for(i=0; iphotopage:';
} else if (fixrr) { // ready to return to photopage
div.innerHTML = '
Step 2 of 2
Unless an error has occured, you can now return to an updated photopage:
';
}
document.getElementById('Main').insertAdjacentHTML('afterbegin',div.outerHTML);
}
}
if (window.location.href.indexOf('flickr.com\/services\/api\/explore\/flickr.photos.notes.')>-1) {
// We are on Flickr API Explorer for note handling and outside "normal" flickr page flow. fixr wont do here...
window.addEventListener('load', apiExplorePreburner, false);
} else {
scaler.postAction = notes.initNotes; // update notes after scaling
// FIXR fixr.init([onPageHandlers], [onResizeHandlers], [onFocusHandlers])
fixr.init([scaler.run, insertStyle, ctrlClicking, albumExtras, topPagination, ctrlClickingDelayed, exploreCalendarDelayed, albumTeaserDelayed, updateMapLinkDelayed, updateTagsDelayed], [scaler.run], [notes.initNotes]);
}