Snippets

Xavier Langlois Instagram - get original image - Tampermonkey / Greasemonkey script

You are viewing an old version of this snippet. View the current version.
Revised by Xavier Langlois db1ede4
// ==UserScript==
// @name       Instagram - Get original pictures link
// @namespace  http://use.i.E.your.homepage/
// @version    0.1
// @description  On Instagram, this script will add a link to the original image(s)
// @match      https://www.instagram.com/*
// @copyright  2016+, XL714 aka Xavier Langlois
// ==/UserScript==

// INSTALL
// cf [http://tampermonkey.net/] for Chrome / Safari
// or [https://addons.mozilla.org/fr/firefox/addon/greasemonkey/] for firefox

function xl714addJQueryIfNeeded(){
    if( !window.jQuery ){
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js';
        document.getElementsByTagName('head')[0].appendChild(script);
    }
};
xl714addJQueryIfNeeded();

$(".-cx-PRIVATE-Photo__root").on('mouseenter', function (event) { 

    img = $(this).find("img");
    src = img.attr('src'); // resized image : eg 640 x 640
    // small image url : https://igcdn-photos-d-a.akamaihd.net/hphotos-ak-xat1/t51.2885-15/e35/12237575_1654895741420683_516758420_n.jpg
    // big image url   : https://igcdn-photos-d-a.akamaihd.net/hphotos-ak-xat1/t51.2885-15/s640x640/sh0.08/e35/12237575_1654895741420683_516758420_n.jpg
    src = src.replace(/\/s\d+x\d+\/[^\/]+\//g, ''); // small image url => big image url
    linkID = img.attr('id') + '_linkID';
    
    if(! $("#"+linkID ).length)
    {
        // if parent tag name is <A> (link) this is the grid view. If not, it's a <DIV> it is image item view
        if($(this).parent().prop('tagName') == 'A'){
            linkStyle = 'width:10px;word-wrap: break-word;text-align:center;display:inline-block;padding:3px;background-color:LightYellow; color:MediumSeaGreen ;border:1px solid MediumSpringGreen;';
            linkText = 'Link<br/><br/>to<br/><br/>image';
        }else{
            linkStyle = 'text-align:center;display:inline-block;padding:3px;background-color:LightYellow; color:MediumSeaGreen ;border:1px solid MediumSpringGreen;';
            linkText = 'Link to image';
        }
        
        $(this).parent().before('<a id="'+linkID+'" href="'+src+'" target="_blank" style="'+linkStyle+'">'+linkText+'</a>');
    }
});  
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.