Last active
March 20, 2017 17:32
-
-
Save skoshy/d97a43167d4c32b2e4e73f97dd877516 to your computer and use it in GitHub Desktop.
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
var scriptId = 'insta-dl'; | |
function addLinks() { | |
let els = document.querySelectorAll('._jjzlb, ._2tomm'); | |
for (let i = 0; i < els.length; i++) { | |
if (els[i].querySelector('.download_link')) | |
continue; // skip if there already is a download link | |
let obj, link; | |
if (obj = els[i].querySelector('video')) { | |
link = obj.src; | |
} else if (obj = els[i].querySelector('img')) { | |
link = obj.src; | |
} | |
let linkObj = document.createElement('a'); | |
linkObj.innerHTML = "Download"; | |
linkObj.className = "download_link"; | |
linkObj.target = '_blank'; | |
linkObj.href = link | |
els[i].appendChild(linkObj); | |
} | |
} | |
function addGlobalStyle(css, id, enabled) { | |
var head, style; | |
head = document.getElementsByTagName('head')[0]; | |
if (!head) { return; } | |
style = document.createElement('style'); | |
style.type = 'text/css'; | |
style.innerHTML = css; | |
style.id = id; | |
head.appendChild(style); | |
style.disabled = !enabled; | |
} | |
if (!document.querySelector(scriptId+'-css')) { | |
addGlobalStyle(` | |
.download_link { | |
font-size: 24px; | |
position: absolute; | |
bottom: 10px; | |
right: 10px; | |
z-index: 1; | |
text-shadow: 0px 0px 15px black; | |
} | |
.download_link, .download_link:hover, .download_link:active, .download_link:visited { | |
color: white; | |
} | |
`, scriptId+'-css', true); | |
} | |
addLinks(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment