From 50002cfbbdf4deda207e81cd0d1827ec2b414891 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Mon, 9 Mar 2020 23:10:59 -0400 Subject: [PATCH 1/7] Fix github token using the wrong key in release workflow --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dae30ed1..7765c18f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,11 +68,11 @@ jobs: with: args: builds/ChromeExtension.zip env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Upload to release uses: Shopify/upload-to-release@master with: args: builds/FirefoxExtension.zip env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + repo-token: ${{ secrets.GITHUB_TOKEN }} From 2ec47d52cd03028bda8a047699ab6f040be118c4 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 10 Mar 2020 00:33:50 -0400 Subject: [PATCH 2/7] Added basic options import/export --- public/_locales/en/messages.json | 15 ++++++++++++ public/options/options.html | 26 ++++++++++++++++++++ src/options.ts | 41 +++++++++++++++++++++++++++++--- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json index b49c0bce..2dc611f5 100644 --- a/public/_locales/en/messages.json +++ b/public/_locales/en/messages.json @@ -425,5 +425,20 @@ }, "mobileUpdateInfo": { "message": "m.youtube.com is now supported" + }, + "exportOptions": { + "message": "Import/Export All Options" + }, + "whatExportOptions": { + "message": "This is your entire configuration in JSON. This includes your userID, so be sure to share this wisely." + }, + "setOptions": { + "message": "Set Options" + }, + "exportOptionsWarning": { + "message": "Warning: Changing the options is permanent and can break your install. Are you sure you would like to do this? Make sure to backup your old one just in case." + }, + "incorrectlyFormattedOptions": { + "message": "This JSON is not formatted correctly. Your options have not been changed." } } diff --git a/public/options/options.html b/public/options/options.html index 72916c3a..37139c31 100644 --- a/public/options/options.html +++ b/public/options/options.html @@ -305,6 +305,32 @@ +
+
+ +
+
+ __MSG_exportOptions__ +
+ +
+ +
__MSG_whatExportOptions__
+ + +
+

