- Install TamperMonkey extension
- Click on
Rawbutton near theinstagram-image-download.user.jsscript - Click "Install"
Now you have a download button on each photo.
| // ==UserScript== | |
| // @name Instagram Image Download | |
| // @namespace ig | |
| // @include https://www.instagram.com/* | |
| // @match *://www.instagram.com/* | |
| // @version 1.3 | |
| // @grant none | |
| // @author Oleg Koval | |
| // ==/UserScript== | |
| let lastUrl = location.href; | |
| let styleTag = document.createElement('style'); | |
| styleTag.innerHTML = ` | |
| .ig-photo-dl { | |
| z-index: 11; | |
| position: absolute; | |
| top: 16px; | |
| left: 16px; | |
| padding: 11px 10px 7px; | |
| background-color: #fff; | |
| text-decoration: none; | |
| border-radius: 2px; | |
| color: #222; | |
| opacity: 0.6; | |
| } | |
| .ig-photo-dl:hover, .ig-photo-dl:active, .ig-photo-dl:focus { | |
| opacity: 1; | |
| color: #222; | |
| text-decoration: none; | |
| } | |
| `; | |
| document.body.appendChild(styleTag); | |
| function setButtons() { | |
| const uls = document.querySelectorAll('article ul'); | |
| if (uls.length === 0) { | |
| return; | |
| } | |
| let imgs = uls[0].querySelectorAll('img'); | |
| for (const img of imgs) { | |
| if (img.parentNode.getElementsByClassName('ig-photo-dl').length) { | |
| continue; | |
| } | |
| if (img.parentNode.parentNode.parentNode.tagName.toLowerCase() === 'a') { | |
| continue; | |
| } | |
| let imageUrl = img.getAttribute('src'); | |
| let dl = document.createElement('a'); | |
| dl.href = imageUrl; | |
| dl.setAttribute('download', imageUrl.substr(imageUrl.lastIndexOf('/') + 1)); | |
| dl.setAttribute('target', '_blank'); | |
| dl.setAttribute('class', 'ig-photo-dl'); | |
| dl.innerHTML = ` | |
| <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" | |
| width="16px" height="16px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"> | |
| <g> | |
| <path d="M256,512l256-256H352V0.001L160,0v256H0L256,512z"/> | |
| </g> | |
| </svg> | |
| `; | |
| img.parentNode.insertBefore(dl, img); | |
| let observer = new MutationObserver(function(mutations) { | |
| for (const mutation of mutations) { | |
| if (mutation.attributeName == 'src') { | |
| console.log(mutation); | |
| let target = mutation.target; | |
| let button = target.previousSibling; | |
| let targetImageUrl = target.src; | |
| button.href = targetImageUrl; | |
| button.setAttribute('download', targetImageUrl.substr(targetImageUrl.lastIndexOf('/') + 1)); | |
| } | |
| } | |
| }); | |
| observer.observe(img.parentNode, {attributes: true, subtree: true}); | |
| } | |
| } | |
| // something changed? | |
| let observer = new MutationObserver(function(mutations) { | |
| setButtons(); | |
| }); | |
| observer.observe(document, {attributes: true, childList: true, characterData: false, subtree: true}); |
Под Firefox 85.0b4 (64-bit) и Tampermonkey 4.11.6120 - работает, под Firefox 84.0.1 x64 - нет.