You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

5 years ago
const set_image_expand = (x, set) => {
const matches = /i\/(thumb\/)?(\d+\.\w+)$/i.exec(x.getAttribute("src"));
if(matches[1])
{
//Is thumbnail
if(set===true || set===undefined)
x.setAttribute("src", "i/"+matches[2]);
}
else {
//Is full
if(set===false || set===undefined)
x.setAttribute("src", "i/thumb/"+matches[2]);
}
};
window.addEventListener('load', () => {
document.querySelectorAll(".thread").forEach(x=> x.classList.toggle("hidden"));
document.querySelectorAll(".script").forEach(x=> x.style=""); //unhide script-specific elements
document.querySelectorAll(".expand").forEach(x=> {
x.addEventListener("click", ()=> {
document.querySelector("[id='"+ x.getAttribute("href").slice(1) +"']").classList.toggle("hidden");
});
});
5 years ago
document.querySelectorAll("figure > img").forEach(x=> {
x.addEventListener("click", ()=> {
set_image_expand(x);
});
});
//nav buttons
document.querySelector("#expand_all_threads").addEventListener("click", () => {
document.querySelectorAll("section.hidden").forEach(x=> {
x.classList.toggle("hidden");
});
});
document.querySelector("#collapse_all_threads").addEventListener("click", () => {
document.querySelectorAll("section:not(.hidden)").forEach(x=> {
x.classList.toggle("hidden");
});
});
document.querySelector("#expand_all_images").addEventListener("click", () => {
document.querySelectorAll("figure > img").forEach(x=> {
set_image_expand(x, true);
});
});
document.querySelector("#collapse_all_images").addEventListener("click", () => {
document.querySelectorAll("figure > img").forEach(x=> {
set_image_expand(x, false);
});
});
});