Skip to content

Commit

Permalink
feat: add support to decide if fullscreen ignores all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
drodil committed Sep 18, 2024
1 parent ae5d3b6 commit 6d74141
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion chrome/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ <h4>Settings</h4>
<label><input type="checkbox" id="scrollpause"><span class="label-text">Enable auto pause when out of viewport</span></label>
<label><input type="checkbox" id="cursorTracking"><span class="label-text">Enable cursor on window tracking</span></label>
<label><input type="checkbox" id="manualPause"><span class="label-text">Manual pause disables auto resume</span></label>
<label><input type="checkbox" id="disabled"><span class="label-text">Disable auto pause/resume</span></label>
<label><input type="checkbox" id="disableOnFullscreen"><span class="label-text">Disable on full screen</span></label>
<label><input type="checkbox" id="disabled"><span class="label-text">Disable extension</span></label>
</div>
<hr>
<div class="container">
Expand Down
1 change: 1 addition & 0 deletions chrome/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const options = {
cursorTracking: false,
manualPause: true,
debugMode: false,
disableOnFullscreen: false,
};

const hosts = chrome.runtime.getManifest().host_permissions;
Expand Down
2 changes: 2 additions & 0 deletions chrome/yt.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let options = {
disabled: false,
cursorTracking: false,
debugMode: false,
disableOnFullscreen: false,
};

const hosts = chrome.runtime.getManifest().host_permissions;
Expand All @@ -41,6 +42,7 @@ function refresh_settings() {
options.focusresume = false;
options.cursorTracking = false;
options.debugMode = false;
options.disableOnFullscreen = true;
for (var host of hosts) {
options[host] = false;
}
Expand Down
12 changes: 7 additions & 5 deletions chrome/yt_auto_pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (window.ytAutoPauseInjected !== true) {
cursorTracking: false,
manualPause: true,
debugMode: false,
disableOnFullscreen: false,
};

function debugLog(message) {
Expand All @@ -39,6 +40,7 @@ if (window.ytAutoPauseInjected !== true) {
options.focusresume = false;
options.cursorTracking = false;
options.debugMode = false;
options.disableOnFullscreen = true;
for (var host of hosts) {
options[host] = false;
}
Expand Down Expand Up @@ -145,6 +147,11 @@ if (window.ytAutoPauseInjected !== true) {
}
debugLog(`Received message: ${JSON.stringify(request)}`);

if (document.fullscreenElement && options.disableOnFullscreen) {
debugLog(`Document is in fullscreen mode, ignoring all commands`);
return true;
}

const videoElements = document.getElementsByTagName("video");
const iframeElements = document.getElementsByTagName("iframe");

Expand All @@ -169,11 +176,6 @@ if (window.ytAutoPauseInjected !== true) {

for (let i = 0; i < videoElements.length; i++) {
try {
if (document.fullscreenElement) {
debugLog(`Document is in fullscreen mode, ignoring all commands`);
break;
}

if (request.action === "stop" && !manuallyPaused) {
automaticallyPaused = true;
videoElements[i].pause();
Expand Down
3 changes: 2 additions & 1 deletion firefox/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ <h4>Settings</h4>
<label><input type="checkbox" id="scrollpause"><span class="label-text">Enable auto pause when out of viewport</span></label>
<label><input type="checkbox" id="cursorTracking"><span class="label-text">Enable cursor on window tracking</span></label>
<label><input type="checkbox" id="manualPause"><span class="label-text">Manual pause disables auto resume</span></label>
<label><input type="checkbox" id="disabled"><span class="label-text">Disable auto pause/resume</span></label>
<label><input type="checkbox" id="disableOnFullscreen"><span class="label-text">Disable on full screen</span></label>
<label><input type="checkbox" id="disabled"><span class="label-text">Disable extension</span></label>
</div>
<hr>
<div class="container">
Expand Down
1 change: 1 addition & 0 deletions firefox/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const options = {
cursorTracking: false,
manualPause: true,
debugMode: false,
disableOnFullscreen: false,
};

const hosts = browser.runtime.getManifest().host_permissions;
Expand Down
2 changes: 2 additions & 0 deletions firefox/yt.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ let options = {
disabled: false,
cursorTracking: false,
debugMode: false,
disableOnFullscreen: false,
};

const hosts = browser.runtime.getManifest().host_permissions;
Expand All @@ -43,6 +44,7 @@ function refresh_settings() {
options.focusresume = false;
options.cursorTracking = false;
options.debugMode = false;
options.disableOnFullscreen = true;
for (var host of hosts) {
options[host] = false;
}
Expand Down
7 changes: 7 additions & 0 deletions firefox/yt_auto_pause.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if (window.ytAutoPauseInjected !== true) {
cursorTracking: false,
manualPause: true,
debugMode: false,
disableOnFullscreen: false,
};

function debugLog(message) {
Expand All @@ -39,6 +40,7 @@ if (window.ytAutoPauseInjected !== true) {
options.focusresume = false;
options.cursorTracking = false;
options.debugMode = false;
options.disableOnFullscreen = true;
for (var host of hosts) {
options[host] = false;
}
Expand Down Expand Up @@ -143,7 +145,12 @@ if (window.ytAutoPauseInjected !== true) {
if (!("action" in request)) {
return false;
}

debugLog(`Received message: ${JSON.stringify(request)}`);
if (document.fullscreenElement && options.disableOnFullscreen) {
debugLog(`Document is in fullscreen mode, ignoring all commands`);
return true;
}

const videoElements = document.getElementsByTagName("video");
const iframeElements = document.getElementsByTagName("iframe");
Expand Down

0 comments on commit 6d74141

Please sign in to comment.