Last active
September 12, 2021 04:54
-
-
Save moreinthemiddle/ef019f481d1b15d7c65697798eadcdbe to your computer and use it in GitHub Desktop.
Twitter is kind of dumb about letting you see images without zooming in. This scripts fixes that, if in a really hacky way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setInterval(()=>{ | |
let increase = 500 | |
let maxHeight = '800px' | |
let div4 = ' > div'.repeat(4) | |
let select = document.querySelector.bind(document) | |
let selectAll = document.querySelectorAll.bind(document) | |
let getBounds = el => el.parentElement.parentElement.getBoundingClientRect() | |
let reactCSS = Array.from(select('#react-native-stylesheet').sheet.rules) | |
reactCSS.forEach(r => { | |
if (r.style) { | |
if (r.style.maxWidth) (r.style.maxWidth = r.style.maxWidth.replace(/600(?=px)/, s => +s + increase)) | |
if (r.style.width) (r.style.width = r.style.width.replace(/990(?=px)/, s => +s + increase)) | |
} | |
}) | |
let masonrySelector = ' > div > div > div > div:nth-child(2) > div:nth-child(2) > div:nth-child(2) > div[class]:not([style]):nth-child(2)' | |
selectAll(`[data-testid=tweet] ${masonrySelector}, [data-testid=tweet] + div ${masonrySelector}`).forEach(masonry => { | |
let els, maxWidth = '100%' | |
let vid = masonry.querySelector('video') | |
if (vid) { | |
els = [vid] | |
maxWidth = vid.videoWidth + 'px' | |
// vid.style.maxWidth = maxWidth | |
return | |
} | |
els = Array.from(masonry.querySelectorAll('img:not([src$=svg])')) | |
if (!els.length || els[0].width < 64) return | |
if (!els.some(el => getBounds(el).bottom > 300 && getBounds(el).top < window.innerHeight * 2)) return | |
els.sort((a,b) => getBounds(a).top - getBounds(b).top) | |
let div = document.createElement('div') | |
els.forEach(i => { | |
let el = document.createElement('img') | |
el.src = i.src.replace(/(&?)name=(\d+x\d+|\w+)/,'$1name=large') | |
el.style.maxHeight = maxHeight | |
el.style.maxWidth = maxWidth | |
div.append(el) | |
}) | |
masonry.parentElement.insertBefore(div, masonry) | |
masonry.style.display = 'none' | |
}) | |
}, 500) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment