Skip to content

Instantly share code, notes, and snippets.

@madprops
Created July 24, 2026 04:09
Show Gist options
  • Select an option

  • Save madprops/ca776c893d286e59b0d5be18d1906370 to your computer and use it in GitHub Desktop.

Select an option

Save madprops/ca776c893d286e59b0d5be18d1906370 to your computer and use it in GitHub Desktop.
Instagram Ctrl+Click on Your Activity - By default this page doesn't offer a way to open items in a new tab, you have to click them, and when you do you lose scroll position. This fixes it - Just paste it in the console
document.body.addEventListener(`click`, function(event) {
if (event.ctrlKey || event.metaKey) {
let target_node = event.target
let img_node = null
if (target_node.tagName === `IMG`) {
img_node = target_node
}
else if (target_node.querySelector(`img`)) {
img_node = target_node.querySelector(`img`)
}
else {
let parent_container = target_node.closest(`[data-bloks-name="bk.components.Flexbox"]`)
if (parent_container) {
img_node = parent_container.querySelector(`img`)
}
}
if (img_node) {
if (img_node.src) {
if (img_node.src.includes(`ig_cache_key`)) {
event.preventDefault()
event.stopPropagation()
try {
let img_url = new URL(img_node.src)
let cache_key_param = img_url.searchParams.get(`ig_cache_key`)
if (cache_key_param) {
let b64_part = cache_key_param.split(`.`)[0]
let media_id_str = atob(b64_part)
let alphabet = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_`
let id_num = BigInt(media_id_str)
let shortcode_str = ``
while (id_num > 0n) {
let remainder = Number(id_num % 64n)
shortcode_str = alphabet[remainder] + shortcode_str
id_num = id_num / 64n
}
if (shortcode_str !== ``) {
window.open(`https://www.instagram.com/p/${shortcode_str}/`, `_blank`)
}
else {
console.error(`Could not calculate shortcode`)
}
}
}
catch (err) {
console.error(`Failed to parse URL`, err)
}
}
}
}
}
}, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment