Snippets

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

Updated by Xavier Langlois

File Instagram - get original image - Tampermonkey / Greasemonkey script Modified

  • Ignore whitespace
  • Hide word diff
 // ==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
+// @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==
 
-// INSTALL
-// cf [http://tampermonkey.net/] for Chrome / Safari
-// or [https://addons.mozilla.org/fr/firefox/addon/greasemonkey/] for firefox
+(function() {
+    'use strict';
 
-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);
+    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>');
+                }
+            }
+        });
     }
-};
-xl714addJQueryIfNeeded();
 
-$(".-cx-PRIVATE-Photo__root").on('mouseenter', function (event) { 
+    $( document ).ready(function() {
+        console.log( "ready!" );
+        xl714Go();
+    });
 
-    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>');
-    }
-});  
+    $( document ).ajaxComplete(function() {
+        console.log( "Triggered ajaxComplete handler." );
+        xl714Go();
+    });
+
+})();
Created by Xavier Langlois

File Instagram - get original image - Tampermonkey / Greasemonkey script Added

  • Ignore whitespace
  • Hide word diff
+// ==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.