Code for Browser Bookmarklet used to quickly save post media (photo or video).
Since instagram started using blobs for video this code doesn't work for major part of video in posts.
/*
Opens currently viewed (single) image. Currently no solution to track down blob link
to real video link.
IIFE prevents Instagram page to become blank in Firefox after invoking bookmarklet.
*/
(function() {
/*
Create object with temporary data that could be helpful between bookmarklet invokations.
*/
window._im ??= {};
var im = window._im;
/*
Checks is there prevLocation already set up and is it the same or changed from
last time it was called.
*/
var same = !!im?.prevLocation && im?.prevLocation === window.location.pathname;
/* Variables that should be recalculated only if we moved to new post */
if (!same) {
im.prevLocation = window.location.pathname;
/* Narrow scope for further DOM elements search. */
im.article =
document.body.querySelector('div[role=dialog] article') ||
document.body.querySelector('article');
/* Array of photo slider indicators visible as dots in the bottom of view box */
im.dots = [...im.article.querySelectorAll('._acnb')];
/* If there are many photos it holds last dot index */
im.maxIndx = Math.max(0, im.dots.length - 1);
/*
Viewbox is element that holds all slides inside, but cut visible part with
`overflow: hidden` and other styles. Viewbox left position related to window
needed to find correct slide if it's not first or last photo in a photo set.
Previously when there was multiple (> 2) photos there were three slides. First
and last slide became actual (visible) only when shows first or last photo in
photo set. All others fall into second. But now there are four slides and
sometimes current photo fall into second, sometimes fall into third slide and I
couldn't get the logic behind that. So I've come up with this solution.
*/
im.viewBoxLeft = im.dots.length && Math.round(im.article.querySelector('div div[role=presentation]').getBoundingClientRect().left);
}
/*
If there are many photos it holds the list of all slides elements. Slides elements
are...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.