diff --git a/src/options.ts b/src/options.ts index 1836c6c3..466a57e6 100644 --- a/src/options.ts +++ b/src/options.ts @@ -345,15 +345,50 @@ function activatePrivateTextChange(element: HTMLElement) { element.querySelector(".option-hidden-section").classList.remove("hidden"); return; } - - textBox.value = Config.config[option]; + + let result = Config.config[option]; + + // See if anything extra must be done + switch (option) { + case "*": + result = JSON.stringify(Config.localConfig); + break; + } + + textBox.value = result; let setButton = element.querySelector(".text-change-set"); setButton.addEventListener("click", () => { let confirmMessage = element.getAttribute("confirm-message"); if (confirmMessage === null || confirm(chrome.i18n.getMessage(confirmMessage))) { - Config.config[option] = textBox.value; + + // See if anything extra must be done + switch (option) { + case "*": + try { + let newConfig = JSON.parse(textBox.value); + for (const key in newConfig) { + Config.config[key] = newConfig[key]; + } + + init(); + + if (newConfig.supportInvidious) { + let checkbox = document.querySelector("#support-invidious > label > label > input"); + + checkbox.checked = true; + invidiousOnClick(checkbox, "supportInvidious"); + } + + } catch (e) { + alert(chrome.i18n.getMessage("incorrectlyFormattedOptions")); + } + + break; + default: + Config.config[option] = textBox.value; + } } }); From f0bf0512590f748b6492396404b23783ab17e26c Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 10 Mar 2020 00:48:53 -0400 Subject: [PATCH 3/7] Properly ask for permissions when changing the server address --- src/options.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/options.ts b/src/options.ts index 466a57e6..27739702 100644 --- a/src/options.ts +++ b/src/options.ts @@ -72,7 +72,7 @@ async function init() { textChangeInput.value = Config.config[textChangeOption]; - textChangeSetButton.addEventListener("click", () => { + textChangeSetButton.addEventListener("click", async () => { // See if anything extra must be done switch (textChangeOption) { case "serverAddress": @@ -84,6 +84,18 @@ async function init() { return; } + // Permission needed on Firefox + if (utils.isFirefox()) { + let permissionSuccess = await new Promise((resolve, reject) => { + chrome.permissions.request({ + origins: [textChangeInput.value + "/"], + permissions: [] + }, resolve); + }); + + if (!permissionSuccess) return; + } + break; } From 030256c9e1e38215c90002046371a51fc2614577 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 10 Mar 2020 02:14:00 -0400 Subject: [PATCH 4/7] Enable checkbox when the permission prompt is successful --- src/options.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/options.ts b/src/options.ts index 27739702..de804cde 100644 --- a/src/options.ts +++ b/src/options.ts @@ -271,6 +271,8 @@ function invidiousOnClick(checkbox: HTMLInputElement, option: string) { if (!granted) { Config.config[option] = false; checkbox.checked = false; + } else { + checkbox.checked = true; } }); } else { @@ -428,4 +430,4 @@ function validateServerAddress(input: string): string { } return input; -} \ No newline at end of file +} From 191e9ceb6f4f71d149187f82d70414133d43086d Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 10 Mar 2020 23:22:17 -0400 Subject: [PATCH 5/7] Makes sure the playing and play listener both don't get called at the same time. This led to double notices. --- src/content.ts | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/content.ts b/src/content.ts index 37212201..7430bcd1 100644 --- a/src/content.ts +++ b/src/content.ts @@ -45,7 +45,12 @@ var lastPreviewBarUpdate; var durationListenerSetUp = false; // Is the video currently being switched -var switchingVideos = false; +var switchingVideos = null; + +// Used by the play and playing listeners to make sure two aren't +// called at the same time +var lastCheckTime = 0; +var lastCheckVideoTime = -1; //the channel this video is about var channelURL; @@ -238,6 +243,9 @@ document.onkeydown = function(e: KeyboardEvent){ } function resetValues() { + lastCheckTime = 0; + lastCheckVideoTime = -1; + //reset sponsor times sponsorTimes = null; UUIDs = []; @@ -250,6 +258,8 @@ function resetValues() { //reset sponsor data found check sponsorDataFound = false; + + if (switchingVideos !== null || true) switchingVideos = true; } async function videoIDChange(id) { @@ -264,8 +274,6 @@ async function videoIDChange(id) { //id is not valid if (!id) return; - switchingVideos = true; - // Wait for options to be ready await utils.wait(() => Config.config !== null, 5000, 1); @@ -501,9 +509,24 @@ function sponsorsLookup(id: string, channelIDPromise?) { video.addEventListener('play', () => { switchingVideos = false; - startSponsorSchedule(); + + // Make sure it doesn't get double called with the playing event + if (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000) { + lastCheckTime = Date.now(); + lastCheckVideoTime = video.currentTime; + + startSponsorSchedule(); + } + }); + video.addEventListener('playing', () => { + // Make sure it doesn't get double called with the play event + if (lastCheckVideoTime !== video.currentTime && Date.now() - lastCheckTime > 2000) { + lastCheckTime = Date.now(); + lastCheckVideoTime = video.currentTime; + + startSponsorSchedule(); + } }); - video.addEventListener('playing', () => startSponsorSchedule()); video.addEventListener('seeked', () => { if (!video.paused) startSponsorSchedule(); }); From 5595420be636e78e18c52e5a7415a0c2e1ae98f3 Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 10 Mar 2020 23:22:57 -0400 Subject: [PATCH 6/7] Removed redundant if statement --- src/content.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content.ts b/src/content.ts index 7430bcd1..218a5401 100644 --- a/src/content.ts +++ b/src/content.ts @@ -259,7 +259,7 @@ function resetValues() { //reset sponsor data found check sponsorDataFound = false; - if (switchingVideos !== null || true) switchingVideos = true; + switchingVideos = true; } async function videoIDChange(id) { From 4a9ed1348e638ce9c157c31aa6b2a39b77168d1b Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Tue, 10 Mar 2020 23:23:10 -0400 Subject: [PATCH 7/7] Increase version number --- manifest/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest/manifest.json b/manifest/manifest.json index 022929c3..ea2cee9d 100644 --- a/manifest/manifest.json +++ b/manifest/manifest.json @@ -1,7 +1,7 @@ { "name": "__MSG_fullName__", "short_name": "__MSG_Name__", - "version": "1.2.21", + "version": "1.2.22", "default_locale": "en", "description": "__MSG_Description__", "content_scripts": [{