Skip to content

Commit 612e9ff

Browse files
authored
Merge branch 'main' into main
2 parents 5ad5f71 + 44e631f commit 612e9ff

5 files changed

Lines changed: 199 additions & 109 deletions

File tree

plugins/SFWSwitch/additional_plugins.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
.pwr-hover-preview,
1111
.pwr-scene-image-container .pwr-scene-image,
1212

13-
/* HotOrNot */
13+
/* Ascension */
1414
.hon-performer-image,
1515
.hon-performer-card,
1616
.hon-scene-image,
1717
.hon-selection-image,
1818
.hon-image-image-container,
1919
.hon-image-image,
20+
.hon-victory-image,
2021

2122
/* Deck Viewer */
2223
.swiper-zoom-container,
@@ -68,7 +69,7 @@
6869
.pwr-scene-image-container:hover .pwr-scene-image,
6970
.pwr-scene-info:hover,
7071

71-
/* HotOrNot */
72+
/* Ascension */
7273
.hon-performer-image:hover,
7374
.hon-performer-card:hover,
7475
.hon-scene-image:hover,
@@ -78,6 +79,7 @@
7879
.hon-selection-card:hover,
7980
.hon-selection-name:hover,
8081
.hon-selection-image:hover,
82+
.hon-victory-image:hover,
8183

8284
/* Sprite Tab */
8385
.sprite-cell:hover,

plugins/SFWSwitch/sfw.js

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ async function getSfwConfig() {
2323
return false;
2424
}
2525
}
26+
2627
async function sfw_mode() {
2728
const stash_css = sfwswitch_findstashcss();
2829
const button = document.getElementById("plugin_sfw");
29-
3030
if (!stash_css) return;
31-
32-
const sfwState = localStorage.getItem("sfw_mode") === "true";
31+
const rawState = localStorage.getItem("sfw_mode");
32+
const sfwState = rawState === "true";
3333
const audioMuteEnabled = await getSfwConfig();
3434

3535
stash_css.disabled = !sfwState;
@@ -69,25 +69,21 @@ function sfwswitch_createbutton() {
6969

7070
document.getElementById(buttonId).addEventListener("click", sfwswitch_switcher);
7171

72-
// Initialize the button based on saved state
7372
sfw_mode();
7473
}
7574
}, 100);
7675

7776
setTimeout(() => clearInterval(intervalId), 10000);
7877
}
7978

80-
// Function to strictly handle the muted state
8179
function sfw_forceMute(media) {
8280
if (!media) return;
8381
media.muted = true;
8482
}
8583

8684
function sfw_mute_all_media() {
87-
// Initial sweep
8885
document.querySelectorAll("audio, video").forEach(sfw_forceMute);
8986

90-
// Global event listener for play, seek, and volume changes
9187
if (!sfw_playListener) {
9288
sfw_playListener = function(e) {
9389
if (e.target.tagName === "VIDEO" || e.target.tagName === "AUDIO") {
@@ -101,7 +97,6 @@ function sfw_mute_all_media() {
10197
document.addEventListener("seeking", sfw_playListener, true);
10298
}
10399

104-
// MutationObserver for content loaded via AJAX/Dynamic updates
105100
if (!sfw_mediaObserver) {
106101
sfw_mediaObserver = new MutationObserver(mutations => {
107102
for (const mutation of mutations) {
@@ -119,7 +114,6 @@ function sfw_mute_all_media() {
119114
}
120115

121116
function sfw_unmute_all_media() {
122-
// 1. Remove listeners FIRST to prevent them from firing during the unmute loop
123117
if (sfw_playListener) {
124118
document.removeEventListener("play", sfw_playListener, true);
125119
document.removeEventListener("volumechange", sfw_playListener, true);
@@ -133,36 +127,29 @@ function sfw_unmute_all_media() {
133127
sfw_mediaObserver = null;
134128
}
135129

136-
// 2. Unmute existing media
137130
document.querySelectorAll("audio, video").forEach(media => {
138131
media.muted = false;
139-
// Optional: media.volume = 1.0; // Use if volume was also forced to 0
140132
});
141133
}
142134

143135
async function sfwswitch_switcher() {
144136
const stash_css = sfwswitch_findstashcss();
145137
if (!stash_css) return;
146138

147-
// Toggle the CSS
148139
stash_css.disabled = !stash_css.disabled;
149140
const enabled = !stash_css.disabled;
150141

151142
localStorage.setItem("sfw_mode", enabled);
152143

153144
const audioMuteEnabled = await getSfwConfig();
154145

155-
// Logic Check: If we just disabled SFW, we MUST run unmute immediately
156146
if (enabled && audioMuteEnabled) {
157147
sfw_mute_all_media();
158148
} else {
159-
// This clears observers and sets muted = false
160149
sfw_unmute_all_media();
161150

162-
// CRITICAL: Force a pause/reset on any media that might be stuck in a background buffer
163151
document.querySelectorAll("audio, video").forEach(media => {
164152
if (media.paused && media.muted) {
165-
// If it was supposed to be stopped, make sure it stays stopped
166153
media.muted = false;
167154
}
168155
});
@@ -176,13 +163,41 @@ async function sfwswitch_switcher() {
176163

177164
function sfwswitch_findstashcss() {
178165
for (let i = 0; i < document.styleSheets.length; i++) {
179-
const stylesheet = document.styleSheets[i];
180-
if (stylesheet.href && stylesheet.href.includes("/plugin/sfwswitch/css")) {
181-
return stylesheet;
166+
const sheet = document.styleSheets[i];
167+
try {
168+
if (sheet.href && sheet.href.includes("/plugin/sfwswitch/css")) {
169+
return sheet;
170+
}
171+
} catch (e) {
172+
// Cross-origin access blocked - skip
182173
}
183174
}
184175
return null;
185176
}
186177

187-
// Initialize button on page load
188-
sfwswitch_createbutton();
178+
async function sfw_init() {
179+
// Wait until the stylesheet is available
180+
let retries = 0;
181+
const maxRetries = 50; // ~5 seconds with 100ms delay
182+
183+
while (!sfwswitch_findstashcss() && retries < maxRetries) {
184+
await new Promise(r => setTimeout(r, 100));
185+
retries++;
186+
}
187+
188+
if (!document.getElementById("plugin_sfw")) {
189+
sfwswitch_createbutton();
190+
}
191+
}
192+
193+
function sfw_start() {
194+
setTimeout(() => {
195+
sfw_init();
196+
}, 0);
197+
}
198+
199+
if (document.readyState === "loading") {
200+
window.addEventListener("DOMContentLoaded", sfw_start);
201+
} else {
202+
sfw_start();
203+
}

plugins/SFWSwitch/sfwswitch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: SFW Switch
22
description: Add a button to blur covers and images.
3-
version: 1.7
3+
version: 1.8
44
url: https://discourse.stashapp.cc/t/sfw-switch/4658
55
ui:
66
javascript:

0 commit comments

Comments
 (0)