Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions plugins/SFWSwitch/sfw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let sfw_mediaObserver = null;
let sfw_playListener = null;
let sfw_extraListeners = null;
let sfw_extraListeners = null;

async function getSfwConfig() {
try {
Expand All @@ -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 };
}
}

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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];
Expand Down
6 changes: 5 additions & 1 deletion plugins/SFWSwitch/sfwswitch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
type: BOOLEAN
never_unblur:
displayName: Never Unblur on Hover
description: Keep images blurred even when hovered.
type: BOOLEAN
Loading