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
7 changes: 7 additions & 0 deletions plugins/SFWSwitch/additional_plugins.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

/* O Stats */
.custom-stats-row .stats-element img,
#on-this-day-section [style*="position: relative; height: 400px"],

/* Sprite Tab */
.sprite-cell
#on-this-day-section [style*="position: relative; height: 400px"]
{
filter: blur(30px);
Expand Down Expand Up @@ -53,6 +57,9 @@ filter: blur(2px);
.hon-image-image:hover,
.hon-performer-info.hon-scene-info:hover,

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

/* O Stats */
.custom-stats-row .stats-element:hover,
.custom-stats-row .stats-element:hover img,
Expand Down
94 changes: 87 additions & 7 deletions plugins/SFWSwitch/sfw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
let sfw_mediaObserver = null;
let sfw_playListener = null;

function sfw_mode() {
const stash_css = sfwswitch_findstashcss();
const button = document.getElementById("plugin_sfw");
Expand All @@ -6,10 +9,14 @@ function sfw_mode() {

const sfwState = localStorage.getItem("sfw_mode") === "true";

// Apply saved state to the stylesheet
stash_css.disabled = !sfwState;

// Update button color
if (sfwState) {
sfw_mute_all_media();
} else {
sfw_unmute_all_media();
}

button.style.color = sfwState ? "#5cff00" : "#f5f8fa";
}

Expand Down Expand Up @@ -45,22 +52,95 @@ function sfwswitch_createbutton() {
setTimeout(() => clearInterval(intervalId), 10000);
}

function sfw_forceMute(media) {
media.muted = true;
media.defaultMuted = true;
media.volume = 0;
}

function sfw_mute_all_media() {

// Mute existing media
document.querySelectorAll("audio, video").forEach(sfw_forceMute);

// Mute media when it starts playing
if (!sfw_playListener) {
sfw_playListener = function(e) {
if (e.target.tagName === "VIDEO" || e.target.tagName === "AUDIO") {
sfw_forceMute(e.target);
}
};

document.addEventListener("play", sfw_playListener, true);
}

// Watch for new media nodes
if (!sfw_mediaObserver) {

sfw_mediaObserver = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {

if (node.tagName === "VIDEO" || node.tagName === "AUDIO") {
sfw_forceMute(node);
}

if (node.querySelectorAll) {
node.querySelectorAll("video, audio").forEach(sfw_forceMute);
}

});
});
});

sfw_mediaObserver.observe(document.body, {
childList: true,
subtree: true
});
}
}

function sfw_unmute_all_media() {

document.querySelectorAll("audio, video").forEach(media => {
media.muted = false;
media.volume = 1;
});

if (sfw_mediaObserver) {
sfw_mediaObserver.disconnect();
sfw_mediaObserver = null;
}

if (sfw_playListener) {
document.removeEventListener("play", sfw_playListener, true);
sfw_playListener = null;
}
}

function sfwswitch_switcher() {
const stash_css = sfwswitch_findstashcss();
if (!stash_css) {
console.error("SFW stylesheet not found.");
return;
}

// Toggle stylesheet
stash_css.disabled = !stash_css.disabled;

// Save new state to localStorage
localStorage.setItem("sfw_mode", !stash_css.disabled);
const enabled = !stash_css.disabled;

localStorage.setItem("sfw_mode", enabled);

if (enabled) {
sfw_mute_all_media();
} else {
sfw_unmute_all_media();
}

const button = document.getElementById("plugin_sfw");
button.style.color = stash_css.disabled ? "#f5f8fa" : "#5cff00";
console.log(`SFW mode ${stash_css.disabled ? "disabled" : "enabled"}`);
button.style.color = enabled ? "#5cff00" : "#f5f8fa";

console.log(`SFW mode ${enabled ? "enabled" : "disabled"}`);
}

function sfwswitch_findstashcss() {
Expand Down
2 changes: 1 addition & 1 deletion plugins/SFWSwitch/sfwswitch.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SFW Switch
description: Add a button to blur covers and images.
version: 1.4
version: 1.5
url: https://discourse.stashapp.cc/t/sfw-switch/4658
ui:
javascript:
Expand Down