Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PC friendly instagram
// ==UserScript==
// @name pc-friendly-instagram
// @namespace https://gist.github.com/justdanpo
// @version 0.7
// @description pc-friendly-instagram
// @author den_po
// @include https://*.instagram.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
const ua = navigator.userAgent += " Instagram"
let loaderFound = false
let cfgFound = false
let oldReq = undefined
document.documentElement.setAttribute('onreset', "navigator.__defineGetter__('userAgent', function(){ return '" + ua.replace(/'/g, "\'") + "' });")
document.documentElement.dispatchEvent(new CustomEvent('reset'))
document.documentElement.removeAttribute('onreset')
new MutationObserver((mutations, observer) => mutations.forEach(mutation => mutation.addedNodes.forEach(itm => {
if (itm.tagName == "SECTION") {
//expand feed width
itm.querySelectorAll("main > section").forEach(s => { s.style.maxWidth = "calc(100vh - 120px)" })
//limit preview size
itm.querySelectorAll("div > button > span.createSpriteExpand").forEach(expandButton => {
expandButton.parentNode.parentNode.style.width = expandButton.parentNode.parentNode.style.height = "calc(100vh - 100px)"
itm.style.display = "table"
})
//move buttons to top
itm.querySelectorAll('nav > div > div > div:nth-of-type(2)').forEach(buttons => {
buttons.style.left = "50px"
buttons.style.top = "0"
buttons.style.bottom = "auto"
buttons.style.zIndex = "20"
buttons.style.width = "200px"
})
//add permanent "feed" link
itm.querySelectorAll('svg[aria-label="Posts"]').forEach(postsGrid => {
const link = postsGrid.closest("a")
const originalFeedLink = link.nextSibling
let newLink = document.createElement("a")
newLink.href = link.href += "feed/"
newLink.innerHTML = '<span class="glyphsSpritePhoto_list__outline__24__grey_5" aria-label="Feed"></span>'
newLink.className = originalFeedLink.className
newLink.onclick = (e) => { e.preventDefault(); originalFeedLink.click() }
originalFeedLink.style.display = "none"
link.parentNode.insertBefore(newLink, link.nextSibling)
new MutationObserver((mutations, observer) => mutations.forEach(mutation => {
if (newLink.className != mutation.target.className) newLink.className = mutation.target.className
})).observe(originalFeedLink, { attributes: true })
})
//search input
itm.querySelectorAll('input[placeholder="Search"]').forEach(searchInput => {
searchInput.style.marginLeft = "250px"
})
}
else if (itm.tagName == "SCRIPT" && !loaderFound) {
let match = /Requiring module.*?\.(\w+)=function/g.exec(itm.innerHTML)
if (match && match.length > 1) {
loaderFound = true
function myReq(fn, idx, dependencies) {
return oldReq(
(g, r, i, a, m, e, d) => {
let retValue = fn(g, r, i, a, m, e, d)
if (!cfgFound && m && m.hasOwnProperty("exports") && m.exports && m.exports.hasOwnProperty("feed-sidebar-threshold-min")) {
cfgFound = true
window._hookedConfig = m.exports
window._hookedConfig["feed-sidebar-threshold-min"].value = 99999
}
return retValue
}
, idx, dependencies)
}
window.__defineGetter__(match[1], function () { return myReq })
window.__defineSetter__(match[1], function (newVal) { oldReq = newVal })
}
}
if (itm && itm.querySelectorAll) {
itm.querySelectorAll('video').forEach(video => {
video.controls = "controls"
})
itm.querySelectorAll('img').forEach(img => {
let decoding = img.attributes.getNamedItem("decoding")
if (decoding && decoding.value == "auto") {
//get image context menu back
if (img.parentNode.nextSibling && img.parentNode.nextSibling.children.length == 0) img.parentNode.nextSibling.style.display = "none"
//improve image quality
img.sizes = "1080px"
new MutationObserver((mutations, observer) => mutations.forEach(mutation => { img.sizes = "1080px" })).observe(img, { attributes: true, attributeFilter: ['srcset'] })
}
})
//remove annoying "login to continue" popup
if (itm.tagName == "DIV" && itm.querySelector('.coreSpriteLoggedOutWordmark')) {
itm.parentNode.removeChild(itm)
document.body.style.overflow = "auto"
let bo = new MutationObserver((mutations, observer) => mutations.forEach(mutation => { document.body.style.overflow = "auto" }))
bo.observe(document.body, { attributes: true, attributeFilter: ['style'] })
setTimeout(() => bo.disconnect(), 1000)
}
}
}))).observe(document, { childList: true, subtree: true })
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.