Created
March 3, 2018 17:33
-
-
Save buzamahmooza/c57b98f85709393a05997ab3cc782e64 to your computer and use it in GitHub Desktop.
A bookmarklet to downloads all original images on a pinterest page. Just drag the code to your bookmarks or save it and add "JavaScript:" in the beginning, visit pinterest and click that bookmark, boom! magic!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(typeof download !== 'function') { | |
alert("The download function was not found on this page, please run the 'downoader' script using tampermonkey."); void(0); | |
} | |
if(/www\.pinterest\./.test(location.href)){ | |
var imgBoxes = document.querySelectorAll('._qk._2h._ql'); | |
console.log('ImgBoxes:', imgBoxes); | |
if(confirm('Download '+imgBoxes.length+' images?')) | |
imgBoxes.forEach(function(imgBox, index, array){ | |
try{ | |
let img = imgBox.querySelector('img[srcset]'); | |
let srcset = img.getAttribute('srcset'); | |
let src = srcset.match(new RegExp(`(/{1,2}|http(s?:))[\d\w?%-_/\=.]*?.(jpg|png|jpeg|gif|tiff)(&f=1)?`, "gim")).pop(); | |
let name = imgBox.querySelector('._nv._ms._mt._mu._nx._5k._mv._n5._n3._my span span').innerHTML; | |
console.log('src:', src, 'name:', name); | |
if(typeof download === 'function') | |
download(src, name); | |
else | |
window.open(src, "_blank"); | |
}catch(exc){console.warn(exc);} | |
}); | |
} else | |
alert('The site you are on is not Pinterest.com, this script will not work on other websites.'); | |
/*Not needed, but could be handy*/ | |
function extractFromSrcset(img){ | |
var bestSrc = "_"; | |
try{ | |
var srcset = img.getAttribute('srcset').split(/\s*?\dx\,*\s*/); | |
var topSrc = srcset.pop(); | |
bestSrc = topSrc.length>0?topSrc:srcset.pop(); | |
}catch(e){} | |
return bestSrc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script will open many pages and may get blocked by the pop-up blocker.
A workaround for this is to use have my other Downloader script active, allowing the script to download immediately rather than needing to open pages.
If you don't have the my other main Downlaoder script active on Tampermonkey, you can do so by clicking this link:
Download Tampermonkey for Chrome
And then clicking on the Downloader link.
Then enable Browser API in your Tampermonkey settings: go to settings->change novice to advanced, -> in Download Mode Beta, set it to Browser API.