Last active
January 29, 2025 14:20
-
-
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)
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
// ==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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment