// ==UserScript== // @name Flickr: Show All Sizes // @namespace Jason Tank/Druidic // @description Adds links to every available size of a Flickr image. // @version 4.1.2 // @require http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js // @match *://*.flickr.com/photos/* // @downloadURL none // ==/UserScript== // Summary: Links appear below the image's description on individual Flickr photo pages. They are fetched in the background, so an animated 'loading' message will appear until the links are ready. // Based (somewhat) on http://userscripts.org/scripts/show/103073 // v1.0 - Initial script. // v1.1 - Small visual tweaks. // - Added links to new "Small 320" and "Medium 800" formats. // v1.2 - Minor change to loading message. // - More documentation in-script. // v1.3 - "Large 1600" and "Large 2048" now supported. // - More documentation. // - Image links now rearrange by size if too many are available. // v1.4 - More robust image-checking. // v1.4.1 - Square 150 support. // - Even MORE robust image-checking. // v1.5 - Reorganized script, links. Trying to keep output on one line. // - Links now have tooltips. // - Redid image-checking using HTML to save info instead of the sometimes-buggy .data() jQuery method. // - Thumbnail is now simply "Small 100". (But remains "Thumbnail" in tooltip.) // v2.0 - Changed methodology. Rather than brute-force trying all possible files, just look at ONE image page and figure out what's available. // - Moved from jQuery 1.6.2 to 1.7.2 // v2.1 - Fixed bug where Firefox would not show links. (Bug probably existed since 1.5!) // - More documentation // v2.2 - Even more documentation!! // - Fixed an unclosed tag in the Medium 640 link. // v2.3 - Clarified the error message and altered its appearance. // - Simplied code. // - Added a check for jQuery, so we don't have to load a second instance if it's already installed. // - Added support for secure (https) pages. // v2.4 - @namespace added. // - Moved the NotOkToDeLoad variable initialization to a place where it would actually initialize! (oops) // - @require added. // - Added "?zz=1" to Medium 640 images so older photos can resize correctly. // v2.5 - Compacted three @match commands into one. // - Bumped up to jQuery 1.8.2 // - Tweaked error message, directing users to http://userscripts.org/scripts/discuss/111902 // v3.0 - Bumped up to jQuery 1.8.3 // - Turned off loading of larger sizes by default. // v3.1 - Minor coding tweaks. (Flickr updated its interface, this extension still works with it!) // v3.2 - Changed colors to match current Flickr look. // - Minor CSS tweak to push Hack outside of a neighbor element's bounding box. // - Bumped up to jQuery 2.0.0 // v3.2.1 - Minor code-style tweaks. (unreleased) // v4.0 - MAJOR rewrite, inspired by http://userscripts.org/scripts/show/168642 // - Revamped the way images are found, using the YUI that Flickr itself uses, when possible. // - Optimized for use with TamperMonkey on Chrome. // - Menu option allows you to change link behavior: view image in browser, or download image. // - Added support for the new "beta" look, as well as the "old" look. // - Tooltips now show width and height of the image. // v4.0.1 - Deleted unused code. // - More documentation. // - Bug fix: Non-JPG original images and some Large size images weren't being transformed into download links. // v4.0.2 - Kludge to fix a bug in the Beta that's erasing the sizes as soon as they're loaded. // v4.1 - Added GM menu commands to toggle viewing of square/small/medium/large images. // v4.1.1 - Fixed bug where sizes wouldn't show. // v4.1.2 - Another workaround regarding the ever-changing Beta backend. // Do we want to download images (true), or view them (false)? var downloadLinks = GM_getValue("downloadLinks", false); function maybeModifyLinks(val) { var h; if (val) { alert("Clicking on links will now download the image."); } else { alert("Clicking on links will now load the image in the browser."); } if(val === downloadLinks) { // Same value. No need to do anything. return; } downloadLinks = val; $("a.fshLink").each(function() { h = $(this).attr("href"); if(val) { // Change to download links. $(this).attr("href", h.replace(/\.([a-z]+)$/i, "_d.$1")); } else { // Change to non-download links. $(this).attr("href", h.replace(/_d\.([a-z]+)$/i, ".$1")); } }); } // Do we want to see certain groups of links (true) or not (false)? var showSquare = GM_getValue("showSquare", true); var showSmall = GM_getValue("showSmall", true); var showMedium = GM_getValue("showMedium", true); var showLarge = GM_getValue("showLarge", true); // Original sizes images will ALWAYS show, if available. function doToggle(imageSize, newFlag) { var m = " be shown. You will need to reload the page for this change to take effect."; GM_setValue("show" + imageSize, newFlag); if(newFlag) { m = imageSize + " images will now" + m; } else { m = imageSize + " images will no longer" + m; } alert(m); } // Register Greasemonkey/Tampermonkey menu commands GM_registerMenuCommand('Flickr: SAS: View Images in Browser', function(cmd) { GM_setValue("downloadLinks", false); maybeModifyLinks(false); }); GM_registerMenuCommand('Flickr: SAS: Download Images', function(cmd) { GM_setValue("downloadLinks", true); maybeModifyLinks(true); }); GM_registerMenuCommand('Flickr: SAS: Toggle Square Images', function(cmd) { showSquare = !showSquare; doToggle("Square", showSquare); }); GM_registerMenuCommand('Flickr: SAS: Toggle Small Images', function(cmd) { showSmall = !showSmall; doToggle("Small", showSmall); }); GM_registerMenuCommand('Flickr: SAS: Toggle Medium Images', function(cmd) { showMedium = !showMedium; doToggle("Medium", showMedium); }); GM_registerMenuCommand('Flickr: SAS: Toggle Large Images', function(cmd) { showLarge = !showLarge; doToggle("Large", showLarge); }); // a function that loads jQuery and calls a callback function when jQuery has finished loading // (This is necessary for straight Chromium, which doesn't support @require) function addJQuery(mainScript) { var script = document.createElement("script"); script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"); script.setAttribute('type', 'text/javascript'); script.addEventListener('load', function() { var script = document.createElement("script"); script.textContent = "(" + mainScript.toString() + ")();"; document.body.appendChild(script); }, false); document.body.appendChild(script); } // the guts of this userscript function flickrSizeHackMain() { var flickrVersion; // Check if we're on the right type of page. if($("div#main div#primary-column div#meta").length <= 0) { if($("div#content div.photo-page-view div.photo-sidebar-view div.sidebar-panel-fixed div.photo-sidebar-actions-view").length <= 0) { return; // Not a photo page. No need to run. } flickrVersion = 2; // We're in the beta } else { flickrVersion = 1; // We're in the old-style } //*//*//*//*//*//*//*//*//*//*//*//*//*// // HTML AND CSS DISPLAY // //*//*//*//*//*//*//*//*//*//*//*//*//*// // NOTE about the TITLE attribute. // The links' title attributes contain space-deliminated information. // (1) The default image link ending. // (2) The default download link ending. [new info: v4.0] // (3) The link's group (small, medium, etc). // (4) The link's maximum height and width. // (5) Flickr's special name for this link's size. [optional] // All information is used in pre-4.0 scripts, and in the legacy code for bare Chromium installs. // Only 3, 4 and 5 are used in 4.0+ scripts. // Initialize variables var fshHTML,fshHTMLhead,fshHTMLtail,fshHTMLtemp,wholeStyle,linkStyle,groupStyle,rowStyle; // Animation of the 'loading' block. function animateLoading() { var Lone = $("div#FlickrSizeHack span.fshL1"), Ltwo = $("div#FlickrSizeHack span.fshL2"), Lthr = $("div#FlickrSizeHack span.fshL3"); function doFading() { Lone.fadeOut(200); Lone.fadeIn(200); Ltwo.delay(100); Ltwo.fadeOut(200); Ltwo.fadeIn(200); Lthr.delay(300); Lthr.fadeOut(200); Lthr.fadeIn(200, doFading); } doFading(); } if(flickrVersion === 1) { // // ORIGINAL LAYOUT // // Create the HTML for display. fshHTML = '