From d6dd674410dae0f0cca8ebc7980ca5a7c3752803 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 21:13:57 +0000 Subject: [PATCH 01/16] Added logic for three state toggles --- src/html/popup/popup.js | 32 +++++++++++++++++++++++++++++--- static/css/toggle.css | 8 ++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/html/popup/popup.js b/src/html/popup/popup.js index 92c97ed5..f1d7d4cb 100644 --- a/src/html/popup/popup.js +++ b/src/html/popup/popup.js @@ -118,7 +118,17 @@ async function setPopupDomElementValuesFromConfig(domElements) { manageDependents(domElements, domElements.shuffleOpenInNewTabOptionToggle, configSync.shuffleOpenInNewTabOption); // ----- Shuffling: Ignore shorts option toggle ----- - domElements.shuffleIgnoreShortsOptionToggle.checked = configSync.shuffleIgnoreShortsOption; + domElements.shuffleIgnoreShortsOptionToggle.dataset.checked = configSync.shuffleIgnoreShortsOption; + console.log(domElements.shuffleIgnoreShortsOptionToggle.dataset.checked); + if (domElements.shuffleIgnoreShortsOptionToggle.dataset.checked == 0) { + domElements.shuffleIgnoreShortsOptionToggle.indeterminate = false; + domElements.shuffleIgnoreShortsOptionToggle.checked = false; + } else if (domElements.shuffleIgnoreShortsOptionToggle.dataset.checked == 1) { + domElements.shuffleIgnoreShortsOptionToggle.indeterminate = true; + } else if (domElements.shuffleIgnoreShortsOptionToggle.dataset.checked == 2) { + domElements.shuffleIgnoreShortsOptionToggle.indeterminate = false; + domElements.shuffleIgnoreShortsOptionToggle.checked = true; + } // ----- Shuffling: Open as playlist option toggle ----- domElements.shuffleOpenAsPlaylistOptionToggle.checked = configSync.shuffleOpenAsPlaylistOption; @@ -205,8 +215,24 @@ async function setPopupDomElemenEventListeners(domElements) { }); // Shuffling: Ignore shorts option toggle - domElements.shuffleIgnoreShortsOptionToggle.addEventListener("change", async function () { - await setSyncStorageValue("shuffleIgnoreShortsOption", this.checked); + domElements.shuffleIgnoreShortsOptionToggle.addEventListener("click", async function () { + if (this.dataset.checked == 0) { + // unchecked, going indeterminate + this.dataset.checked = 1; + this.indeterminate = true; + } else if (this.dataset.checked == 1) { + // indeterminate, going checked + this.dataset.checked = 2; + this.indeterminate = false; + this.checked = true; + } else if (this.dataset.checked == 2) { + // checked, going unchecked + this.dataset.checked = 0; + this.indeterminate = false; + this.checked = false; + } + + await setSyncStorageValue("shuffleIgnoreShortsOption", this.dataset.checked); manageDependents(domElements, domElements.shuffleIgnoreShortsOptionToggle, this.checked); }); diff --git a/static/css/toggle.css b/static/css/toggle.css index 3bc88fad..0048debf 100644 --- a/static/css/toggle.css +++ b/static/css/toggle.css @@ -14,6 +14,14 @@ white-space: nowrap; width: 1px; } + +.toggle input:indeterminate + .slider { + background-color: orange; +} + +.toggle input:indeterminate + .slider::before { + transform: translateX(1em); +} .toggle .slider { position: absolute; From 3671d61b87732b7386870a8f4f52b2d39e128340 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 21:14:09 +0000 Subject: [PATCH 02/16] Updated description --- static/html/popup.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/html/popup.html b/static/html/popup.html index 57aa82b3..23d37984 100644 --- a/static/html/popup.html +++ b/static/html/popup.html @@ -45,8 +45,8 @@

General Video Settings

From 90ea68db9f51f193405fdea056023af9b4ef2784 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 21:14:14 +0000 Subject: [PATCH 03/16] Updated changelog --- CHANGELOG.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a964bfb1..2fbc48a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,16 @@ # Changelog -## v2.3.0 +## v2.4.0 (Unreleased) +- Added a new option to shuffle only from shorts. + + +## v2.3.0 + - Shuffling when excluding shorts is now a lot quicker if you have shuffled from the channel before, as the extension will remember which videos are shorts and skip them automatically. - Added an additional message to the shuffle button if shuffling takes a bit longer due to ignoring shorts. - Fixed a rare data inconsistency bug occurring with specific database values. - ## v2.2.4 From 5066ce8e690d1c9ee1405034542ed42ab5a29681 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 21:14:22 +0000 Subject: [PATCH 04/16] Updated data type --- src/config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/config.js b/src/config.js index 9d40ec79..6fb1afce 100644 --- a/src/config.js +++ b/src/config.js @@ -11,7 +11,8 @@ export const configSyncDefaults = { // These properties influence the behavior of the "Shuffle" button "shuffleOpenInNewTabOption": true, "shuffleReUseNewTabOption": true, - "shuffleIgnoreShortsOption": false, + // 0 = only shorts, 1 = no option set, 2 = ignore shorts + "shuffleIgnoreShortsOption": 1, "shuffleOpenAsPlaylistOption": true, // How many random videos to add to a playlist "shuffleNumVideosInPlaylist": 10, From 24f2f99c548de55da9dd1a3cf4f046e175cae742 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 21:17:08 +0000 Subject: [PATCH 05/16] Added migration logic --- src/background.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/background.js b/src/background.js index 936f5ec3..1c32afaf 100644 --- a/src/background.js +++ b/src/background.js @@ -95,6 +95,18 @@ async function handleVersionSpecificUpdates(previousVersion) { await chrome.storage.local.remove("youtubeAPIKey"); } } + + // v2.4.0 changed the data type for the shuffleIgnoreShortsOption from boolean to number + if (previousVersion < "2.4.0") { + console.log("Updating local storage to v2.4.0 format..."); + const localStorageContents = await chrome.storage.local.get(); + // Delete the youtubeAPIKey from local storage if it exists + if(localStorageContents["shuffleIgnoreShortsOption"] == true) { + await chrome.storage.local.set({"shuffleIgnoreShortsOption": 2}); + } else { + await chrome.storage.local.set({"shuffleIgnoreShortsOption": 1}); + } + } } // The shuffling page will open a port when it is started From a60983a74b3eaaf87842873cebf33a72b8d51c05 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 21:17:13 +0000 Subject: [PATCH 06/16] Updated text --- static/html/popup.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/html/popup.html b/static/html/popup.html index 23d37984..92003053 100644 --- a/static/html/popup.html +++ b/static/html/popup.html @@ -46,7 +46,7 @@

General Video Settings

From 5cbb77c55901b8f3ece2f7ef2c2c96e5284e8c6c Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 22:00:06 +0000 Subject: [PATCH 07/16] Fixed chrome startup handlers not running --- src/background.js | 59 ++++++++++++++++++++++------------------------- src/config.js | 2 ++ 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/background.js b/src/background.js index 1c32afaf..24ee75e1 100644 --- a/src/background.js +++ b/src/background.js @@ -3,8 +3,20 @@ import { configSync, setSyncStorageValue } from "./chromeStorage.js"; // ---------- Initialization/Chrome event listeners ---------- -// On Chrome startup, we make sure we are not using too much local storage -chrome.runtime.onStartup.addListener(async function () { + +// Check whether a new version was installed +async function initExtension() { + const manifestData = chrome.runtime.getManifest(); + if (configSync.previousVersion < manifestData.version) { + await handleExtensionUpdate(manifestData, configSync.previousVersion); + } + + checkLocalStorageCapacity(); +} +await initExtension(); + +// Make sure we are not using too much local storage +async function checkLocalStorageCapacity() { // If over 90% of the storage quota for playlists is used, remove playlists that have not been accessed in a long time const utilizedStorage = await chrome.storage.local.getBytesInUse(); const maxLocalStorage = chrome.storage.local.QUOTA_BYTES; @@ -32,25 +44,11 @@ chrome.runtime.onStartup.addListener(async function () { chrome.storage.local.remove(playlistId); } } -}); - -// Check whether a new version was installed -chrome.runtime.onInstalled.addListener(async function (details) { - const manifestData = chrome.runtime.getManifest(); - - if (details.reason == "update" && details.previousVersion !== manifestData.version) { - await handleExtensionUpdate(manifestData, details.previousVersion); - } else if (details.reason == "install") { - await handleExtensionInstall(manifestData); - } -}); - -async function handleExtensionInstall(manifestData) { - console.log(`Extension was installed (v${manifestData.version})`); } async function handleExtensionUpdate(manifestData, previousVersion) { console.log(`Extension was updated to version v${manifestData.version}`); + await setSyncStorageValue("previousVersion", manifestData.version); // Handle changes that may be specific to a certain version change await handleVersionSpecificUpdates(previousVersion); @@ -69,7 +67,18 @@ async function handleExtensionUpdate(manifestData, previousVersion) { } async function handleVersionSpecificUpdates(previousVersion) { - // v1.5.0 added renamed some keys in the channelSettings object + // v2.4.0 changed the data type for the shuffleIgnoreShortsOption from boolean to number + if (previousVersion < "2.4.0") { + console.log("Updating sync storage to v2.4.0 format..."); + const syncStorageContents = await chrome.storage.sync.get(); + if (syncStorageContents["shuffleIgnoreShortsOption"] == true) { + await setSyncStorageValue("shuffleIgnoreShortsOption", 2); + } else { + await setSyncStorageValue("shuffleIgnoreShortsOption", 1); + } + } + + // v1.5.0 renamed some keys in the channelSettings object if (previousVersion < "1.5.0") { console.log("Updating channelSettings to v1.5.0 format..."); @@ -83,7 +92,7 @@ async function handleVersionSpecificUpdates(previousVersion) { delete channelSetting["shufflePercentage"]; } } - await chrome.storage.sync.set(configSyncValues); + await setSyncStorageValue(configSyncValues); } // v1.3.0 removed the "youtubeAPIKey" key from local storage, which was replaced by the "youtubeAPIKeys" key @@ -95,18 +104,6 @@ async function handleVersionSpecificUpdates(previousVersion) { await chrome.storage.local.remove("youtubeAPIKey"); } } - - // v2.4.0 changed the data type for the shuffleIgnoreShortsOption from boolean to number - if (previousVersion < "2.4.0") { - console.log("Updating local storage to v2.4.0 format..."); - const localStorageContents = await chrome.storage.local.get(); - // Delete the youtubeAPIKey from local storage if it exists - if(localStorageContents["shuffleIgnoreShortsOption"] == true) { - await chrome.storage.local.set({"shuffleIgnoreShortsOption": 2}); - } else { - await chrome.storage.local.set({"shuffleIgnoreShortsOption": 1}); - } - } } // The shuffling page will open a port when it is started diff --git a/src/config.js b/src/config.js index 6fb1afce..753afe8d 100644 --- a/src/config.js +++ b/src/config.js @@ -35,6 +35,8 @@ export const configSyncDefaults = { "lastViewedChangelogVersion": "0", // For april fools: Will be the number of the year in which the user was last rickrolled (we only want to rickroll the user once per year) "wasLastRickRolledInYear": "1970", + // Used for updating the extension + "previousVersion": chrome.runtime.getManifest().version, }; export const shufflingHints = [ From 2f9a18a2031f45a5689d5f918319cf63f2e82669 Mon Sep 17 00:00:00 2001 From: NikkelM <57323886+NikkelM@users.noreply.github.com> Date: Sun, 5 Nov 2023 22:06:37 +0000 Subject: [PATCH 08/16] Change text according to option value --- src/html/popup/popup.js | 10 +- static/html/popup.html | 413 ++++++++++++++++++++-------------------- 2 files changed, 219 insertions(+), 204 deletions(-) diff --git a/src/html/popup/popup.js b/src/html/popup/popup.js index f1d7d4cb..90b4dea6 100644 --- a/src/html/popup/popup.js +++ b/src/html/popup/popup.js @@ -35,7 +35,8 @@ function getPopupDomElements() { shuffleOpenInNewTabOptionToggle: document.getElementById("shuffleOpenInNewTabOptionToggle"), // Shuffling: Reuse tab option toggle shuffleReUseNewTabOptionToggle: document.getElementById("shuffleReUseNewTabOptionToggle"), - // Shuffling : Ignore shorts option toggle + // Shuffling : Ignore shorts option (toggle) + shuffleIgnoreShortsOptionTextLabel: document.getElementById("shuffleIgnoreShortsOptionTextLabel"), shuffleIgnoreShortsOptionToggle: document.getElementById("shuffleIgnoreShortsOptionToggle"), // Shuffling: Open as playlist option toggle shuffleOpenAsPlaylistOptionToggle: document.getElementById("shuffleOpenAsPlaylistOptionToggle"), @@ -119,13 +120,15 @@ async function setPopupDomElementValuesFromConfig(domElements) { // ----- Shuffling: Ignore shorts option toggle ----- domElements.shuffleIgnoreShortsOptionToggle.dataset.checked = configSync.shuffleIgnoreShortsOption; - console.log(domElements.shuffleIgnoreShortsOptionToggle.dataset.checked); if (domElements.shuffleIgnoreShortsOptionToggle.dataset.checked == 0) { + domElements.shuffleIgnoreShortsOptionTextLabel.textContent = "Only shorts"; domElements.shuffleIgnoreShortsOptionToggle.indeterminate = false; domElements.shuffleIgnoreShortsOptionToggle.checked = false; } else if (domElements.shuffleIgnoreShortsOptionToggle.dataset.checked == 1) { + domElements.shuffleIgnoreShortsOptionTextLabel.textContent = "Shorts handling"; domElements.shuffleIgnoreShortsOptionToggle.indeterminate = true; } else if (domElements.shuffleIgnoreShortsOptionToggle.dataset.checked == 2) { + domElements.shuffleIgnoreShortsOptionTextLabel.textContent = "Ignore Shorts"; domElements.shuffleIgnoreShortsOptionToggle.indeterminate = false; domElements.shuffleIgnoreShortsOptionToggle.checked = true; } @@ -218,15 +221,18 @@ async function setPopupDomElemenEventListeners(domElements) { domElements.shuffleIgnoreShortsOptionToggle.addEventListener("click", async function () { if (this.dataset.checked == 0) { // unchecked, going indeterminate + domElements.shuffleIgnoreShortsOptionTextLabel.textContent = "Shorts handling"; this.dataset.checked = 1; this.indeterminate = true; } else if (this.dataset.checked == 1) { // indeterminate, going checked + domElements.shuffleIgnoreShortsOptionTextLabel.textContent = "Ignore Shorts"; this.dataset.checked = 2; this.indeterminate = false; this.checked = true; } else if (this.dataset.checked == 2) { // checked, going unchecked + domElements.shuffleIgnoreShortsOptionTextLabel.textContent = "Only shorts"; this.dataset.checked = 0; this.indeterminate = false; this.checked = false; diff --git a/static/html/popup.html b/static/html/popup.html index 92003053..c1558436 100644 --- a/static/html/popup.html +++ b/static/html/popup.html @@ -1,220 +1,229 @@ + + Random YouTube Video + + + + + + + +
+

Random YouTube Video

+ + + +

Hover over an option to view a more detailed explanation.

+ +

General Video Settings

+ +
+ +
+ +
- - Random YouTube Video - - - - - - - -
- -

Random YouTube Video

- - - -

Hover over an option to view a more detailed explanation.

- -

General Video Settings

- -
- - -
- -
- - -
- -
- - -
- -
- -
- - - -
+ +
+ +
- -
- + +
+ +
+ + + +
+ +
+ +
- -
-

Videos in playlist:

- + +
+

Videos in playlist:

+ +
- -
- - - -
-