Add configurable skip delay (0-30s) for Skip Intro and Skip Credits

This commit is contained in:
justin committed 2026-09-02 16:50:04 -07:00
1 parent 0f1f2a309e
commit b2082d0624
9 files changed
+333 -21

No files matched your search

+48 -11
View File
@@ -1,6 +1,6 @@
(function () {
let settings = DEFAULT_SETTINGS;
const recentClicks = new WeakMap();
const elementState = new WeakMap();
const CLICK_COOLDOWN_MS = 1500;
function isSkipIntroButton(text) {
@@ -16,11 +16,48 @@
return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
}
function canClick(el) {
const last = recentClicks.get(el);
if (last && Date.now() - last < CLICK_COOLDOWN_MS) return false;
recentClicks.set(el, Date.now());
return true;
function getDelayMs(type) {
const seconds = type === "intro" ? settings.introDelaySeconds : settings.creditsDelaySeconds;
return clampDelaySeconds(seconds) * 1000;
}
function isStillEligible(el, type) {
if (!document.body.contains(el)) return false;
if (!isVisible(el)) return false;
if (type === "intro" && !settings.skipIntro) return false;
if (type === "credits" && !settings.skipCredits) return false;
if (!hostMatchesConfig(window.location.hostname, settings.plexUrl)) return false;
const text = (el.innerText || el.textContent || "").trim().toLowerCase();
return type === "intro" ? isSkipIntroButton(text) : isSkipCreditsButton(text);
}
function performClick(el) {
const state = elementState.get(el) || {};
state.timer = null;
state.lastClickAt = Date.now();
elementState.set(el, state);
el.click();
}
function scheduleClick(el, type) {
const state = elementState.get(el) || {};
if (state.timer) return;
if (state.lastClickAt && Date.now() - state.lastClickAt < CLICK_COOLDOWN_MS) return;
const delayMs = getDelayMs(type);
if (delayMs <= 0) {
performClick(el);
return;
}
state.timer = setTimeout(() => {
const current = elementState.get(el) || {};
current.timer = null;
elementState.set(el, current);
if (isStillEligible(el, type)) performClick(el);
}, delayMs);
elementState.set(el, state);
}
function scanAndClick() {
@@ -33,11 +70,11 @@
if (!text) return;
if (!isVisible(el)) return;
const wantsIntroSkip = settings.skipIntro && isSkipIntroButton(text);
const wantsCreditsSkip = settings.skipCredits && isSkipCreditsButton(text);
if (!wantsIntroSkip && !wantsCreditsSkip) return;
if (canClick(el)) el.click();
if (settings.skipIntro && isSkipIntroButton(text)) {
scheduleClick(el, "intro");
} else if (settings.skipCredits && isSkipCreditsButton(text)) {
scheduleClick(el, "credits");
}
});
}