Code for Chrome 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.
/*
Checks is there prevLocation already set up and is it the same or changed from
last time it was called. Used explicit referrence from window object to avoid
Referrence error on the first run.
*/
let same = !!window.prevLocation && window.prevLocation === location.pathname;
let prevLocation = same ? window.prevLocation : location.pathname;
/* Narrow scope for further DOM elements search. */
let article = same ? window.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 */
let dots = same ? window.dots : [...article.querySelectorAll('._acnb')];
/*
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.
*/
let viewBoxLeft = same
? window.viewBoxLeft
: dots.length && Math.floor(article.querySelector('div div[role=presentation]').getBoundingClientRect().left);
/* If there are many photos it holds the list of all slides elements */
let slides = same && !dots.length
? window.slides
: [...article.querySelectorAll('div[role=presentation] li[tabindex="-1"]')];
/* If there are many photos it holds last dot index */
let maxIndx = same
? window.maxIndx
: Math.max(0, dots.length - 1);
/* If there are many photos it gets index of dot marked as active */
let dotIndx = dots.length && dots.findIndex(item => item.classList.contains('_acnf'));
/*
If active dot index...
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.