diff --git a/plugins/SFWSwitch/README.md b/plugins/SFWSwitch/README.md index 02cb3507..8ea57374 100644 --- a/plugins/SFWSwitch/README.md +++ b/plugins/SFWSwitch/README.md @@ -9,8 +9,10 @@ https://discourse.stashapp.cc/t/sfw-switch/4658 - Gray = Blur disabled - Toggling the button blurs cover images and other content. - Hovering over an image temporarily removes the blur. +- Optional toggle to also mute audio from scenes. +- Optional toggle to not remove the blur on thumbnail hover. - Extends the blurring functionality to some community plugins. - - Custom selectors should should be added to `additional_plugins.css` file. + - Custom selectors should be added to `additional_plugins.css` file. ## Screenshots diff --git a/plugins/SFWSwitch/sfw.js b/plugins/SFWSwitch/sfw.js index fc18e571..e7332b84 100644 --- a/plugins/SFWSwitch/sfw.js +++ b/plugins/SFWSwitch/sfw.js @@ -1,6 +1,6 @@ let sfw_mediaObserver = null; let sfw_playListener = null; -let sfw_extraListeners = null; +let sfw_extraListeners = null; async function getSfwConfig() { try { @@ -17,10 +17,10 @@ async function getSfwConfig() { }); const result = await response.json(); const pluginSettings = result.data.configuration.plugins.sfwswitch; - return pluginSettings?.audio_setting === true; + return { audioMute: pluginSettings?.audio_setting === true, neverUnblur: pluginSettings?.never_unblur === true }; } catch (e) { console.error("SFW Switch: Could not fetch config", e); - return false; + return { audioMute: false, neverUnblur: false }; } } @@ -30,9 +30,10 @@ async function sfw_mode() { if (!stash_css) return; const rawState = localStorage.getItem("sfw_mode"); const sfwState = rawState === "true"; - const audioMuteEnabled = await getSfwConfig(); + const { audioMute: audioMuteEnabled, neverUnblur } = await getSfwConfig(); stash_css.disabled = !sfwState; + sfw_apply_never_unblur(sfwState && neverUnblur); if (sfwState && audioMuteEnabled) { sfw_mute_all_media(); @@ -141,7 +142,8 @@ async function sfwswitch_switcher() { localStorage.setItem("sfw_mode", enabled); - const audioMuteEnabled = await getSfwConfig(); + const { audioMute: audioMuteEnabled, neverUnblur } = await getSfwConfig(); + sfw_apply_never_unblur(enabled && neverUnblur); if (enabled && audioMuteEnabled) { sfw_mute_all_media(); @@ -161,6 +163,33 @@ async function sfwswitch_switcher() { } } +function sfw_apply_never_unblur(enabled) { + const existing = document.getElementById("sfw-never-unblur"); + if (enabled && !existing) { + let css = ""; + for (let s = 0; s < document.styleSheets.length; s++) { + const sheet = document.styleSheets[s]; + try { + if (!sheet.href || !sheet.href.includes("/plugin/sfwswitch/css")) continue; + for (let i = 0; i < sheet.cssRules.length; i++) { + const rule = sheet.cssRules[i]; + if (rule instanceof CSSStyleRule && !rule.selectorText.includes(":hover")) { + css += `${rule.selectorText}{filter:${rule.style.filter}!important}`; + } + } + } catch (e) {} + } + if (css) { + const style = document.createElement("style"); + style.id = "sfw-never-unblur"; + style.textContent = css; + document.head.appendChild(style); + } + } else if (!enabled && existing) { + existing.remove(); + } +} + function sfwswitch_findstashcss() { for (let i = 0; i < document.styleSheets.length; i++) { const sheet = document.styleSheets[i]; diff --git a/plugins/SFWSwitch/sfwswitch.yml b/plugins/SFWSwitch/sfwswitch.yml index 59b8dc61..67f7d528 100644 --- a/plugins/SFWSwitch/sfwswitch.yml +++ b/plugins/SFWSwitch/sfwswitch.yml @@ -1,6 +1,6 @@ name: SFW Switch -description: Add a button to blur covers and images. -version: 1.8 +description: Add a button to the menu bar to blur images, text and optionally mute audio. +version: 1.9 url: https://discourse.stashapp.cc/t/sfw-switch/4658 ui: javascript: @@ -12,4 +12,8 @@ settings: audio_setting: displayName: Enable Sound Mute description: By default the plugin does not mute sound. Enabling this feature will have sound sources included when the SFW button is enabled. - type: BOOLEAN \ No newline at end of file + type: BOOLEAN + never_unblur: + displayName: Never Unblur on Hover + description: Keep images blurred even when hovered. + type: BOOLEAN