Skip to content

Instantly share code, notes, and snippets.

@dshster
Created June 12, 2016 10:52
Show Gist options
  • Save dshster/2f4aef73fa336e126f83a06efb1c0a35 to your computer and use it in GitHub Desktop.
Save dshster/2f4aef73fa336e126f83a06efb1c0a35 to your computer and use it in GitHub Desktop.
Append download link to instagram photos (userscript)
// ==UserScript==
// @name Instagram image in a new tab
// @namespace http://shvalyov.ru
// @version 0.1
// @description append download link to photos
// @author dshster
// @match https://www.instagram.com/*
// @grant none
// ==/UserScript==
(function(window, undefined) {
'use strict';
var document = window.document;
var $main = document.querySelector('main > section > div > div');
function appendDownloadLinkToArticle(articleNode) {
var downloadLink = document.createElement('a');
var header = articleNode.querySelector('header');
var image = articleNode.querySelector('div > div > div > img[src]');
var imageUrl = image.src;
var filename = imageUrl.split('/').pop();
downloadLink.href = imageUrl;
downloadLink.setAttribute('download', filename);
downloadLink.appendChild(document.createTextNode('Download image'));
header.appendChild(downloadLink);
downloadLink.onclick = function(event) {
event.preventDefault();
}
}
var observer = new window.MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var article;
if (mutation.addedNodes.length === 1) {
article = mutation.addedNodes[0];
if (article.nodeName === 'ARTICLE') {
appendDownloadLinkToArticle(article);
}
}
});
});
observer.observe($main, { childList: true });
var articles = document.querySelectorAll('article');
Array.prototype.forEach.call(articles, function(article) {
appendDownloadLinkToArticle(article);
});
})(window);
@Korb
Copy link

Korb commented Jan 5, 2021

Firefox 84.0.1 x64, Tampermonkey 4.11.6120 - не распознается, как userscript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment