Last active
January 30, 2019 21:44
-
-
Save nakami/660aa0841ae60d558935b2ea2531fb7b to your computer and use it in GitHub Desktop.
Add high resolution download button on the pinkbike POD page
This file contains hidden or 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
// run on https://www.pinkbike.com/photo/podlist/ | |
// high res links look like this: https://lp1.pinkbike.org/p0pb<ID>/<ID>.jpg | |
// get all li-tags with 'inElm' class | |
var li_inElms = document.querySelectorAll('li.inElm') | |
// iterate over all li-tags | |
for(var i = 0; i < li_inElms.length; i++){ | |
// get the id | |
var link = li_inElms[i].getElementsByTagName('a')[0].getAttribute('href'); | |
var link_splitted = link.split("/"); | |
var id = link_splitted[4]; | |
// build the high res link | |
var dl_link = 'https://lp1.pinkbike.org/p0pb' + id + '/' + id + '.jpg'; | |
// create a new 'a' element | |
var new_a = document.createElement("a"); | |
new_a.setAttribute('href', dl_link); | |
new_a.setAttribute('download', id + ".jpeg"); | |
new_a.innerHTML = 'download'; | |
// add 'a' to li element | |
li_inElms[i].appendChild(new_a); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment