Snippets

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

Created by Xavier Langlois last modified
// ==UserScript==
// @name         Get insta image
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.instagram.com/*
// @grant        none
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==

(function() {
    'use strict';

    var xl714Go = function(){
        $('img[srcset]').on('mouseenter', function (event) {
            let srcset = $(this).attr('srcset').split(',');console.log('srcset', srcset);
            if(srcset.length){
                srcset = srcset[srcset.length-1].split(' ');
                let src = srcset[0];console.log('src', src); // resized image : eg 640 x 640
                if(! $(this).parent().find('.xl714-dl-link').length){
                    //let linkStyle = 'width:10px;word-wrap: break-word;text-align:center;display:inline-block;padding:3px;background-color:LightYellow; color:MediumSeaGreen ;border:1px solid MediumSpringGreen;';
                    let linkStyle = 'text-align:center;display:inline-block;padding:3px;background-color:LightYellow; color:MediumSeaGreen ;border:1px solid MediumSpringGreen;';
                    $(this).closest('article').parent().before('<a class="xl714-dl-link" href="'+src+'" target="_blank" style="'+linkStyle+'">Image</a>');
                }
            }
        });
        $('img[srcset]').each(function() {
            //let img = $(this).find("img").get(1);
            let srcset = $(this).attr('srcset').split(',');console.log('srcset', srcset);
            if(srcset.length){
                srcset = srcset[srcset.length-1].split(' ');
                let src = srcset[0];console.log('src', src); // resized image : eg 640 x 640
                if(! $(this).parent().find('.xl714-dl-link').length){
                    //let linkStyle = 'width:10px;word-wrap: break-word;text-align:center;display:inline-block;padding:3px;background-color:LightYellow; color:MediumSeaGreen ;border:1px solid MediumSpringGreen;';
                    let linkStyle = 'text-align:center;display:inline-block;padding:3px;background-color:LightYellow; color:MediumSeaGreen ;border:1px solid MediumSpringGreen;';
                    $(this).closest('article').parent().before('<a class="xl714-dl-link" href="'+src+'" target="_blank" style="'+linkStyle+'">Image</a>');
                }
            }
        });
    }

    $( document ).ready(function() {
        console.log( "ready!" );
        xl714Go();
    });

    $( document ).ajaxComplete(function() {
        console.log( "Triggered ajaxComplete handler." );
        xl714Go();
    });

})();

Comments (0)