Skip to content

Instantly share code, notes, and snippets.

@Isuru-Nanayakkara
Last active January 29, 2025 14:20
Show Gist options
  • Save Isuru-Nanayakkara/425627b77a823233c2d7 to your computer and use it in GitHub Desktop.
Save Isuru-Nanayakkara/425627b77a823233c2d7 to your computer and use it in GitHub Desktop.
Add a link to download photos and videos from Instagram. (http://i.imgur.com/RvyxF2u.png)
// ==UserScript==
// @name InstaDownloader
// @description Download photos and videos from Instagram.
// @include https://www.instagram.com/p/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version 1.1
// @license GPL v3 or any later version (http://www.gnu.org/copyleft/gpl.html)
// @grant GM_addStyle
// ==/UserScript==
function addDownloadButton(jNode) {
// Left align the download button
$('.t28').css('align-items', 'flex-start');
var downloadButtonText = '';
var downloadLinkURL = '';
// Check the type of media
var medium = $('meta[name="medium"]').attr('content');
if (medium == 'image') {
downloadButtonText = 'Download Image'
downloadLinkURL = $('meta[property="og:image"]').attr('content');
} else if (medium == 'video') {
downloadButtonText = 'Download Video'
downloadLinkURL = $('meta[property="og:video"]').attr('content');
}
// Create download button
var downloadLink = document.createElement('a');
downloadLink.setAttribute('id', 'downloadLink');
downloadLink.setAttribute('href', downloadLinkURL);
downloadLink.innerHTML = downloadButtonText;
// Add the download button to page
$('.t28').prepend(downloadLink);
}
waitForKeyElements('div.s28', addDownloadButton);
/* Style our newly added elements using CSS */
GM_addStyle ( multilineStr ( function () {/*!
#downloadLink {
-webkit-appearance: button-bevel;
-moz-appearance: button-bevel;
appearance: button-bevel;
padding: 7px;
margin-bottom: 4px;
}
*/} ) );
function multilineStr (dummyFunc) {
var str = dummyFunc.toString ();
str = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
.replace (/\s*\*\/\s*\}\s*$/, '') // Strip */ }
.replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
;
return str;
}
@Korb
Copy link

Korb commented Jan 5, 2021

Firefox 85.0b4 (64-bit), Tampermonkey 4.11.6120 - no links or buttons for downloading appeared, everything in the context menu is as usual.

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