function sfw_mode() { const stash_css = sfwswitch_findstashcss(); const button = document.getElementById("plugin_sfw"); if (stash_css && stash_css.disabled) { // SFW mode is disabled button.style.color = "#f5f8fa"; // Default color } else { // SFW mode is enabled button.style.color = "#5cff00"; // Active color } } function sfwswitch_createbutton() { const buttonId = "plugin_sfw"; // Check if the button already exists if (document.getElementById(buttonId)) { return; } // Create the button element const buttonContainer = document.createElement("a"); buttonContainer.className = "mr-2"; buttonContainer.innerHTML = ` `; // Poll for the navbar-buttons container const intervalId = setInterval(() => { const navbarButtons = document.querySelector(".navbar-buttons"); if (navbarButtons) { clearInterval(intervalId); // Stop polling navbarButtons.insertBefore(buttonContainer, navbarButtons.childNodes[0]); // Add click event listener document.getElementById(buttonId).addEventListener("click", sfwswitch_switcher); // Initialize the button state sfw_mode(); } }, 100); // Check every 100ms // Stop polling after a timeout to avoid infinite loops setTimeout(() => clearInterval(intervalId), 10000); // 10 seconds max } function sfwswitch_switcher() { const stash_css = sfwswitch_findstashcss(); if (!stash_css) { console.error("SFW stylesheet not found."); return; } stash_css.disabled = !stash_css.disabled; const button = document.getElementById("plugin_sfw"); if (stash_css.disabled) { console.log("SFW mode disabled"); button.style.color = "#f5f8fa"; // Default color } else { console.log("SFW mode enabled"); button.style.color = "#5cff00"; // Active color } } function sfwswitch_findstashcss() { for (let i = 0; i < document.styleSheets.length; i++) { const stylesheet = document.styleSheets[i]; if (stylesheet.href && stylesheet.href.includes("/plugin/sfwswitch/css")) { return stylesheet; } } return null; // Return null if no matching stylesheet is found } function waitForElementClass(elementId, callBack, time) { time = (typeof time !== 'undefined') ? time : 100; window.setTimeout(function () { var element = document.getElementsByClassName(elementId); if (element.length > 0) { callBack(elementId, element); } else { waitForElementClass(elementId, callBack); } }, time); } sfwswitch_createbutton();