// ==UserScript== // @name Flickr Original Link // @namespace https://greasyfork.org/scripts/1190-flickr-original-link // @include /flickr\.com/ // @version 5.4.1 // @grant GM_getValue // @grant GM_setValue // @grant GM_addStyle // @require https://code.jquery.com/jquery-3.3.1.min.js // @description Show direct links to download biggest Flickr image available and some other sizes. // @downloadURL none // ==/UserScript== var postfix = "_d.jpg"; var prefix = "DOWNLOAD "; var isChecked_openLink = ""; var isChecked_alwaysShow = ""; var key_openLink = "flickr_openLink"; var key_alwaysShow = "flickr_alwaysShow"; var value_openLink = false; var value_alwaysShow = false; var imageSizeOrder = ["o", "k", "h", "l", "c", "z"]; var globalObserver = null; function log(s) { console.log(s); } log("Begin flickr script"); function getSetting() { log("Begin get settings"); value_openLink = GM_getValue(key_openLink, false); value_alwaysShow = GM_getValue(key_alwaysShow, false); if (value_openLink) { postfix = "."; isChecked_openLink = ' checked="checked" '; prefix = "OPEN "; } else { postfix = "_d."; isChecked_openLink = ""; prefix = "DOWNLOAD "; } if (value_alwaysShow) { isChecked_alwaysShow = ' checked="checked" '; } else { isChecked_alwaysShow = ""; } } function checkAlwaysShow() { if (value_alwaysShow) { $('div.interaction-view').css('opacity', '1'); } $('div.interaction-bar').css('bottom', '1.1em'); } function action_single_page() { if ($('.commonButton').length > 0) return false; var action = function (sourceCode) { var sizes = sourceCode.match(/modelExport: {.+?"sizes":{.+?}}/i); var mSize = sizes[0].match(/"width":"?\d+"?,"height":"?\d+"?,/ig); var mLink = sizes[0].match(/"displayUrl":"[^"]+"/ig); var length = mLink.length; for (var k = 0; k < length; k++) { mSize[k] = mSize[k].replace(/"width":(\d+),"height":(\d+),/i, "$1 x $2"); mLink[k] = mLink[k].replace(/"displayUrl":"([^"]+)"/i, "$1").replace(/\\/g, "").replace(/(_[a-z])\.([a-z]{3,4})/i, '$1' + postfix + '$2'); } var insertLocation = $('.sub-photo-right-row1').filter(':first'); var str = '' + prefix + mSize[length - 1] + ' px'; for (k = length - 2; k > length - 6; --k) { str += '' + mSize[k] + ' px'; } insertLocation.html(insertLocation.html() + str); }; $.get(document.URL, action); } function getLinkFromSource(data) { if (data === null) return;// source code is not loaded, or empty, or has nothing good var sizes = data.match(/"sizes":.+?}}/ig); if (sizes === null) return false; // source code is not loaded, or empty, or has nothing good var dates = data.match(/"datePosted":"\d+"/ig); if (dates == null) { log("cannot find any dates"); } var e2 = $('div.photo-list-photo-view'); for (var index = 0; index < e2.length; index++) { var e = $(e2[index]); if (e.find('.myFuckingLink').filter(':first').length > 0) continue; e.html(e.html() + ''); for (var i = 0; i < imageSizeOrder.length; ++i) { var photo = sizes[index].match(new RegExp('"' + imageSizeOrder[i] + '":{"displayUrl":"([^"]+)","width":(\\d+),"height":(\\d+)', "i")); if (photo === null) continue; var b = e.find('.myFuckingLink'); //b.attr('href', "http:" + photo[1].replace(/\\/g, "").replace(/(_[a-z])\.([a-z]{3,4})/i, '$1' + postfix + '$2')); //new flickr update 4/4/2019. Links now included https and are full address. b.attr('href', photo[1].replace(/\\/g, "").replace(/(_[a-z])\.([a-z]{3,4})/i, '$1' + postfix + '$2')); var timestamp = dates[index].match(/\d+/i); var t = new Date((new Number(timestamp)) * 1000); b.attr('title', prefix + photo[2] + " x " + photo[3] + " | Upload: " + t.toLocaleDateString()); b.html(prefix + photo[2] + " x " + photo[3]); break; } } } function action_normal_page() { var target = $('#content')[0]; var config = { childList: true, subtree: true, }; var prevUrl = "none"; var prevThumbLength = 0; var sourceCode = null; var action = function () { var e3 = $('div.photo-list-photo-view'); if (document.URL == prevUrl) { if (e3.length == prevThumbLength) return false; // number of thumbnail is not change, no need to process further checkAlwaysShow(); prevThumbLength = e3.length; log("Number of thumb: " + prevThumbLength); // source code is get, use it now getLinkFromSource(sourceCode); } else { var e1 = e3.find('a').filter(':first'); if (e1.length < 1) return false; // not found any link to valid single image page checkAlwaysShow(); // get full source code for this page sourceCode = null; prevUrl = document.URL; var link1 = e1.attr('href'); console.time("GetSource"); $('#content').append('