Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A bookmarklet for downloading currently viewed Flickr image in the biggest available size
/*jslint browser, maxlen: 80 */
/*global DOMParser, fetch */
(function () {
"use strict";
var originalSizeLink = document.querySelector(".Original > a");
var canonicalUrl = document.querySelector("#canonicalurl").href;
var biggestSizeUrl = canonicalUrl + "/sizes/k/";
var secondBiggestSizeUrl = canonicalUrl + "/sizes/h/";
function downloadImage(href) {
var a = document.createElement("a");
a.href = href;
a.download = document.title.split(" |")[0] + ".jpg";
document.body.appendChild(a);
a.click();
}
function getHrefAndDownloadImage(responseText) {
var href = new DOMParser()
.parseFromString(responseText, "text/html")
.querySelector("#allsizes-photo > img")
.src;
downloadImage(href);
}
if (originalSizeLink) {
return originalSizeLink.click();
}
fetch(biggestSizeUrl)
.then(function (response) {
return (response.ok && response.url === biggestSizeUrl)
? response
: fetch(secondBiggestSizeUrl);
})
.then(function (response) {
return response.text();
})
.then(getHrefAndDownloadImage);
}());
@version365

This comment has been minimized.

Copy link

commented Feb 12, 2018

How to add it to Chrome?
I created a new bookmark and edited the URL as javascript:your code
But nothing happen when clicked!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.