Skip to content

Commit 4580493

Browse files
authored
Add SFW Switch plugin (#641)
1 parent 1387085 commit 4580493

File tree

4 files changed

+237
-0
lines changed

4 files changed

+237
-0
lines changed

plugins/SFWSwitch/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SFW Switch
2+
3+
https://discourse.stashapp.cc/t/sfw-switch/4657
4+
5+
## Features
6+
7+
- Adds a SFW toggle button to the menu bar.
8+
- Green = Blur enabled
9+
- Gray = Blur disabled
10+
- Toggling the button blurs cover images and other content.
11+
- Hovering over an image temporarily removes the blur.
12+
13+
## Screenshots
14+
15+
![image](https://user-images.githubusercontent.com/23707269/206918500-0676e4ea-dcfb-4370-b35f-3f6887b76b54.png)
16+
17+
## Credit
18+
Original plugin by Belleyy [here](https://github.com/Belleyy/CommunityScripts/tree/pluginUI_SFWSwitch/plugins/SFW%20Switch).
19+
20+
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).

plugins/SFWSwitch/sfw.css

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* [Global changes] Blur NSFW images and unblur on mouse over */
2+
3+
/*Credit: fl0w#9497 */
4+
5+
/* === MORE BLUR === */
6+
/* scene */
7+
.scene-card-preview,
8+
.vjs-poster,
9+
video,
10+
.scene-cover,
11+
.scrubber-item,
12+
13+
/* image */
14+
.image-card-preview,
15+
.image-image,
16+
.gallery-image,
17+
18+
/* group */
19+
.group-card-image,
20+
.group-images,
21+
22+
/* gallery */
23+
.gallery-card-image,
24+
table > tbody > tr > td > a > img.w-100,
25+
26+
/* performer */
27+
.performer-card-image,
28+
img.performer,
29+
30+
/* studio */
31+
.studio-card-image,
32+
33+
/* tag */
34+
.tag-card-image
35+
36+
{
37+
filter: blur(30px);
38+
}
39+
40+
/* === LESS BLUR === */
41+
/* common */
42+
.card-section-title,
43+
44+
/* scene */
45+
.scene-studio-overlay,
46+
.scene-header > h3,
47+
h3.scene-header,
48+
.studio-logo,
49+
.image-thumbnail,
50+
51+
/* image */
52+
h3.image-header,
53+
54+
/* group */
55+
.group-details > div > h2,
56+
57+
/* gallery */
58+
h3.gallery-header,
59+
60+
/* studio */
61+
.studio-details .logo,
62+
.studio-details > div > h2,
63+
64+
/* tag */
65+
.logo-container > .logo,
66+
.logo-container > h2
67+
68+
{
69+
filter: blur(2px);
70+
}
71+
72+
/* === UNBLUR ON HOVER === */
73+
/* common */
74+
.thumbnail-section:hover *,
75+
.card:hover .card-section-title,
76+
77+
/* scene */
78+
.card:hover .scene-studio-overlay,
79+
.video-js:hover .vjs-poster,
80+
video:hover,
81+
.scene-header:hover > h3,
82+
div:hover > .scene-header,
83+
.studio-logo:hover,
84+
.scene-cover:hover,
85+
.image-thumbnail:hover,
86+
.scene-card-preview:hover,
87+
.scrubber-item:hover,
88+
89+
/* image */
90+
.image-image:hover,
91+
div:hover > .image-header,
92+
.gallery-image:hover,
93+
94+
/* group */
95+
.group-images:hover,
96+
.group-details > div > h2:hover,
97+
98+
/* gallery */
99+
div:hover > .gallery-header,
100+
table > tbody > tr > td:hover > a > img.w-100,
101+
102+
/* performer */
103+
img.performer:hover,
104+
105+
/* studio */
106+
.studio-details .logo:hover,
107+
.studio-details:hover > div > h2,
108+
109+
/* tag */
110+
.logo-container > .logo:hover,
111+
.logo-container:hover > h2
112+
{
113+
filter: blur(0px);
114+
}

plugins/SFWSwitch/sfw.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
function sfw_mode() {
2+
const stash_css = sfwswitch_findstashcss();
3+
const button = document.getElementById("plugin_sfw");
4+
5+
if (stash_css && stash_css.disabled) {
6+
// SFW mode is disabled
7+
button.style.color = "#f5f8fa"; // Default color
8+
} else {
9+
// SFW mode is enabled
10+
button.style.color = "#5cff00"; // Active color
11+
}
12+
}
13+
14+
function sfwswitch_createbutton() {
15+
const buttonId = "plugin_sfw";
16+
17+
// Check if the button already exists
18+
if (document.getElementById(buttonId)) {
19+
return;
20+
}
21+
22+
// Create the button element
23+
const buttonContainer = document.createElement("a");
24+
buttonContainer.className = "mr-2";
25+
buttonContainer.innerHTML = `
26+
<button id="${buttonId}" type="button" class="minimal d-flex align-items-center h-100 btn btn-primary" title="Turn SFW Mode">
27+
<svg fill="currentColor" xmlns="http://www.w3.org/2000/svg" class="svg-inline--fa fa-cog fa-w-16 fa-icon undefined" viewBox="1.5 1.5 13 13">
28+
<path d="m7.646 9.354-3.792 3.792a.5.5 0 0 0 .353.854h7.586a.5.5 0 0 0 .354-.854L8.354 9.354a.5.5 0 0 0-.708 0z"></path>
29+
<path d="M11.414 11H14.5a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.5-.5h-13a.5.5 0 0 0-.5.5v7a.5.5 0 0 0 .5.5h3.086l-1 1H1.5A1.5 1.5 0 0 1 0 10.5v-7A1.5 1.5 0 0 1 1.5 2h13A1.5 1.5 0 0 1 16 3.5v7a1.5 1.5 0 0 1-1.5 1.5h-2.086l-1-1z"></path>
30+
</svg>
31+
</button>
32+
`;
33+
34+
// Poll for the navbar-buttons container
35+
const intervalId = setInterval(() => {
36+
const navbarButtons = document.querySelector(".navbar-buttons");
37+
if (navbarButtons) {
38+
clearInterval(intervalId); // Stop polling
39+
navbarButtons.insertBefore(buttonContainer, navbarButtons.childNodes[0]);
40+
41+
// Add click event listener
42+
document.getElementById(buttonId).addEventListener("click", sfwswitch_switcher);
43+
44+
// Initialize the button state
45+
sfw_mode();
46+
}
47+
}, 100); // Check every 100ms
48+
49+
// Stop polling after a timeout to avoid infinite loops
50+
setTimeout(() => clearInterval(intervalId), 10000); // 10 seconds max
51+
}
52+
53+
function sfwswitch_switcher() {
54+
const stash_css = sfwswitch_findstashcss();
55+
if (!stash_css) {
56+
console.error("SFW stylesheet not found.");
57+
return;
58+
}
59+
60+
stash_css.disabled = !stash_css.disabled;
61+
62+
const button = document.getElementById("plugin_sfw");
63+
if (stash_css.disabled) {
64+
console.log("SFW mode disabled");
65+
button.style.color = "#f5f8fa"; // Default color
66+
} else {
67+
console.log("SFW mode enabled");
68+
button.style.color = "#5cff00"; // Active color
69+
}
70+
}
71+
72+
function sfwswitch_findstashcss() {
73+
for (let i = 0; i < document.styleSheets.length; i++) {
74+
const stylesheet = document.styleSheets[i];
75+
if (stylesheet.href && stylesheet.href.includes("/plugin/sfw_switch/css")) {
76+
return stylesheet;
77+
}
78+
}
79+
return null; // Return null if no matching stylesheet is found
80+
}
81+
82+
function waitForElementClass(elementId, callBack, time) {
83+
time = (typeof time !== 'undefined') ? time : 100;
84+
window.setTimeout(function () {
85+
var element = document.getElementsByClassName(elementId);
86+
if (element.length > 0) {
87+
callBack(elementId, element);
88+
} else {
89+
waitForElementClass(elementId, callBack);
90+
}
91+
}, time);
92+
}
93+
94+
sfwswitch_createbutton();

plugins/SFWSwitch/sfwswitch.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: SFW Switch
2+
description: Add a button to blur covers and images.
3+
url: https://discourse.stashapp.cc/t/sfw-switch/4657
4+
version: 1.1
5+
ui:
6+
javascript:
7+
- sfw.js
8+
css:
9+
- sfw.css

0 commit comments

Comments
 (0)