Last active
April 14, 2025 23:48
-
-
Save CodeZombie/1c1fa714fc8c92275e99 to your computer and use it in GitHub Desktop.
Expand All Images in 4chan Thread Greasemonkey Extension
This file contains hidden or 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
// ==UserScript== | |
// @name Expand All Images | |
// @namespace zombiearmy.expandimage | |
// @description Expand all images in a 4chan thread | |
// @match *://boards.4chan.org/* | |
// @match *://boards.4channel.org/* | |
// @version 2 | |
// @grant none | |
// ==/UserScript== | |
var expanded = false; | |
//add expand buttons for desktop | |
var navlink = document.getElementsByClassName("navLinks desktop"); | |
for(var i = 0; i < navlink.length; i++) { | |
navlink[i].innerHTML += " [<a href='javascript:toggleImages()'>Toggle Images</a>] "; | |
} | |
//add expand buttons for mobile | |
navlink = document.getElementsByClassName("navLinks mobile"); | |
for(i = 0; i < navlink.length; i++) { | |
navlink[i].innerHTML += '<span class="mobileib button"><a href="javascript:toggleImages()">Expand Images</a></span>'; | |
} | |
window.toggleImages = function() { | |
var thumbs = document.getElementsByClassName("fileThumb"); | |
if(!expanded) { | |
expanded = true; | |
for(var i = 0; i < thumbs.length; i++) { | |
var img = thumbs[i].getElementsByTagName('img')[0]; | |
if (img.alt != "File deleted.") { | |
ImageExpansion.expand(img); | |
} | |
} | |
}else{ | |
expanded = false; | |
var collapseWebm = document.getElementsByClassName("collapseWebm"); | |
var expandedWebm = document.getElementsByClassName("expandedWebm"); | |
while(collapseWebm.length > 0){ | |
collapseWebm[0].remove(); | |
} | |
while(expandedWebm.length > 0){ | |
expandedWebm[0].remove(); | |
} | |
for(var i = 0; i < thumbs.length; i++) { | |
if(thumbs[i].style.display=="none"){ | |
thumbs[i].style.display = null; | |
} | |
var img = thumbs[i].getElementsByTagName('img')[1]; | |
if (img !== undefined) { | |
ImageExpansion.contract(img); | |
} | |
} | |
} | |
} |
The script would stop if it encountered a deleted image in a thread. Here there is a quick fix:
Edit: Videos weren't collapsing, fixed that too.
window.toggleImages = function() {
var thumbs = document.getElementsByClassName("fileThumb");
if(!expanded) {
expanded = true;
for(var i = 0; i < thumbs.length; i++) {
var img = thumbs[i].getElementsByTagName('img')[0];
if (img.alt != "File deleted.") {
ImageExpansion.expand(img);
}
}
}else{
expanded = false;
var collapseWebm = document.getElementsByClassName("collapseWebm");
var expandedWebm = document.getElementsByClassName("expandedWebm");
while(collapseWebm.length > 0){
collapseWebm[0].remove();
}
while(expandedWebm.length > 0){
expandedWebm[0].remove();
}
for(var i = 0; i < thumbs.length; i++) {
if(thumbs[i].style.display=="none"){
thumbs[i].style.display = null;
}
var img = thumbs[i].getElementsByTagName('img')[1];
if (img !== undefined) {
ImageExpansion.contract(img);
}
}
}
}
Also the the includes should be updated to this:
// @include *://boards.4chan.org/*
// @include *://boards.4channel.org/*
Not sure if anyone is still using this in 2022 (I'm not!) but I just updated it with Maurogch's fixes (thank you!!!!) because this page still seems to still come up on google searches, so it might as well be functional :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The links are showing on the page, but when I click them in Firefox 58.0.22 nothing happens. The console says
ReferenceError: toggleImages is not defined
. I've tried messing around but can't find a solution. Any help would be appreciated.