From cc67ee6775647894ef0ce2ac308510bdc4f07a63 Mon Sep 17 00:00:00 2001 From: DogmaDragon <103123951+DogmaDragon@users.noreply.github.com> Date: Sat, 6 Dec 2025 15:10:47 +0200 Subject: [PATCH] Add SFW Switch plugin --- plugins/SFWSwitch/README.md | 20 ++++++ plugins/SFWSwitch/sfw.css | 114 ++++++++++++++++++++++++++++++++ plugins/SFWSwitch/sfw.js | 94 ++++++++++++++++++++++++++ plugins/SFWSwitch/sfwswitch.yml | 9 +++ 4 files changed, 237 insertions(+) create mode 100644 plugins/SFWSwitch/README.md create mode 100644 plugins/SFWSwitch/sfw.css create mode 100644 plugins/SFWSwitch/sfw.js create mode 100644 plugins/SFWSwitch/sfwswitch.yml diff --git a/plugins/SFWSwitch/README.md b/plugins/SFWSwitch/README.md new file mode 100644 index 00000000..254b7fd7 --- /dev/null +++ b/plugins/SFWSwitch/README.md @@ -0,0 +1,20 @@ +# SFW Switch + +https://discourse.stashapp.cc/t/sfw-switch/4657 + +## Features + +- Adds a SFW toggle button to the menu bar. + - Green = Blur enabled + - Gray = Blur disabled +- Toggling the button blurs cover images and other content. +- Hovering over an image temporarily removes the blur. + +## Screenshots + +![image](https://user-images.githubusercontent.com/23707269/206918500-0676e4ea-dcfb-4370-b35f-3f6887b76b54.png) + +## Credit +Original plugin by Belleyy [here](https://github.com/Belleyy/CommunityScripts/tree/pluginUI_SFWSwitch/plugins/SFW%20Switch). + +The CSS code used is provided by fl0w#9497 [here](https://discourse.stashapp.cc/t/custom-css-snippets/4043#p-8143-blur-nsfw-images-and-unblur-on-mouse-over-41). \ No newline at end of file diff --git a/plugins/SFWSwitch/sfw.css b/plugins/SFWSwitch/sfw.css new file mode 100644 index 00000000..f4601ac0 --- /dev/null +++ b/plugins/SFWSwitch/sfw.css @@ -0,0 +1,114 @@ +/* [Global changes] Blur NSFW images and unblur on mouse over */ + +/*Credit: fl0w#9497 */ + +/* === MORE BLUR === */ +/* scene */ +.scene-card-preview, +.vjs-poster, +video, +.scene-cover, +.scrubber-item, + +/* image */ +.image-card-preview, +.image-image, +.gallery-image, + +/* group */ +.group-card-image, +.group-images, + +/* gallery */ +.gallery-card-image, +table > tbody > tr > td > a > img.w-100, + +/* performer */ +.performer-card-image, +img.performer, + +/* studio */ +.studio-card-image, + +/* tag */ +.tag-card-image + +{ +filter: blur(30px); +} + +/* === LESS BLUR === */ +/* common */ +.card-section-title, + +/* scene */ +.scene-studio-overlay, +.scene-header > h3, +h3.scene-header, +.studio-logo, +.image-thumbnail, + +/* image */ +h3.image-header, + +/* group */ +.group-details > div > h2, + +/* gallery */ +h3.gallery-header, + +/* studio */ +.studio-details .logo, +.studio-details > div > h2, + +/* tag */ +.logo-container > .logo, +.logo-container > h2 + +{ +filter: blur(2px); +} + +/* === UNBLUR ON HOVER === */ +/* common */ +.thumbnail-section:hover *, +.card:hover .card-section-title, + +/* scene */ +.card:hover .scene-studio-overlay, +.video-js:hover .vjs-poster, +video:hover, +.scene-header:hover > h3, +div:hover > .scene-header, +.studio-logo:hover, +.scene-cover:hover, +.image-thumbnail:hover, +.scene-card-preview:hover, +.scrubber-item:hover, + +/* image */ +.image-image:hover, +div:hover > .image-header, +.gallery-image:hover, + +/* group */ +.group-images:hover, +.group-details > div > h2:hover, + +/* gallery */ +div:hover > .gallery-header, +table > tbody > tr > td:hover > a > img.w-100, + +/* performer */ +img.performer:hover, + +/* studio */ +.studio-details .logo:hover, +.studio-details:hover > div > h2, + +/* tag */ +.logo-container > .logo:hover, +.logo-container:hover > h2 +{ +filter: blur(0px); +} \ No newline at end of file diff --git a/plugins/SFWSwitch/sfw.js b/plugins/SFWSwitch/sfw.js new file mode 100644 index 00000000..383255d5 --- /dev/null +++ b/plugins/SFWSwitch/sfw.js @@ -0,0 +1,94 @@ +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/sfw_switch/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(); diff --git a/plugins/SFWSwitch/sfwswitch.yml b/plugins/SFWSwitch/sfwswitch.yml new file mode 100644 index 00000000..b0d70b01 --- /dev/null +++ b/plugins/SFWSwitch/sfwswitch.yml @@ -0,0 +1,9 @@ +name: SFW Switch +description: Add a button to blur covers and images. +url: https://discourse.stashapp.cc/t/sfw-switch/4657 +version: 1.1 +ui: + javascript: + - sfw.js + css: + - sfw.css \ No newline at end of file