Add an option to disable autoplay for playlists

This commit is contained in:
Lawrence Hook
2022-11-06 17:56:29 -05:00
parent 1158752c96
commit 8383bfa313
3 changed files with 38 additions and 8 deletions
+6
View File
@@ -134,6 +134,11 @@ const SECTIONS = [
id: "disable_autoplay",
defaultValue: true
},
{
name: "Disable autoplay for playlists",
id: "disable_playlist_autoplay",
defaultValue: true
},
{
name: "Redirect shorts to the default viewer",
tags: "Redirects, Basic",
@@ -381,6 +386,7 @@ browser.runtime.onMessage.addListener((data, sender) => {
const { frameId, tab } = sender;
browser.storage.local.get(localSettings => {
const settings = { ...DEFAULT_SETTINGS, ...localSettings };
browser.tabs.sendMessage(tab.id, { settings }, {});
// Gray out browserAction
+31 -7
View File
@@ -56,11 +56,9 @@ document.addEventListener("DOMContentLoaded", event => {
counter = 0;
theaterClicked = false;
hyper = false;
originalPlayback = undefined;
originalMuted = undefined;
onResultsPage = resultsPageRegex.test(location.href);
requestRunDynamicSettings()
handleNewPage();
});
// let lastRun = Date.now();
@@ -83,10 +81,8 @@ function runDynamicSettings() {
url = location.href;
theaterClicked = false;
hyper = false;
originalPlayback = undefined;
originalMuted = undefined;
onResultsPage = resultsPageRegex.test(location.href);
handleUrlChange();
handleNewPage();
}
// Mark the left nav bar sections
@@ -246,7 +242,34 @@ function runDynamicSettings() {
}
function handleUrlChange() {
function injectScripts() {
// Disable playlist autoplay
if (cache['disable_playlist_autoplay']) {
const existingScript = document.querySelector('script[id="disable_playlist_autoplay"]')
if (existingScript) return;
const script = document.createElement("script");
script.id = 'disable_playlist_autoplay';
script.type = "text/javascript";
script.innerText = `
(function() {
let pm;
function f() {
if (!pm) pm = document.querySelector('yt-playlist-manager');
if (pm) pm.canAutoAdvance_ = false;
}
f();
setInterval(f, 100);
})()
`;
document.body?.appendChild(script);
}
}
function handleNewPage() {
if (cache['global_enable'] !== true) return;
dynamicIters = 0;
@@ -275,6 +298,7 @@ function handleUrlChange() {
location.replace(newUrl);
}
injectScripts();
requestRunDynamicSettings();
}
+1 -1
View File
@@ -3,7 +3,7 @@
"description": "Spend less time on YouTube. Customize YouTube's user interface to be less engaging.",
"homepage_url": "https://github.com/lawrencehook/remove-youtube-suggestions",
"manifest_version": 2,
"version": "4.3.14",
"version": "4.3.15",
"icons": {
"16": "images/16.png",