Skip to content

Instantly share code, notes, and snippets.

@tire-fire
Created October 25, 2025 20:11
Show Gist options
  • Select an option

  • Save tire-fire/84a48b595ea9667ff3899f3b1bec3b0f to your computer and use it in GitHub Desktop.

Select an option

Save tire-fire/84a48b595ea9667ff3899f3b1bec3b0f to your computer and use it in GitHub Desktop.
Right-click save instagram image
// ==UserScript==
// @name Instagram Right-Click Save
// @namespace http://tampermonkey.net/
// @version 4.4
// @description Enable native right-click save on Instagram images
// @match https://www.instagram.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
console.log('Instagram Right-Click Save initializing...');
const originalAddEventListener = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function(type, listener, options) {
if (type === 'contextmenu') {
return;
}
return originalAddEventListener.call(this, type, listener, options);
};
const processedSrcs = new Set();
function enableImageRightClick() {
const images = document.querySelectorAll('img.x5yr21d, img[src*="cdninstagram"]');
let processed = 0;
for (const img of images) {
if (!img.src || processedSrcs.has(img.src)) continue;
if (processed >= 20) break;
const parent = img.parentElement;
if (!parent) continue;
if (parent.querySelector('.instagram-save-overlay')) continue;
img.style.pointerEvents = 'auto';
img.draggable = true;
const overlay = document.createElement('div');
overlay.className = 'instagram-save-overlay';
overlay.style.cssText = `
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 999;
pointer-events: auto;
cursor: context-menu;
`;
const overlayImg = document.createElement('img');
overlayImg.src = img.src;
overlayImg.crossOrigin = 'anonymous';
overlayImg.style.cssText = `
width: 100%;
height: 100%;
object-fit: cover;
pointer-events: auto;
`;
overlay.appendChild(overlayImg);
if (parent.style.position !== 'relative' && parent.style.position !== 'absolute') {
parent.style.position = 'relative';
}
parent.appendChild(overlay);
processedSrcs.add(img.src);
processed++;
}
if (processed > 0) {
console.log(`Added overlays to ${processed} images (total tracked: ${processedSrcs.size})`);
}
}
let debounceTimer;
let isProcessing = false;
const observer = new MutationObserver(() => {
if (isProcessing) return;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
isProcessing = true;
enableImageRightClick();
isProcessing = false;
}, 300);
});
function init() {
console.log('Instagram Right-Click Save initialized');
enableImageRightClick();
if (document.body) {
observer.observe(document.body, {
childList: true,
subtree: true
});
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
@grand-lotus-iroh
Copy link

grand-lotus-iroh commented Nov 19, 2025

Talk about light weight... this is great. Thanks!!

I also like this one too - https://greasyfork.org/en/scripts/521062-instagram-working-progress-bar/code

I pushed this through bot and it works if you want something half the lines:

// ==UserScript==
// @name         IG Right-Click Save Minimal
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Enable right-click save on Instagram images efficiently
// @match        https://www.instagram.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
  'use strict';

  // Block all new contextmenu event listeners
  const origAddEventListener = EventTarget.prototype.addEventListener;
  EventTarget.prototype.addEventListener = function (t, l, o) {
    if (t === 'contextmenu') return;
    return origAddEventListener.call(this, t, l, o);
  };

  const seen = new Set();
  function addOverlays() {
    document.querySelectorAll('img.x5yr21d, img[src*="cdninstagram"]').forEach(img => {
      if (!img.src || seen.has(img.src)) return;
      const parent = img.parentElement;
      if (!parent || parent.querySelector('.ig-rc-overlay')) return;

      img.style.pointerEvents = 'auto';
      img.draggable = true;

      const overlay = document.createElement('div');
      overlay.className = 'ig-rc-overlay';
      overlay.style = `
        position:absolute;top:0;left:0;width:100%;height:100%;z-index:999;pointer-events:auto;cursor:context-menu;
      `;
      const overlayImg = document.createElement('img');
      overlayImg.src = img.src;
      overlayImg.crossOrigin = 'anonymous';
      overlayImg.style = 'width:100%;height:100%;object-fit:cover;pointer-events:auto;';
      overlay.appendChild(overlayImg);

      if (!/relative|absolute/.test(parent.style.position)) parent.style.position = 'relative';
      parent.appendChild(overlay);

      seen.add(img.src);
    });
  }

  const obs = new MutationObserver(() => setTimeout(addOverlays, 200));
  window.addEventListener('DOMContentLoaded', () => {
    addOverlays();
    if (document.body) obs.observe(document.body, { childList: true, subtree: true });
  });
})();

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