User:Wadiox123/global.js

(function { "use strict"; if (window.wadiox123 && window.wadiox123.category_exhibition_auto_advance && window.wadiox123.category_exhibition_auto_advance.has_run) return; if (!window.wadiox123) {   window.wadiox123 = {        category_exhibition_auto_advance: {}    }; } else if (!window.wadiox123.category_exhibition_auto_advance) {    window.wadiox123.category_exhibition_auto_advance = {}; } window.wadiox123.category_exhibition_auto_advance.has_run = true; var paginator = document.querySelector("#mw-pages > .category-gallery-paginator > .wikia-paginator > ul"); var forward_text = window.wadiox123.category_exhibition_auto_advance.forward_text; var forward_title = window.wadiox123.category_exhibition_auto_advance.forward_title; var backward_text = window.wadiox123.category_exhibition_auto_advance.backward_text; var backward_title = window.wadiox123.category_exhibition_auto_advance.backward_title; var halt_text = window.wadiox123.category_exhibition_auto_advance.halt_text; var halt_title = window.wadiox123.category_exhibition_auto_advance.halt_title; var interval = window.wadiox123.category_exhibition_auto_advance.interval; var enable = window.wadiox123.category_exhibition_auto_advance.enable; var init_pause = window.wadiox123.category_exhibition_auto_advance.init_pause; var buttons, timer; if (!forward_text) forward_text = "\u25ba"; if (!forward_title) forward_title = "Scroll Forward"; if (!backward_text) backward_text = "\u25c4"; if (!backward_title) backward_title = "Scroll Backward"; if (!halt_text) halt_text = "\u25a0"; if (!halt_title) halt_title = "Stop Scrolling"; if (!interval || (typeof interval !== "number")) interval = 5000; if (interval < 1000) interval = 1000; if ((mw.config.get("wgNamespaceNumber") === 14) && paginator) { if (enable === "forward") { forward; } else if (enable === "backward") { backward; } else { halt; } } function forward { disableButton("forward"); removeTimer; if (!init_pause) goForward; timer = setInterval(goForward, interval); } function backward { disableButton("backward"); removeTimer; if (!init_pause) goBackward; timer = setInterval(goBackward, interval); } function halt { disableButton("halt"); removeTimer; } function disableButton(direction) { buttons = document.getElementById("wadiox123-categoryexhibitionautoadvance-buttons"); getPaginator; if (paginator && !buttons) { buttons = document.createElement("span"); buttons.id = "wadiox123-categoryexhibitionautoadvance-buttons"; buttons.innerHTML = ""+backward_text+" "+halt_text+" "+forward_text+" "; buttons.children[0].addEventListener("click", backward); buttons.children[1].addEventListener("click", halt); buttons.children[2].addEventListener("click", forward); paginator.parentElement.parentElement.insertAdjacentElement("afterend", buttons); }   buttons.children[0].classList.remove("disabled"); buttons.children[1].classList.remove("disabled"); buttons.children[2].classList.remove("disabled"); buttons.children[0].style.removeProperty("display"); buttons.children[1].style.removeProperty("display"); buttons.children[2].style.removeProperty("display"); if (direction === "forward") { buttons.children[2].classList.add("disabled"); buttons.children[2].style.display = "none"; } else if (direction === "backward") { buttons.children[0].classList.add("disabled"); buttons.children[0].style.display = "none"; } else if (direction === "halt") { buttons.children[1].classList.add("disabled"); buttons.children[1].style.display = "none"; } } function removeTimer { if (timer) clearInterval(timer); timer = false; } function goForward { getPaginator; if (paginator) { var next = paginator.querySelector("li > .paginator-next:not(.disabled)"); if (!next) next = paginator.querySelector("li:nth-of-type(2) > a"); next.click; } } function goBackward { getPaginator; if (paginator) { var next = paginator.querySelector("li > .paginator-prev:not(.disabled)"); if (!next) next = paginator.querySelector("li:nth-last-of-type(2) > a"); next.click; } } function getPaginator { paginator = document.querySelector("#mw-pages > .category-gallery-paginator > .wikia-paginator > ul"); if (!paginator) { removeTimer; if (buttons) buttons.parentElement.removeChild(buttons); buttons = false; } } }); //