From 5d4377c081d18d89e64184c60d3fa97504768c81 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Tue, 12 Apr 2022 02:27:39 +0300 Subject: [PATCH] Restructuring Settings Structure --- src/assets/javascripts/helpers/common.js | 31 +- src/assets/javascripts/helpers/twitter.js | 14 + src/assets/javascripts/helpers/wikipedia.js | 4 +- .../javascripts/helpers/youtube/options.js | 149 +--- .../javascripts/helpers/youtube/youtube.js | 170 +--- src/pages/options/imgur/imgur.html | 85 +- src/pages/options/imgur/imgur.js | 4 +- src/pages/options/instagram/instagram.html | 84 +- src/pages/options/instagram/instagram.js | 4 +- src/pages/options/lbry/lbry.html | 86 +- src/pages/options/lbry/lbry.js | 4 +- src/pages/options/medium/medium.html | 87 +- src/pages/options/medium/medium.js | 4 +- src/pages/options/peertube/peertube.html | 86 +- src/pages/options/peertube/peertube.js | 4 +- src/pages/options/pixiv/pixiv.html | 89 ++- src/pages/options/pixiv/pixiv.js | 4 +- src/pages/options/reddit/reddit.html | 48 +- src/pages/options/reddit/reddit.js | 8 +- src/pages/options/search/search.html | 75 +- src/pages/options/search/search.js | 13 +- .../options/sendTargets/sendTargets.html | 85 +- src/pages/options/sendTargets/sendTargets.js | 4 +- src/pages/options/spotify/spotify.html | 86 +- src/pages/options/spotify/spotify.js | 4 +- src/pages/options/tiktok/tiktok.html | 84 +- src/pages/options/tiktok/tiktok.js | 8 +- src/pages/options/translate/translate.html | 744 +++++++++--------- src/pages/options/translate/translate.js | 25 +- src/pages/options/twitter/twitter.html | 206 +++-- src/pages/options/twitter/twitter.js | 38 +- src/pages/options/wikipedia/wikipedia.html | 144 ++-- src/pages/options/wikipedia/wikipedia.js | 12 +- src/pages/options/youtube/invidious.js | 248 +++--- src/pages/options/youtube/piped.js | 361 +++------ src/pages/options/youtube/pipedMaterial.js | 129 ++- src/pages/options/youtube/youtube.html | 272 ++++--- src/pages/options/youtube/youtube.js | 107 +-- src/pages/stylesheets/styles.css | 5 +- 39 files changed, 1692 insertions(+), 1923 deletions(-) diff --git a/src/assets/javascripts/helpers/common.js b/src/assets/javascripts/helpers/common.js index cf95d91..65810db 100644 --- a/src/assets/javascripts/helpers/common.js +++ b/src/assets/javascripts/helpers/common.js @@ -88,9 +88,10 @@ function processDefaultCustomInstances( getNameCustomRedirects, setNameCustomRedirects ) { + let nameProtocolElement = document.getElementById(name).getElementsByClassName(protocol)[0]; let nameCustomInstances = []; - let nameCheckListElement = document.getElementById(`${name}-${protocol}-checklist`); + let nameCheckListElement = nameProtocolElement.getElementsByClassName('checklist')[0]; let nameDefaultRedirects; function calcNameCheckBoxes() { @@ -101,22 +102,22 @@ function processDefaultCustomInstances( break; } for (const element of nameCheckListElement.getElementsByTagName('input')) - element.checked = nameDefaultRedirects.includes(element.id) - document.getElementById(`${name}-${protocol}-toogle-all`).checked = isTrue; + element.checked = nameDefaultRedirects.includes(element.className) + nameProtocolElement.getElementsByClassName('toogle-all')[0].checked = isTrue; } nameDefaultRedirects = getNameRedirectsChecks(); nameCheckListElement.innerHTML = [ - `
Toggle All
`, - ...nameHelper.getRedirects()[name][protocol].map((x) => `
${x}
`), + `
Toggle All
`, + ...nameHelper.getRedirects()[name][protocol].map((x) => `
${x}
`), ].join('\n
\n'); localise.localisePage(); calcNameCheckBoxes(); - document.getElementById(`${name}-${protocol}-toogle-all`).addEventListener("change", event => { + nameProtocolElement.getElementsByClassName('toogle-all')[0].addEventListener("change", event => { if (event.target.checked) nameDefaultRedirects = [...nameHelper.getRedirects()[name][protocol]]; else @@ -126,12 +127,12 @@ function processDefaultCustomInstances( }); for (let element of nameCheckListElement.getElementsByTagName('input')) { - if (element.id != `${name}-${protocol}-toogle-all`) - document.getElementById(element.id).addEventListener("change", (event) => { + if (element.className != 'toogle-all') + nameProtocolElement.getElementsByClassName(element.className)[0].addEventListener("change", event => { if (event.target.checked) - nameDefaultRedirects.push(element.id) + nameDefaultRedirects.push(element.className) else { - let index = nameDefaultRedirects.indexOf(element.id); + let index = nameDefaultRedirects.indexOf(element.className); if (index > -1) nameDefaultRedirects.splice(index, 1); } setNameRedirectsChecks(nameDefaultRedirects); @@ -141,9 +142,9 @@ function processDefaultCustomInstances( nameCustomInstances = getNameCustomRedirects(); function calcNameCustomInstances() { - document.getElementById(`${name}-${protocol}-custom-checklist`).innerHTML = + nameProtocolElement.getElementsByClassName('custom-checklist')[0].innerHTML = nameCustomInstances.map( - (x) => `
${x}

- -
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
@@ -196,4 +199,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/imgur/imgur.js b/src/pages/options/imgur/imgur.js index 25fd891..9742bfd 100644 --- a/src/pages/options/imgur/imgur.js +++ b/src/pages/options/imgur/imgur.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/instagram/instagram.html b/src/pages/options/instagram/instagram.html index f61f001..baf5166 100644 --- a/src/pages/options/instagram/instagram.html +++ b/src/pages/options/instagram/instagram.html @@ -135,50 +135,54 @@

-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
+
+
+
+

Custom Instances

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

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
- - +

Default Instances

- -
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
@@ -187,4 +191,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/instagram/instagram.js b/src/pages/options/instagram/instagram.js index 9967176..a7788a6 100644 --- a/src/pages/options/instagram/instagram.js +++ b/src/pages/options/instagram/instagram.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/lbry/lbry.html b/src/pages/options/lbry/lbry.html index 6e0e43f..4000007 100644 --- a/src/pages/options/lbry/lbry.html +++ b/src/pages/options/lbry/lbry.html @@ -144,56 +144,60 @@
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
- --> + - + \ No newline at end of file diff --git a/src/pages/options/lbry/lbry.js b/src/pages/options/lbry/lbry.js index 43ff74d..7599521 100644 --- a/src/pages/options/lbry/lbry.js +++ b/src/pages/options/lbry/lbry.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/medium/medium.html b/src/pages/options/medium/medium.html index bc0b9d6..fde374e 100644 --- a/src/pages/options/medium/medium.html +++ b/src/pages/options/medium/medium.html @@ -144,51 +144,54 @@

- -
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
- -
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
@@ -198,4 +201,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/medium/medium.js b/src/pages/options/medium/medium.js index dcc4b4a..5337e41 100644 --- a/src/pages/options/medium/medium.js +++ b/src/pages/options/medium/medium.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/peertube/peertube.html b/src/pages/options/peertube/peertube.html index fb95dd4..c419049 100644 --- a/src/pages/options/peertube/peertube.html +++ b/src/pages/options/peertube/peertube.html @@ -144,57 +144,59 @@

- -
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
- - + \ No newline at end of file diff --git a/src/pages/options/peertube/peertube.js b/src/pages/options/peertube/peertube.js index 7aa0f71..d01a6e0 100644 --- a/src/pages/options/peertube/peertube.js +++ b/src/pages/options/peertube/peertube.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/pixiv/pixiv.html b/src/pages/options/pixiv/pixiv.html index 8f15343..9ce7c1d 100644 --- a/src/pages/options/pixiv/pixiv.html +++ b/src/pages/options/pixiv/pixiv.html @@ -135,7 +135,10 @@
-

Frontend: This isn't a fully private frontend

+

+ Frontend: This isn't a fully private frontend +

@@ -153,49 +156,53 @@
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
@@ -205,4 +212,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/pixiv/pixiv.js b/src/pages/options/pixiv/pixiv.js index 0cefd1d..a9a11e1 100644 --- a/src/pages/options/pixiv/pixiv.js +++ b/src/pages/options/pixiv/pixiv.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/reddit/reddit.html b/src/pages/options/reddit/reddit.html index d63618a..820294b 100644 --- a/src/pages/options/reddit/reddit.html +++ b/src/pages/options/reddit/reddit.html @@ -162,20 +162,20 @@
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
diff --git a/src/pages/options/reddit/reddit.js b/src/pages/options/reddit/reddit.js index 6d747eb..2645ed4 100644 --- a/src/pages/options/reddit/reddit.js +++ b/src/pages/options/reddit/reddit.js @@ -45,11 +45,11 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalLibredditDiv = document.getElementById("libreddit-normal"); - let torLibredditDiv = document.getElementById("libreddit-tor"); + let normalLibredditDiv = libredditDivElement.getElementsByClassName("normal")[0]; + let torLibredditDiv = libredditDivElement.getElementsByClassName("tor")[0]; - let normalTedditDiv = document.getElementById("teddit-normal"); - let torTedditDiv = document.getElementById("teddit-tor"); + let normalTedditDiv = tedditDivElement.getElementsByClassName("normal")[0]; + let torTedditDiv = tedditDivElement.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalLibredditDiv.style.display = 'block'; normalTedditDiv.style.display = 'block'; diff --git a/src/pages/options/search/search.html b/src/pages/options/search/search.html index a90ad8e..a5f26ab 100644 --- a/src/pages/options/search/search.html +++ b/src/pages/options/search/search.html @@ -162,20 +162,20 @@

-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+

-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+

-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
@@ -325,4 +324,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/search/search.js b/src/pages/options/search/search.js index cc4a44e..d96665e 100644 --- a/src/pages/options/search/search.js +++ b/src/pages/options/search/search.js @@ -61,14 +61,15 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalsearxDiv = document.getElementById("searx-normal"); - let torsearxDiv = document.getElementById("searx-tor"); + let normalsearxDiv = searxDivElement.getElementsByClassName("normal")[0]; + let torsearxDiv = searxDivElement.getElementsByClassName("tor")[0]; - let normalsearxngDiv = document.getElementById("searxng-normal"); - let torsearxngDiv = document.getElementById("searxng-tor"); + let normalsearxngDiv = searxngDivElement.getElementsByClassName("normal")[0]; + let torsearxngDiv = searxngDivElement.getElementsByClassName("tor")[0]; + + let normalwhoogleDiv = whoogleDivElement.getElementsByClassName("normal")[0]; + let torwhoogleDiv = whoogleDivElement.getElementsByClassName("tor")[0]; - let normalwhoogleDiv = document.getElementById("whoogle-normal"); - let torwhoogleDiv = document.getElementById("whoogle-tor"); if (protocol == 'normal') { normalsearxDiv.style.display = 'block'; normalsearxngDiv.style.display = 'block'; diff --git a/src/pages/options/sendTargets/sendTargets.html b/src/pages/options/sendTargets/sendTargets.html index 3a00adf..7da5d1f 100644 --- a/src/pages/options/sendTargets/sendTargets.html +++ b/src/pages/options/sendTargets/sendTargets.html @@ -143,50 +143,53 @@

- -
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
@@ -196,4 +199,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/sendTargets/sendTargets.js b/src/pages/options/sendTargets/sendTargets.js index 0b0a937..1e39e24 100644 --- a/src/pages/options/sendTargets/sendTargets.js +++ b/src/pages/options/sendTargets/sendTargets.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/spotify/spotify.html b/src/pages/options/spotify/spotify.html index 890bf97..731e7d5 100644 --- a/src/pages/options/spotify/spotify.html +++ b/src/pages/options/spotify/spotify.html @@ -143,57 +143,59 @@

- -
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
- - + \ No newline at end of file diff --git a/src/pages/options/spotify/spotify.js b/src/pages/options/spotify/spotify.js index 1bd078c..8dbc6bc 100644 --- a/src/pages/options/spotify/spotify.js +++ b/src/pages/options/spotify/spotify.js @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/tiktok/tiktok.html b/src/pages/options/tiktok/tiktok.html index 34c091a..8136ccd 100644 --- a/src/pages/options/tiktok/tiktok.html +++ b/src/pages/options/tiktok/tiktok.html @@ -144,49 +144,53 @@
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Default Instances

- -
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
+
- - +

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
@@ -196,4 +200,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/tiktok/tiktok.js b/src/pages/options/tiktok/tiktok.js index 13de04d..1f5351a 100644 --- a/src/pages/options/tiktok/tiktok.js +++ b/src/pages/options/tiktok/tiktok.js @@ -3,12 +3,12 @@ import commonHelper from "../../../assets/javascripts/helpers/common.js"; let disableTiktokElement = document.getElementById("disable-tiktok"); disableTiktokElement.addEventListener("change", - (event) => tiktokHelper.setDisable(!event.target.checked) + event => tiktokHelper.setDisable(!event.target.checked) ); let protocolElement = document.getElementById("protocol") protocolElement.addEventListener("change", - (event) => { + event => { let protocol = event.target.options[protocolElement.selectedIndex].value tiktokHelper.setProtocol(protocol); changeProtocolSettings(protocol); @@ -16,8 +16,8 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; diff --git a/src/pages/options/translate/translate.html b/src/pages/options/translate/translate.html index aace2d4..3116a0a 100644 --- a/src/pages/options/translate/translate.html +++ b/src/pages/options/translate/translate.html @@ -2,12 +2,12 @@ - - - - - - LibRedirect: Translate + + + + + + LibRedirect: Translate @@ -128,380 +128,378 @@ -
-
-

Enable

- -
+
+
+

Enable

+ +
-
-

Frontend

- -
+
+

Frontend

+ +
-
-

Protocol

- -
+
+

Protocol

+ +
+
+ +
+
+

From

+ +
+
+

To

+ +
+ +
+

Engine

+ +
+
+
+

Default Instances

+
+
+

- -
-
-

From

- -
-
-

To

- -
- -
-

Engine

- -
-
-
-

Default Instances

-
-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
+
+

Custom Instances

- -
-
-
-

Default Instances

-
-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-
-

Custom Instances

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

Default Instances

+
+
+
+
+

Custom Instances

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

Default Instances

+
+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
- - - +
+ + + + - + \ No newline at end of file diff --git a/src/pages/options/translate/translate.js b/src/pages/options/translate/translate.js index d1df35a..5da4874 100644 --- a/src/pages/options/translate/translate.js +++ b/src/pages/options/translate/translate.js @@ -6,8 +6,8 @@ disableElement.addEventListener("change", (event) => translateHelper.setDisable(!event.target.checked) ); -let simplyTranslateDivElement = document.getElementById("simplyTranslate") -let lingvaDivElement = document.getElementById("lingva") +let simplyTranslateDivElement = document.getElementById("simplyTranslate"); +let lingvaDivElement = document.getElementById("lingva"); function changeFrontendsSettings(frontend) { @@ -22,14 +22,14 @@ function changeFrontendsSettings(frontend) { } let translateFrontendElement = document.getElementById("translate-frontend"); translateFrontendElement.addEventListener("change", - (event) => { + event => { let frontend = event.target.options[translateFrontendElement.selectedIndex].value translateHelper.setFrontend(frontend) changeFrontendsSettings(frontend); } ); -let protocolElement = document.getElementById("protocol") +let protocolElement = document.getElementById("protocol"); protocolElement.addEventListener("change", (event) => { let protocol = event.target.options[protocolElement.selectedIndex].value @@ -39,11 +39,12 @@ protocolElement.addEventListener("change", ); function changeProtocolSettings(protocol) { - let normalSimplyTranslateDiv = document.getElementById("simplyTranslate-normal"); - let torSimplyTranslateDiv = document.getElementById("simplyTranslate-tor"); + let normalSimplyTranslateDiv = document.getElementById("simplyTranslate").getElementsByClassName("normal")[0]; + let torSimplyTranslateDiv = document.getElementById("simplyTranslate").getElementsByClassName("tor")[0]; + + let normalLingvaDiv = document.getElementById("lingva").getElementsByClassName("normal")[0]; + let torLingvaDiv = document.getElementById("lingva").getElementsByClassName("tor")[0]; - let normalLingvaDiv = document.getElementById("lingva-normal"); - let torLingvaDiv = document.getElementById("lingva-tor"); if (protocol == 'normal') { normalSimplyTranslateDiv.style.display = 'block'; normalLingvaDiv.style.display = 'block'; @@ -58,17 +59,18 @@ function changeProtocolSettings(protocol) { } } -let fromElement = document.getElementById("from"); +let fromElement = document.getElementsByClassName("from")[0]; fromElement.addEventListener("change", event => translateHelper.setFrom(event.target.options[fromElement.selectedIndex].value) ); -let toElement = document.getElementById("to"); +let toElement = document.getElementsByClassName("to")[0]; toElement.addEventListener("change", event => translateHelper.setTo(event.target.options[toElement.selectedIndex].value) ); -let simplyTranslateEngineElement = document.getElementById("simplyTranslate-engine"); +let simplyTranslateElement = document.getElementById("simplyTranslate") +let simplyTranslateEngineElement = simplyTranslateElement.getElementsByClassName("engine")[0]; simplyTranslateEngineElement.addEventListener("change", event => translateHelper.setSimplyTranslateEngine(event.target.options[simplyTranslateEngineElement.selectedIndex].value) ); @@ -110,7 +112,6 @@ translateHelper.init().then(() => { translateHelper.setSimplyTranslateTorCustomRedirects ); - commonHelper.processDefaultCustomInstances( 'lingva', 'normal', diff --git a/src/pages/options/twitter/twitter.html b/src/pages/options/twitter/twitter.html index 980fd55..d017ba7 100644 --- a/src/pages/options/twitter/twitter.html +++ b/src/pages/options/twitter/twitter.html @@ -149,84 +149,154 @@
-
- -
-
-

Theme

- -
-
- -
-

Infinite scrolling (experimental, requires JavaScript)

- +

Enable Custom Settings (will use cookies)

+
-
-

Make profile sidebar stick to top

- -
+
-
+
-
- -
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
+
- - +

Display

-
-
-
- -
-
-

Default Tor Instances

-
-
-
-
-

Custom Instances

-
-
- - +

Theme

+
-
-
+ +
+

Infinite scrolling (experimental, requires JavaScript)

+ +
+ +
+

Make profile sidebar stick to top

+ +
+ +
+

Support bidirectional text (makes clicking on tweets harder)

+ +
+ +
+

Hide tweet stats (replies, retweets, likes)

+ +
+ +
+

Hide profile banner

+ +
+ +
+

Hide pinned tweets

+ +
+ +
+

Hide tweet replies

+ +
+ +
+

Square profile pictures

+ +
+ +
+ +
+

Media

+
+ +
+

Enable mp4 video playback (only for gifs)

+ +
+ +
+

Enable hls video streaming (requires JavaScript)

+ +
+ +
+

Proxy video streaming through the server (might be slow)

+ +
+ +
+

Autoplay gifs

+ +
+ +
+
+ +
+ +
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ +
+ +
+
+

Default Tor Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
diff --git a/src/pages/options/twitter/twitter.js b/src/pages/options/twitter/twitter.js index 2d86d9a..c6d7ea1 100644 --- a/src/pages/options/twitter/twitter.js +++ b/src/pages/options/twitter/twitter.js @@ -2,23 +2,23 @@ import twitterHelper from "../../../assets/javascripts/helpers/twitter.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js"; let disableTwitterElement = document.getElementById("disable-nitter"); -disableTwitterElement.addEventListener("change", - (event) => twitterHelper.setDisable(!event.target.checked) -); - -let protocolElement = document.getElementById("protocol") -protocolElement.addEventListener("change", - (event) => { - let protocol = event.target.options[protocolElement.selectedIndex].value - twitterHelper.setProtocol(protocol); - changeProtocolSettings(protocol); - } -); +let customSettingsDivElement = document.getElementsByClassName("custom-settings"); +let protocolElement = document.getElementById("protocol"); +let enableYoutubeCustomSettingsElement = document.getElementById("enable-twitter-custom-settings"); +let bypassWatchOnTwitterElement = document.getElementById("bypass-watch-on-twitter"); +let nitterElement = document.getElementById("nitter"); +document.addEventListener("change", _ => { + twitterHelper.setDisable(!disableTwitterElement.checked) + twitterHelper.setProtocol(protocolElement.value); + twitterHelper.setEnableCustomSettings(enableYoutubeCustomSettingsElement.checked); + twitterHelper.setBypassWatchOnTwitter(bypassWatchOnTwitterElement.checked); + changeProtocolSettings(protocolElement.value); +}) function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = nitterElement.getElementsByClassName("normal")[0]; + let torDiv = nitterElement.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; @@ -27,15 +27,15 @@ function changeProtocolSettings(protocol) { normalDiv.style.display = 'none'; torDiv.style.display = 'block'; } + if (enableYoutubeCustomSettingsElement.checked) + for (const item of customSettingsDivElement) item.style.display = 'block'; + else + for (const item of customSettingsDivElement) item.style.display = 'none'; } -let bypassWatchOnTwitterElement = document.getElementById("bypass-watch-on-twitter") -bypassWatchOnTwitterElement.addEventListener("change", - event => twitterHelper.setBypassWatchOnTwitter(event.target.checked) -); - twitterHelper.init().then(() => { disableTwitterElement.checked = !twitterHelper.getDisable(); + enableYoutubeCustomSettingsElement.checked = twitterHelper.getEnableCustomSettings(); bypassWatchOnTwitterElement.checked = twitterHelper.getBypassWatchOnTwitter(); let protocol = twitterHelper.getProtocol(); diff --git a/src/pages/options/wikipedia/wikipedia.html b/src/pages/options/wikipedia/wikipedia.html index 7ad257c..728f2b1 100644 --- a/src/pages/options/wikipedia/wikipedia.html +++ b/src/pages/options/wikipedia/wikipedia.html @@ -2,12 +2,12 @@ - - - - - - LibRedirect: Wikipedia + + + + + + LibRedirect: Wikipedia @@ -54,7 +54,7 @@
- Imgur + Imgur
@@ -127,78 +127,78 @@
-
+
+
+

Enable

+ +
+ +
+

Protocol

+ +
+ +
+
+
-

Enable

- +

Default Instances

- - -
-

Protocol

- +
-
- -
-
-

Default Instances

-
-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
+
+

Custom Instances

+
+
+ + +
+
+
+
-
-
-

Default Instances

-
-
-
-
-
-

Custom Instances

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

Default Instances

-
+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
- - - +
+
+ + + + + - + \ No newline at end of file diff --git a/src/pages/options/wikipedia/wikipedia.js b/src/pages/options/wikipedia/wikipedia.js index 92ab8dc..1cad27a 100644 --- a/src/pages/options/wikipedia/wikipedia.js +++ b/src/pages/options/wikipedia/wikipedia.js @@ -3,22 +3,21 @@ import commonHelper from "../../../assets/javascripts/helpers/common.js"; let disableWikipediaElement = document.getElementById("disable-wikipedia"); disableWikipediaElement.addEventListener("change", - (event) => wikipediaHelper.setDisable(!event.target.checked) + event => wikipediaHelper.setDisable(!event.target.checked) ); -let protocolElement = document.getElementById("protocol") +let protocolElement = document.getElementById("protocol"); protocolElement.addEventListener("change", - (event) => { + event => { let protocol = event.target.options[protocolElement.selectedIndex].value wikipediaHelper.setProtocol(protocol); changeProtocolSettings(protocol); } ); - function changeProtocolSettings(protocol) { - let normalDiv = document.getElementById("normal"); - let torDiv = document.getElementById("tor"); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalDiv.style.display = 'block'; torDiv.style.display = 'none'; @@ -33,6 +32,7 @@ wikipediaHelper.init().then(() => { disableWikipediaElement.checked = !wikipediaHelper.getDisable(); let protocol = wikipediaHelper.getProtocol(); + console.log('protocol', protocol); protocolElement.value = protocol; changeProtocolSettings(protocol); diff --git a/src/pages/options/youtube/invidious.js b/src/pages/options/youtube/invidious.js index 9df3406..d735c18 100644 --- a/src/pages/options/youtube/invidious.js +++ b/src/pages/options/youtube/invidious.js @@ -1,165 +1,121 @@ import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js"; -let invidiousAlwaysProxyElement = document.getElementById("invidious-local"); -invidiousAlwaysProxyElement.addEventListener("change", - event => youtubeHelper.setInvidiousAlwaysProxy(event.target.checked) -); +let invidiousElement = document.getElementById('invidious'); +let invidiousAlwaysProxyElement = invidiousElement.getElementsByClassName("local")[0]; +let invidiousPlayerStyleElement = invidiousElement.getElementsByClassName("player_style")[0]; +let invidiousQualityElement = invidiousElement.getElementsByClassName("quality")[0]; +let invidiousVideoLoopElement = invidiousElement.getElementsByClassName("video_loop")[0]; +let invidiousContinueAutoplayElement = invidiousElement.getElementsByClassName("continue_autoplay")[0]; +let invidiousContinueElement = invidiousElement.getElementsByClassName("continue")[0]; +let youtubeListenElement = invidiousElement.getElementsByClassName("listen")[0]; +let invidiousSpeedElement = invidiousElement.getElementsByClassName("speed")[0]; +let invidiousQualityDashElement = invidiousElement.getElementsByClassName("quality_dash")[0]; +let invidiousRelatedVideoElement = invidiousElement.getElementsByClassName("related_videos")[0]; +let invidiousAnnotationsElement = invidiousElement.getElementsByClassName("annotations")[0]; +let invidiousExtendDescElement = invidiousElement.getElementsByClassName("extend_desc")[0]; +let invidiousVrModeElement = invidiousElement.getElementsByClassName("vr_mode")[0]; +let invidiousSavePlayerPosElement = invidiousElement.getElementsByClassName("save_player_pos")[0]; +let invidiousComments0Element = invidiousElement.getElementsByClassName("comments[0]")[0]; +let invidiousComments1Element = invidiousElement.getElementsByClassName("comments[1]")[0]; +let invidiousCaptions0Element = invidiousElement.getElementsByClassName("captions[0]")[0]; +let invidiousCaptions1Element = invidiousElement.getElementsByClassName("captions[1]")[0]; +let invidiousCaptions2Element = invidiousElement.getElementsByClassName("captions[2]")[0]; +let autoplayElement = invidiousElement.getElementsByClassName("youtubeAutoplay")[0]; +let volumeElement = invidiousElement.getElementsByClassName("volume")[0]; +let volumeValueElement = invidiousElement.getElementsByClassName("volume-value")[0]; -let invidiousPlayerStyleElement = document.getElementById("invidious-player_style"); -invidiousPlayerStyleElement.addEventListener("change", - event => youtubeHelper.setInvidiousPlayerStyle(event.target.options[invidiousPlayerStyleElement.selectedIndex].value) -); +volumeElement.addEventListener("input", () => volumeValueElement.textContent = `${volumeElement.value}%`); -let invidiousQualityElement = document.getElementById("invidious-quality"); -invidiousQualityElement.addEventListener("change", - event => youtubeHelper.setinvidiousQuality(event.target.options[invidiousQualityElement.selectedIndex].value) -); +invidiousElement.addEventListener("change", async _ => { + console.log('changed invidious settings'); + let commentsList = youtubeHelper.getInvidiousComments(); + commentsList[0] = invidiousComments0Element.value; + commentsList[1] = invidiousComments1Element.value; -let invidiousVideoLoopElement = document.getElementById("invidious-video_loop"); -invidiousVideoLoopElement.addEventListener("change", - event => youtubeHelper.setInvidiousVideoLoop(event.target.checked) -); + let captionsList = youtubeHelper.getInvidiousCaptions(); + captionsList[0] = invidiousCaptions0Element.value; + captionsList[1] = invidiousCaptions1Element.value; + captionsList[2] = invidiousCaptions2Element.value; -let invidiousContinueAutoplayElement = document.getElementById("invidious-continue_autoplay"); -invidiousContinueAutoplayElement.addEventListener("change", - event => youtubeHelper.setInvidiousContinueAutoplay(event.target.checked) -); + await youtubeHelper.setYoutubeSettings({ + invidiousAlwaysProxy: invidiousAlwaysProxyElement.checked, + youtubeAutoplay: autoplayElement.checked, + invidiousPlayerStyle: invidiousPlayerStyleElement.value, + invidiousQuality: invidiousQualityElement.value, + invidiousVideoLoop: invidiousVideoLoopElement.checked, + invidiousContinueAutoplay: invidiousContinueAutoplayElement.checked, + invidiousContinue: invidiousContinueElement.checked, + youtubeListen: youtubeListenElement.checked, + invidiousSpeed: invidiousSpeedElement.value, + invidiousQualityDash: invidiousQualityDashElement.value, + youtubeVolume: volumeElement.value, + invidiousComments: commentsList, + invidiousCaptions: captionsList, + invidiousRelatedVideos: invidiousRelatedVideoElement.checked, + invidiousAnnotations: invidiousAnnotationsElement.checked, + invidiousExtendDesc: invidiousExtendDescElement.checked, + invidiousVrMode: invidiousVrModeElement.checked, + invidiousSavePlayerPos: invidiousSavePlayerPosElement.checked + }); + init(); +}); -let invidiousContinueElement = document.getElementById("invidious-continue"); -invidiousContinueElement.addEventListener("change", - event => youtubeHelper.setInvidiousContinue(event.target.checked) -); +function init() { + youtubeHelper.init().then(() => { + invidiousVideoLoopElement.checked = youtubeHelper.getInvidiousVideoLoop(); -let youtubeListenElement = document.getElementById("invidious-listen"); -youtubeListenElement.addEventListener("change", - event => youtubeHelper.setYoutubeListen(event.target.checked) -); + autoplayElement.checked = youtubeHelper.getAutoplay(); -let invidiousSpeedElement = document.getElementById("invidious-speed"); -invidiousSpeedElement.addEventListener("change", - event => youtubeHelper.setInvidiousSpeed(event.target.options[invidiousSpeedElement.selectedIndex].value) -); + invidiousPlayerStyleElement.value = youtubeHelper.getInvidiousPlayerStyle(); -let invidiousQualityDashElement = document.getElementById("invidious-quality_dash"); -invidiousQualityDashElement.addEventListener("change", - event => youtubeHelper.setInvidiousQualityDash(event.target.options[invidiousQualityDashElement.selectedIndex].value) -); + invidiousContinueAutoplayElement.checked = youtubeHelper.getInvidiousContinueAutoplay(); + invidiousContinueElement.checked = youtubeHelper.getInvidiousContinue(); + invidiousAlwaysProxyElement.checked = youtubeHelper.getInvidiousAlwaysProxy(); + youtubeListenElement.checked = youtubeHelper.getYoutubeListen(); -let invidiousComments0Element = document.getElementById("invidious-comments[0]"); -invidiousComments0Element.addEventListener("change", - event => { - let commentsList = youtubeHelper.getInvidiousComments(); - commentsList[0] = event.target.options[invidiousComments0Element.selectedIndex].value - youtubeHelper.setInvidiousComments(commentsList) - } -); -let invidiousComments1Element = document.getElementById("invidious-comments[1]"); -invidiousComments1Element.addEventListener("change", - event => { - let commentsList = youtubeHelper.getInvidiousComments(); - commentsList[1] = event.target.options[invidiousComments1Element.selectedIndex].value - youtubeHelper.setInvidiousComments(commentsList) - } -); + invidiousSpeedElement.value = youtubeHelper.getInvidiousSpeed(); + invidiousQualityElement.value = youtubeHelper.getInvidiousQuality(); + invidiousQualityDashElement.value = youtubeHelper.getInvidiousQualityDash(); -let invidiousCaptions0Element = document.getElementById("invidious-captions[0]"); -invidiousCaptions0Element.addEventListener("change", - event => { - let captionsList = youtubeHelper.getInvidiousCaptions(); - captionsList[0] = event.target.options[invidiousCaptions0Element.selectedIndex].value - youtubeHelper.setInvidiousCaptions(captionsList) - } -); -let invidiousCaptions1Element = document.getElementById("invidious-captions[1]"); -invidiousCaptions1Element.addEventListener("change", - event => { - let captionsList = youtubeHelper.getInvidiousCaptions(); - captionsList[1] = event.target.options[invidiousCaptions1Element.selectedIndex].value - youtubeHelper.setInvidiousCaptions(captionsList) - } -); -let invidiousCaptions2Element = document.getElementById("invidious-captions[2]"); -invidiousCaptions2Element.addEventListener("change", - event => { - let captionsList = youtubeHelper.getInvidiousCaptions(); - captionsList[2] = event.target.options[invidiousCaptions2Element.selectedIndex].value - youtubeHelper.setInvidiousCaptions(captionsList) - } -); + volumeElement.value = youtubeHelper.getVolume(); + volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`; -let invidiousRelatedVideoElement = document.getElementById("invidious-related_videos"); -invidiousRelatedVideoElement.addEventListener("change", - event => youtubeHelper.setInvidiousRelatedVideos(event.target.checked) -); + invidiousComments0Element.value = youtubeHelper.getInvidiousComments()[0]; + invidiousComments1Element.value = youtubeHelper.getInvidiousComments()[1]; -let invidiousAnnotationsElement = document.getElementById("invidious-annotations"); -invidiousAnnotationsElement.addEventListener("change", - event => youtubeHelper.setInvidiousAnnotations(event.target.checked) -); + invidiousCaptions0Element.value = youtubeHelper.getInvidiousCaptions()[0]; + invidiousCaptions1Element.value = youtubeHelper.getInvidiousCaptions()[1]; + invidiousCaptions2Element.value = youtubeHelper.getInvidiousCaptions()[2]; + invidiousRelatedVideoElement.checked = youtubeHelper.getInvidiousRelatedVideos(); + invidiousAnnotationsElement.checked = youtubeHelper.getInvidiousAnnotations(); + invidiousExtendDescElement.checked = youtubeHelper.getInvidiousExtendDesc(); + invidiousVrModeElement.checked = youtubeHelper.getInvidiousVrMode(); + invidiousSavePlayerPosElement.checked = youtubeHelper.getInvidiousSavePlayerPos(); -let invidiousExtendDescElement = document.getElementById("invidious-extend_desc"); -invidiousExtendDescElement.addEventListener("change", - event => youtubeHelper.setInvidiousExtendDesc(event.target.checked) -); + commonHelper.processDefaultCustomInstances( + 'invidious', + 'normal', + youtubeHelper, + document, + youtubeHelper.getInvidiousNormalRedirectsChecks, + youtubeHelper.setInvidiousNormalRedirectsChecks, + youtubeHelper.getInvidiousNormalCustomRedirects, + youtubeHelper.setInvidiousNormalCustomRedirects + ); -let invidiousVrModeElement = document.getElementById("invidious-vr_mode"); -invidiousVrModeElement.addEventListener("change", - event => youtubeHelper.setInvidiousVrMode(event.target.checked) -); + commonHelper.processDefaultCustomInstances( + 'invidious', + 'tor', + youtubeHelper, + document, + youtubeHelper.getInvidiousTorRedirectsChecks, + youtubeHelper.setInvidiousTorRedirectsChecks, + youtubeHelper.getInvidiousTorCustomRedirects, + youtubeHelper.setInvidiousTorCustomRedirects + ); + }); +} -let invidiousSavePlayerPosElement = document.getElementById("invidious-save_player_pos"); -invidiousSavePlayerPosElement.addEventListener("change", - event => youtubeHelper.setInvidiousSavePlayerPos(event.target.checked) -); - -youtubeHelper.init().then(() => { - invidiousVideoLoopElement.checked = youtubeHelper.getInvidiousVideoLoop(); - - invidiousPlayerStyleElement.value = youtubeHelper.getInvidiousPlayerStyle(); - - invidiousContinueAutoplayElement.checked = youtubeHelper.getInvidiousContinueAutoplay(); - invidiousContinueElement.checked = youtubeHelper.getInvidiousContinue(); - invidiousAlwaysProxyElement.checked = youtubeHelper.getInvidiousAlwaysProxy(); - youtubeListenElement.checked = youtubeHelper.getYoutubeListen(); - - invidiousSpeedElement.value = youtubeHelper.getInvidiousSpeed(); - invidiousQualityElement.value = youtubeHelper.getInvidiousQuality(); - invidiousQualityDashElement.value = youtubeHelper.getInvidiousQualityDash(); - - invidiousComments0Element.value = youtubeHelper.getInvidiousComments()[0]; - invidiousComments1Element.value = youtubeHelper.getInvidiousComments()[1]; - - invidiousCaptions0Element.value = youtubeHelper.getInvidiousCaptions()[0]; - invidiousCaptions1Element.value = youtubeHelper.getInvidiousCaptions()[1]; - invidiousCaptions2Element.value = youtubeHelper.getInvidiousCaptions()[2]; - - invidiousRelatedVideoElement.checked = youtubeHelper.getInvidiousRelatedVideos(); - invidiousAnnotationsElement.checked = youtubeHelper.getInvidiousAnnotations(); - invidiousExtendDescElement.checked = youtubeHelper.getInvidiousExtendDesc(); - invidiousVrModeElement.checked = youtubeHelper.getInvidiousVrMode(); - invidiousSavePlayerPosElement.checked = youtubeHelper.getInvidiousSavePlayerPos(); - - commonHelper.processDefaultCustomInstances( - 'invidious', - 'normal', - youtubeHelper, - document, - youtubeHelper.getInvidiousNormalRedirectsChecks, - youtubeHelper.setInvidiousNormalRedirectsChecks, - youtubeHelper.getInvidiousNormalCustomRedirects, - youtubeHelper.setInvidiousNormalCustomRedirects - ); - - commonHelper.processDefaultCustomInstances( - 'invidious', - 'tor', - youtubeHelper, - document, - youtubeHelper.getInvidiousTorRedirectsChecks, - youtubeHelper.setInvidiousTorRedirectsChecks, - youtubeHelper.getInvidiousTorCustomRedirects, - youtubeHelper.setInvidiousTorCustomRedirects - ); -}); \ No newline at end of file +init() \ No newline at end of file diff --git a/src/pages/options/youtube/piped.js b/src/pages/options/youtube/piped.js index 5f388d6..e0495e7 100644 --- a/src/pages/options/youtube/piped.js +++ b/src/pages/options/youtube/piped.js @@ -1,257 +1,132 @@ import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js"; -let pipedSponsorblockElement = document.getElementById("piped-sponsorblock"); -pipedSponsorblockElement.addEventListener("change", - event => youtubeHelper.setPipedSponsorblock(event.target.checked) -); +let pipedElement = document.getElementById('piped'); +let pipedListenElement = pipedElement.getElementsByClassName("listen")[0]; +let pipedQualityElement = pipedElement.getElementsByClassName("quality")[0]; +let pipedBufferGoalElement = pipedElement.getElementsByClassName("bufferGoal")[0]; +let pipedRegionElement = pipedElement.getElementsByClassName("region")[0]; +let pipedHomepageElement = pipedElement.getElementsByClassName("homepage")[0]; +let pipedCommentsElement = pipedElement.getElementsByClassName("comments")[0]; +let pipedMinimizeDescriptionElement = pipedElement.getElementsByClassName("minimizeDescription")[0]; +let pipedWatchHistoryElement = pipedElement.getElementsByClassName("watchHistory")[0]; +let pipedDisableLBRYElement = pipedElement.getElementsByClassName("disableLBRY")[0]; +let pipedProxyLBRYElement = pipedElement.getElementsByClassName("proxyLBRY")[0]; + +let pipedSelectedSkipSponsorElement = pipedElement.getElementsByClassName("selectedSkip-sponsor")[0]; +let pipedSelectedSkipIntroElement = pipedElement.getElementsByClassName("selectedSkip-intro")[0]; +let pipedSelectedSkipOutroElement = pipedElement.getElementsByClassName("selectedSkip-outro")[0]; +let pipedSelectedSkipPreviewElement = pipedElement.getElementsByClassName("selectedSkip-preview")[0]; +let pipedSelectedSkipInteractionElement = pipedElement.getElementsByClassName("selectedSkip-interaction")[0]; +let pipedSelectedSkipSelfpromoElement = pipedElement.getElementsByClassName("selectedSkip-selfpromo")[0]; +let pipedSelectedSkipMusicOfftopicElement = pipedElement.getElementsByClassName("selectedSkip-music_offtopic")[0]; +let pipedSelectedSkipPoiHighlightElement = pipedElement.getElementsByClassName("selectedSkip-poi_highlight")[0]; +let pipedSelectedSkipFillerElement = pipedElement.getElementsByClassName("selectedSkip-filler")[0]; + +let pipedSponsorblockElement = pipedElement.getElementsByClassName("sponsorblock")[0]; +let pipedEnabledCodecsElement = pipedElement.getElementsByClassName("enabledCodecs")[0]; +let autoplayElement = pipedElement.getElementsByClassName("youtubeAutoplay")[0]; + +let volumeElement = pipedElement.getElementsByClassName("volume")[0]; +let volumeValueElement = pipedElement.getElementsByClassName("volume-value")[0]; + +volumeElement.addEventListener("input", () => volumeValueElement.textContent = `${volumeElement.value}%`); function selectSkipModify(value, boolean) { - if (boolean) { - if (!selectSkip.includes(value)) selectSkip.push(value); + if (boolean && !selectSkip.includes(value)) { + selectSkip.push(value); } - else { + else if (!boolean) { let i = selectSkip.indexOf(value); if (i > -1) selectSkip.splice(i, 1); } - youtubeHelper.setPipedSelectedSkip(selectSkip) } - -let pipedSelectedSkipSponsorElement = document.getElementById("piped-selectedSkip-sponsor"); -pipedSelectedSkipSponsorElement.addEventListener("change", - event => selectSkipModify('sponsor', event.target.checked) -); - -let pipedSelectedSkipIntroElement = document.getElementById("piped-selectedSkip-intro"); -pipedSelectedSkipIntroElement.addEventListener("change", - event => selectSkipModify('intro', event.target.checked) -); - -let pipedSelectedSkipOutroElement = document.getElementById("piped-selectedSkip-outro"); -pipedSelectedSkipOutroElement.addEventListener("change", - event => selectSkipModify('outro', event.target.checked) -); - -let pipedSelectedSkipPreviewElement = document.getElementById("piped-selectedSkip-preview"); -pipedSelectedSkipPreviewElement.addEventListener("change", - event => selectSkipModify('preview', event.target.checked) -); - -let pipedSelectedSkipInteractionElement = document.getElementById("piped-selectedSkip-interaction"); -pipedSelectedSkipInteractionElement.addEventListener("change", - event => selectSkipModify('interaction', event.target.checked) -); - -let pipedSelectedSkipSelfpromoElement = document.getElementById("piped-selectedSkip-selfpromo"); -pipedSelectedSkipSelfpromoElement.addEventListener("change", - event => selectSkipModify('selfpromo', event.target.checked) -); - -let pipedSelectedSkipMusicOfftopicElement = document.getElementById("piped-selectedSkip-music_offtopic"); -pipedSelectedSkipMusicOfftopicElement.addEventListener("change", - event => selectSkipModify('music_offtopic', event.target.checked) -); - -let pipedSelectedSkipPoiHighlightElement = document.getElementById("piped-selectedSkip-poi_highlight"); -pipedSelectedSkipPoiHighlightElement.addEventListener("change", - event => selectSkipModify('poi_highlight', event.target.checked) -); - -let pipedSelectedSkipFillerElement = document.getElementById("piped-selectedSkip-filler"); -pipedSelectedSkipFillerElement.addEventListener("change", - event => selectSkipModify('filler', event.target.checked) -); - -let pipedListenElement = document.getElementById("piped-listen"); -pipedListenElement.addEventListener("change", - event => youtubeHelper.setYoutubeListen(event.target.checked) -); - -let pipedQualityElement = document.getElementById("piped-quality"); -pipedQualityElement.addEventListener("change", - event => youtubeHelper.setPipedQuality(event.target.options[pipedQualityElement.selectedIndex].value) -); - -let pipedBufferGoalElement = document.getElementById("piped-bufferGoal"); -pipedBufferGoalElement.addEventListener("change", - event => youtubeHelper.setPipedBufferGoal(pipedBufferGoalElement.value) -); - -let pipedRegionElement = document.getElementById("piped-region"); -pipedRegionElement.addEventListener("change", - event => youtubeHelper.setPipedRegion(event.target.options[pipedRegionElement.selectedIndex].value) -); - -let pipedHomepageElement = document.getElementById("piped-homepage"); -pipedHomepageElement.addEventListener("change", - event => youtubeHelper.setPipedHomepage(event.target.options[pipedHomepageElement.selectedIndex].value) -); - -let pipedCommentsElement = document.getElementById("piped-comments"); -pipedCommentsElement.addEventListener("change", - event => youtubeHelper.setPipedComments(event.target.checked) -); - -let pipedMinimizeDescriptionElement = document.getElementById("piped-minimizeDescription"); -pipedMinimizeDescriptionElement.addEventListener("change", - event => youtubeHelper.setPipedMinimizeDescription(event.target.checked) -); - -let pipedWatchHistoryElement = document.getElementById("piped-watchHistory"); -pipedWatchHistoryElement.addEventListener("change", - event => youtubeHelper.setPipedWatchHistory(event.target.checked) -); - -let pipedEnabledCodecsElement = document.getElementById("piped-enabledCodecs"); -pipedEnabledCodecsElement.addEventListener("change", - () => { - let result = []; - for (const opt of pipedEnabledCodecsElement.options) - if (opt.selected) result.push(opt.value); - youtubeHelper.setPipedEnabledCodecs(result); - } -); - -let pipedDisableLBRYElement = document.getElementById("piped-disableLBRY"); -pipedDisableLBRYElement.addEventListener("change", - event => youtubeHelper.setPipedDisableLBRY(event.target.checked) -); - -let pipedProxyLBRYElement = document.getElementById("piped-proxyLBRY"); -pipedProxyLBRYElement.addEventListener("change", - event => youtubeHelper.setPipedProxyLBRY(event.target.checked) -); - -let pipedMaterialListenElement = document.getElementById("pipedMaterial-listen"); -pipedMaterialListenElement.addEventListener("change", - event => youtubeHelper.setYoutubeListen(event.target.checked) -); - -let pipedMaterialDisableLBRYElement = document.getElementById("pipedMaterial-disableLBRY"); -pipedMaterialDisableLBRYElement.addEventListener("change", - event => youtubeHelper.setPipedDisableLBRY(event.target.checked) -); - -let pipedMaterialProxyLBRYElement = document.getElementById("pipedMaterial-proxyLBRY"); -pipedMaterialProxyLBRYElement.addEventListener("change", - event => youtubeHelper.setPipedProxyLBRY(event.target.checked) -); - -let pipedMaterialSponsorblockElement = document.getElementById("pipedMaterial-sponsorblock"); -pipedMaterialSponsorblockElement.addEventListener("change", - event => youtubeHelper.setPipedSponsorblock(event.target.checked) -); - -let pipedMaterialSkipToLastPointElement = document.getElementById("pipedMaterial-skipToLastPoint"); -pipedMaterialSkipToLastPointElement.addEventListener("change", - event => youtubeHelper.setPipedMaterialSkipToLastPoint(event.target.checked) -); - - -let pipedMaterialSelectedSkipSponsorElement = document.getElementById("pipedMaterial-selectedSkip-sponsor"); -pipedMaterialSelectedSkipSponsorElement.addEventListener("change", - event => selectSkipModify('sponsor', event.target.checked) -); - -let pipedMaterialSelectedSkipIntroElement = document.getElementById("pipedMaterial-selectedSkip-intro"); -pipedMaterialSelectedSkipIntroElement.addEventListener("change", - event => selectSkipModify('intro', event.target.checked) -); - -let pipedMaterialSelectedSkipOutroElement = document.getElementById("pipedMaterial-selectedSkip-outro"); -pipedMaterialSelectedSkipOutroElement.addEventListener("change", - event => selectSkipModify('outro', event.target.checked) -); - -let pipedMaterialSelectedSkipPreviewElement = document.getElementById("pipedMaterial-selectedSkip-preview"); -pipedMaterialSelectedSkipPreviewElement.addEventListener("change", - event => selectSkipModify('preview', event.target.checked) -); - -let pipedMaterialSelectedSkipInteractionElement = document.getElementById("pipedMaterial-selectedSkip-interaction"); -pipedMaterialSelectedSkipInteractionElement.addEventListener("change", - event => selectSkipModify('interaction', event.target.checked) -); - -let pipedMaterialSelectedSkipSelfpromoElement = document.getElementById("pipedMaterial-selectedSkip-selfpromo"); -pipedMaterialSelectedSkipSelfpromoElement.addEventListener("change", - event => selectSkipModify('selfpromo', event.target.checked) -); - -let pipedMaterialSelectedSkipMusicOfftopicElement = document.getElementById("pipedMaterial-selectedSkip-music_offtopic"); -pipedMaterialSelectedSkipMusicOfftopicElement.addEventListener("change", - event => selectSkipModify('music_offtopic', event.target.checked) -); - -let pipedMaterialSelectedSkipPoiHighlightElement = document.getElementById("pipedMaterial-selectedSkip-poi_highlight"); -pipedMaterialSelectedSkipPoiHighlightElement.addEventListener("change", - event => selectSkipModify('poi_highlight', event.target.checked) -); - -let pipedMaterialSelectedSkipFillerElement = document.getElementById("pipedMaterial-selectedSkip-filler"); -pipedMaterialSelectedSkipFillerElement.addEventListener("change", - event => selectSkipModify('filler', event.target.checked) -); - let selectSkip = []; -youtubeHelper.init().then(() => { +pipedElement.addEventListener("change", async () => { + console.log("changed piped settings"); + let pipedEnabledCodecsResult = []; + for (const opt of pipedEnabledCodecsElement.options) + if (opt.selected) pipedEnabledCodecsResult.push(opt.value); - pipedSponsorblockElement.checked = youtubeHelper.getPipedSponsorblock(); - selectSkip = youtubeHelper.getPipedSelectedSkip(); - pipedSelectedSkipSponsorElement.checked = selectSkip.includes('sponsor'); - pipedSelectedSkipIntroElement.checked = selectSkip.includes('intro'); - pipedSelectedSkipOutroElement.checked = selectSkip.includes('outro'); - pipedSelectedSkipPreviewElement.checked = selectSkip.includes('preview'); - pipedSelectedSkipInteractionElement.checked = selectSkip.includes('interaction'); - pipedSelectedSkipSelfpromoElement.checked = selectSkip.includes('selfpromo'); - pipedSelectedSkipMusicOfftopicElement.checked = selectSkip.includes('music_offtopic'); - pipedSelectedSkipPoiHighlightElement.checked = selectSkip.includes('poi_highlight'); - pipedSelectedSkipFillerElement.checked = selectSkip.includes('filler'); - pipedListenElement.checked = youtubeHelper.getYoutubeListen(); - pipedQualityElement.value = youtubeHelper.getPipedQuality(); - pipedBufferGoalElement.value = youtubeHelper.getPipedBufferGoal(); - pipedRegionElement.value = youtubeHelper.getPipedRegion(); - pipedHomepageElement.value = youtubeHelper.getPipedHomepage(); - pipedCommentsElement.checked = youtubeHelper.getPipedComments(); - pipedMinimizeDescriptionElement.checked = youtubeHelper.getPipedMinimizeDescription(); - pipedWatchHistoryElement.checked = youtubeHelper.getPipedWatchHistory(); - pipedEnabledCodecsElement.value = youtubeHelper.getPipedEnabledCodecs(); - pipedDisableLBRYElement.checked = youtubeHelper.getPipedDisableLBRY(); - pipedProxyLBRYElement.checked = youtubeHelper.getPipedProxyLBRY(); + selectSkipModify('sponsor', pipedSelectedSkipSponsorElement.checked); + selectSkipModify('intro', pipedSelectedSkipIntroElement.checked); + selectSkipModify('outro', pipedSelectedSkipOutroElement.checked); + selectSkipModify('preview', pipedSelectedSkipPreviewElement.checked); + selectSkipModify('interaction', pipedSelectedSkipInteractionElement.checked); + selectSkipModify('selfpromo', pipedSelectedSkipSelfpromoElement.checked); + selectSkipModify('music_offtopic', pipedSelectedSkipMusicOfftopicElement.checked); + selectSkipModify('poi_highlight', pipedSelectedSkipPoiHighlightElement.checked); + selectSkipModify('filler', pipedSelectedSkipFillerElement.checked); - pipedMaterialListenElement.checked = youtubeHelper.getYoutubeListen(); - pipedMaterialDisableLBRYElement.checked = youtubeHelper.getPipedDisableLBRY(); - pipedMaterialProxyLBRYElement.checked = youtubeHelper.getPipedProxyLBRY(); - pipedMaterialSponsorblockElement.checked = youtubeHelper.getPipedSponsorblock() - pipedMaterialSkipToLastPointElement.checked = youtubeHelper.getPipedMaterialSkipToLastPoint(); - pipedMaterialSelectedSkipSponsorElement.checked = selectSkip.includes('sponsor'); - pipedMaterialSelectedSkipIntroElement.checked = selectSkip.includes('intro'); - pipedMaterialSelectedSkipOutroElement.checked = selectSkip.includes('outro'); - pipedMaterialSelectedSkipPreviewElement.checked = selectSkip.includes('preview'); - pipedMaterialSelectedSkipInteractionElement.checked = selectSkip.includes('interaction'); - pipedMaterialSelectedSkipSelfpromoElement.checked = selectSkip.includes('selfpromo'); - pipedMaterialSelectedSkipMusicOfftopicElement.checked = selectSkip.includes('music_offtopic'); - pipedMaterialSelectedSkipPoiHighlightElement.checked = selectSkip.includes('poi_highlight'); - pipedMaterialSelectedSkipFillerElement.checked = selectSkip.includes('filler'); - - commonHelper.processDefaultCustomInstances( - 'piped', - 'normal', - youtubeHelper, - document, - youtubeHelper.getPipedNormalRedirectsChecks, - youtubeHelper.setPipedNormalRedirectsChecks, - youtubeHelper.getPipedNormalCustomRedirects, - youtubeHelper.setPipedNormalCustomRedirects - ); - commonHelper.processDefaultCustomInstances( - 'piped', - 'tor', - youtubeHelper, - document, - youtubeHelper.getPipedTorRedirectsChecks, - youtubeHelper.setPipedTorRedirectsChecks, - youtubeHelper.getPipedTorCustomRedirects, - youtubeHelper.setPipedTorCustomRedirects - ); + await youtubeHelper.setYoutubeSettings({ + pipedQuality: pipedQualityElement.value, + pipedBufferGoal: pipedBufferGoalElement.value, + pipedRegion: pipedRegionElement.value, + pipedHomepage: pipedHomepageElement.value, + pipedComments: pipedCommentsElement.checked, + pipedMinimizeDescription: pipedMinimizeDescriptionElement.checked, + youtubeAutoplay: autoplayElement.checked, + pipedWatchHistory: pipedWatchHistoryElement.checked, + pipedDisableLBRY: pipedDisableLBRYElement.checked, + pipedProxyLBRY: pipedProxyLBRYElement.checked, + youtubeVolume: volumeElement.value, + pipedSponsorblock: pipedSponsorblockElement.checked, + pipedEnabledCodecs: pipedEnabledCodecsResult, + youtubeListen: pipedListenElement.checked, + pipedSelectedSkip: selectSkip, + }); + init(); }); + +function init() { + youtubeHelper.init().then(() => { + pipedSponsorblockElement.checked = youtubeHelper.getPipedSponsorblock(); + selectSkip = youtubeHelper.getPipedSelectedSkip(); + pipedSelectedSkipSponsorElement.checked = selectSkip.includes('sponsor'); + pipedSelectedSkipIntroElement.checked = selectSkip.includes('intro'); + pipedSelectedSkipOutroElement.checked = selectSkip.includes('outro'); + pipedSelectedSkipPreviewElement.checked = selectSkip.includes('preview'); + autoplayElement.checked = youtubeHelper.getAutoplay(); + pipedSelectedSkipInteractionElement.checked = selectSkip.includes('interaction'); + pipedSelectedSkipSelfpromoElement.checked = selectSkip.includes('selfpromo'); + pipedSelectedSkipMusicOfftopicElement.checked = selectSkip.includes('music_offtopic'); + pipedSelectedSkipPoiHighlightElement.checked = selectSkip.includes('poi_highlight'); + pipedSelectedSkipFillerElement.checked = selectSkip.includes('filler'); + pipedListenElement.checked = youtubeHelper.getYoutubeListen(); + pipedQualityElement.value = youtubeHelper.getPipedQuality(); + pipedBufferGoalElement.value = youtubeHelper.getPipedBufferGoal(); + pipedRegionElement.value = youtubeHelper.getPipedRegion(); + pipedHomepageElement.value = youtubeHelper.getPipedHomepage(); + pipedCommentsElement.checked = youtubeHelper.getPipedComments(); + pipedMinimizeDescriptionElement.checked = youtubeHelper.getPipedMinimizeDescription(); + pipedWatchHistoryElement.checked = youtubeHelper.getPipedWatchHistory(); + pipedEnabledCodecsElement.value = youtubeHelper.getPipedEnabledCodecs(); + pipedDisableLBRYElement.checked = youtubeHelper.getPipedDisableLBRY(); + pipedProxyLBRYElement.checked = youtubeHelper.getPipedProxyLBRY(); + + volumeElement.value = youtubeHelper.getVolume(); + volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`; + + commonHelper.processDefaultCustomInstances( + 'piped', + 'normal', + youtubeHelper, + document, + youtubeHelper.getPipedNormalRedirectsChecks, + youtubeHelper.setPipedNormalRedirectsChecks, + youtubeHelper.getPipedNormalCustomRedirects, + youtubeHelper.setPipedNormalCustomRedirects + ); + commonHelper.processDefaultCustomInstances( + 'piped', + 'tor', + youtubeHelper, + document, + youtubeHelper.getPipedTorRedirectsChecks, + youtubeHelper.setPipedTorRedirectsChecks, + youtubeHelper.getPipedTorCustomRedirects, + youtubeHelper.setPipedTorCustomRedirects + ); + }); +} +init(); \ No newline at end of file diff --git a/src/pages/options/youtube/pipedMaterial.js b/src/pages/options/youtube/pipedMaterial.js index 9a8a961..60b2c42 100644 --- a/src/pages/options/youtube/pipedMaterial.js +++ b/src/pages/options/youtube/pipedMaterial.js @@ -1,25 +1,112 @@ import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js"; -youtubeHelper.init().then(() => { - commonHelper.processDefaultCustomInstances( - 'pipedMaterial', - 'normal', - youtubeHelper, - document, - youtubeHelper.getPipedMaterialNormalRedirectsChecks, - youtubeHelper.setPipedMaterialNormalRedirectsChecks, - youtubeHelper.getPipedMaterialNormalCustomRedirects, - youtubeHelper.setPipedMaterialNormalCustomRedirects - ); - commonHelper.processDefaultCustomInstances( - 'pipedMaterial', - 'tor', - youtubeHelper, - document, - youtubeHelper.getPipedMaterialTorRedirectsChecks, - youtubeHelper.setPipedMaterialTorRedirectsChecks, - youtubeHelper.getPipedMaterialTorCustomRedirects, - youtubeHelper.setPipedMaterialTorCustomRedirects - ); +let pipedMaterialElement = document.getElementById('pipedMaterial'); +let listenElement = pipedMaterialElement.getElementsByClassName("listen")[0]; +let disableLBRYElement = pipedMaterialElement.getElementsByClassName("disableLBRY")[0]; +let proxyLBRYElement = pipedMaterialElement.getElementsByClassName("proxyLBRY")[0]; +let sponsorblockElement = pipedMaterialElement.getElementsByClassName("sponsorblock")[0]; +let skipToLastPointElement = pipedMaterialElement.getElementsByClassName("skipToLastPoint")[0]; + +let selectedSkipSponsorElement = pipedMaterialElement.getElementsByClassName("selectedSkip-sponsor")[0]; +let selectedSkipIntroElement = pipedMaterialElement.getElementsByClassName("selectedSkip-intro")[0]; +let selectedSkipOutroElement = pipedMaterialElement.getElementsByClassName("selectedSkip-outro")[0]; +let selectedSkipPreviewElement = pipedMaterialElement.getElementsByClassName("selectedSkip-preview")[0]; +let selectedSkipInteractionElement = pipedMaterialElement.getElementsByClassName("selectedSkip-interaction")[0]; +let selectedSkipSelfpromoElement = pipedMaterialElement.getElementsByClassName("selectedSkip-selfpromo")[0]; +let selectedSkipMusicOfftopicElement = pipedMaterialElement.getElementsByClassName("selectedSkip-music_offtopic")[0]; + +let autoplayElement = pipedMaterialElement.getElementsByClassName("youtubeAutoplay")[0]; + +let volumeElement = pipedMaterialElement.getElementsByClassName("volume")[0]; +let volumeValueElement = pipedMaterialElement.getElementsByClassName("volume-value")[0]; + +volumeElement.addEventListener("input", () => volumeValueElement.textContent = `${volumeElement.value}%`); + +let selectSkip = []; +function selectSkipModify(value, boolean) { + if (boolean && !selectSkip.includes(value)) { + selectSkip.push(value); + } + else if (!boolean) { + let i = selectSkip.indexOf(value); + if (i > -1) selectSkip.splice(i, 1); + } +} +pipedMaterialElement.addEventListener("change", async () => { + console.log("changed piped settings"); + + selectSkipModify('sponsors', selectedSkipSponsorElement.checked); + selectSkipModify('intro', selectedSkipIntroElement.checked); + selectSkipModify('outro', selectedSkipOutroElement.checked); + selectSkipModify('preview', selectedSkipPreviewElement.checked); + selectSkipModify('interaction', selectedSkipInteractionElement.checked); + selectSkipModify('selfpromo', selectedSkipSelfpromoElement.checked); + selectSkipModify('music_offtopic', selectedSkipMusicOfftopicElement.checked); + + await youtubeHelper.setYoutubeSettings({ + youtubeListen: listenElement.checked, + pipedDisableLBRY: disableLBRYElement.checked, + pipedProxyLBRY: proxyLBRYElement.checked, + pipedSponsorblock: sponsorblockElement.checked, + pipedSkipToLastPoint: skipToLastPointElement.checked, + pipedSelectedSkipSponsor: selectedSkipSponsorElement.checked, + pipedSelectedSkipIntro: selectedSkipIntroElement.checked, + pipedSelectedSkipOutro: selectedSkipOutroElement.checked, + youtubeAutoplay: autoplayElement.checked, + youtubeVolume: volumeElement.value, + pipedSelectedSkipPreview: selectedSkipPreviewElement.checked, + pipedSelectedSkipInteraction: selectedSkipInteractionElement.checked, + pipedSelectedSkipSelfpromo: selectedSkipSelfpromoElement.checked, + pipedSelectedSkipMusicOfftopic: selectedSkipMusicOfftopicElement.checked, + + pipedSponsorblock: sponsorblockElement.checked, + pipedMaterialSkipToLastPoint: skipToLastPointElement.checked, + pipedSelectedSkip: selectSkip, + }); + init(); }); + +function init() { + youtubeHelper.init().then(() => { + autoplayElement.checked = youtubeHelper.getAutoplay(); + + listenElement.checked = youtubeHelper.getYoutubeListen(); + disableLBRYElement.checked = youtubeHelper.getPipedDisableLBRY(); + proxyLBRYElement.checked = youtubeHelper.getPipedProxyLBRY(); + sponsorblockElement.checked = youtubeHelper.getPipedSponsorblock(); + skipToLastPointElement.checked = youtubeHelper.getPipedMaterialSkipToLastPoint(); + selectedSkipSponsorElement.checked = selectSkip.includes('sponsors'); + selectedSkipIntroElement.checked = selectSkip.includes('intro'); + selectedSkipOutroElement.checked = selectSkip.includes('outro'); + selectedSkipPreviewElement.checked = selectSkip.includes('preview'); + selectedSkipInteractionElement.checked = selectSkip.includes('interaction'); + selectedSkipSelfpromoElement.checked = selectSkip.includes('selfpromo'); + selectedSkipMusicOfftopicElement.checked = selectSkip.includes('music_offtopic'); + + volumeElement.value = youtubeHelper.getVolume(); + volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`; + + commonHelper.processDefaultCustomInstances( + 'pipedMaterial', + 'normal', + youtubeHelper, + document, + youtubeHelper.getPipedMaterialNormalRedirectsChecks, + youtubeHelper.setPipedMaterialNormalRedirectsChecks, + youtubeHelper.getPipedMaterialNormalCustomRedirects, + youtubeHelper.setPipedMaterialNormalCustomRedirects + ); + commonHelper.processDefaultCustomInstances( + 'pipedMaterial', + 'tor', + youtubeHelper, + document, + youtubeHelper.getPipedMaterialTorRedirectsChecks, + youtubeHelper.setPipedMaterialTorRedirectsChecks, + youtubeHelper.getPipedMaterialTorCustomRedirects, + youtubeHelper.setPipedMaterialTorCustomRedirects + ); + }); +} +init(); \ No newline at end of file diff --git a/src/pages/options/youtube/youtube.html b/src/pages/options/youtube/youtube.html index c118694..95ebb7d 100644 --- a/src/pages/options/youtube/youtube.html +++ b/src/pages/options/youtube/youtube.html @@ -154,7 +154,7 @@
@@ -190,64 +190,47 @@
+
+ +
+

-
-

Autoplay Video

- -
- -
-

Volume: --%

- -
- -
- -
- -
- - -
-
-

Player Style

- -
-

Always loop

- + +
+ +
+

Autoplay Video

+

Play next by default

- +

Autoplay next video

- +

Always proxy videos

- +

Listen by default

- +

Default speed

- @@ -261,7 +244,7 @@

Preferred video quality

- @@ -271,7 +254,7 @@

Preferred DASH video quality

- @@ -288,16 +271,23 @@
+
+

+ Volume: --% +

+ +
+

Default comments

-   - @@ -306,7 +296,7 @@

Default captions

- @@ -439,7 +429,7 @@   - @@ -572,7 +562,7 @@   - @@ -708,47 +698,54 @@

Show related videos

- +

Show annotations by default

- +

Automatically extend video description

- +

Interactive 360 degree videos (requires WebGL)

- +

Save playback position

- + +
+ +
+

Player Style

+

-
- +

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+
+ +
+

Autoplay Video

+ +
+ +
+

+ Volume: --% +

+ +

Enable Sponsorblock

- +

Skip Sponsors

- +

Skip Intermission/Intro Animation

- +

Skip Endcards/Credits

- +

Skip Preview/Recap

- +

Skip Interaction Reminder (Subscribe)

- +

Skip Unpaid/Self Promotion

- +

Skip Music: Non-Music Section

- +

Skip Highlight

- +

Skip Filler Tangent

- +

Audio Only

- +

Default Quality

- @@ -864,12 +873,12 @@

Buffering Goal (in seconds)

- +

Country Selection

- @@ -1068,7 +1077,7 @@

Default Homepage

- @@ -1076,22 +1085,22 @@

Show Comments

- +

Minimize Description by default

- +

Store Watch History

- +

Enabled Codecs (Multiple)

- @@ -1100,30 +1109,31 @@

Disable LBRY for Streaming

- +

Enable Proxy for LBRY

- +
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+

-
-
+
+
+

Autoplay Video

+ +
+ +
+

+ Volume: --% +

+ +
+

Audio Only

- +

Disable LBRY

- +

Proxy LBRY videos

- +

Enable Sponsorblock

- +
-

Skip to the last watched point when encountering a video already seen

- +

Skip to the last watched point when encountering a video already seen +

+

Skip Sponsors

- +

Skip Intermission/Intro Animation

- +

Skip Endcards/Credits

- +

Skip Preview/Recap

- +

Skip Interaction Reminder (Subscribe)

- +

Skip Unpaid/Self Promotion

- +

Skip Music: Non-Music Section

- -
- -
-

Skip Highlight

- -
- -
-

Skip Filler Tangent

- +

-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
-
+

Default Instances

-
+

Custom Instances

-
+
- -
-
+
@@ -1299,4 +1311,4 @@ - + \ No newline at end of file diff --git a/src/pages/options/youtube/youtube.js b/src/pages/options/youtube/youtube.js index 3fec42c..5f91525 100644 --- a/src/pages/options/youtube/youtube.js +++ b/src/pages/options/youtube/youtube.js @@ -1,12 +1,17 @@ import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; +let disableYoutubeElement = document.getElementById("disable-invidious"); let youtubeFrontendElement = document.getElementById("youtube-frontend"); let invidiousDivElement = document.getElementById("invidious"); let pipedDivElement = document.getElementById("piped"); let pipedMaterialDivElement = document.getElementById("pipedMaterial"); -let invidiousPipedPipedMaterialDivElement = document.getElementById("invidious-piped-pipedMaterial"); let freetubeYatteeDivElement = document.getElementById("freetube-yatte"); let customSettingsDivElement = document.getElementsByClassName("custom-settings"); +let youtubeEmbedFrontendElement = document.getElementById("youtube-embed-frontend"); +let enableYoutubeCustomSettingsElement = document.getElementById("enable-youtube-custom-settings"); +let OnlyEmbeddedVideoElement = document.getElementById("only-embed"); +let bypassWatchOnYoutubeElement = document.getElementById("bypass-watch-on-youtube"); +let protocolElement = document.getElementById("protocol"); function changeFrontendsSettings() { let frontend = youtubeFrontendElement.value; @@ -17,28 +22,24 @@ function changeFrontendsSettings() { for (const item of customSettingsDivElement) item.style.display = 'none'; if (frontend == 'invidious') { - invidiousPipedPipedMaterialDivElement.style.display = 'block' invidiousDivElement.style.display = 'block'; pipedDivElement.style.display = 'none'; pipedMaterialDivElement.style.display = 'none'; freetubeYatteeDivElement.style.display = 'none'; } else if (frontend == 'piped') { - invidiousPipedPipedMaterialDivElement.style.display = 'block' invidiousDivElement.style.display = 'none'; pipedDivElement.style.display = 'block'; pipedMaterialDivElement.style.display = 'none'; freetubeYatteeDivElement.style.display = 'none'; } else if (frontend == 'pipedMaterial') { - invidiousPipedPipedMaterialDivElement.style.display = 'block' invidiousDivElement.style.display = 'none'; pipedDivElement.style.display = 'none'; pipedMaterialDivElement.style.display = 'block'; freetubeYatteeDivElement.style.display = 'none'; } else if (frontend == 'freetube' || frontend == 'yatte') { - invidiousPipedPipedMaterialDivElement.style.display = 'none' invidiousDivElement.style.display = 'none'; pipedDivElement.style.display = 'none'; pipedMaterialDivElement.style.display = 'none'; @@ -49,91 +50,28 @@ function changeFrontendsSettings() { function changeYoutubeEmbedFrontendsSettings(youtubeEmbedFrontend) { if (youtubeEmbedFrontend == 'invidious') { - invidiousPipedPipedMaterialDivElement.style.display = 'block' pipedDivElement.style.display = 'none'; invidiousDivElement.style.display = 'block'; } if (youtubeEmbedFrontend == 'piped') { - invidiousPipedPipedMaterialDivElement.style.display = 'block' pipedDivElement.style.display = 'block'; invidiousDivElement.style.display = 'none'; } else if (youtubeEmbedFrontend == 'youtube') { - invidiousPipedPipedMaterialDivElement.style.display = 'none' pipedDivElement.style.display = 'none'; invidiousDivElement.style.display = 'none'; } } -youtubeFrontendElement.addEventListener("change", - event => { - let frontend = event.target.options[youtubeFrontendElement.selectedIndex].value - youtubeHelper.setFrontend(frontend); - changeFrontendsSettings(); - } -); - -let youtubeEmbedFrontendElement = document.getElementById("youtube-embed-frontend"); -youtubeEmbedFrontendElement.addEventListener("change", - event => { - let youtubeEmbedFrontend = event.target.options[youtubeEmbedFrontendElement.selectedIndex].value - youtubeHelper.setYoutubeEmbedFrontend(youtubeEmbedFrontend); - changeYoutubeEmbedFrontendsSettings(youtubeEmbedFrontend); - } -); - -let disableYoutubeElement = document.getElementById("disable-invidious"); -disableYoutubeElement.addEventListener("change", - event => youtubeHelper.setDisable(!event.target.checked) -); - -let enableYoutubeCustomSettingsElement = document.getElementById("enable-youtube-custom-settings"); -enableYoutubeCustomSettingsElement.addEventListener("change", - event => { - youtubeHelper.setEnableCustomSettings(event.target.checked) - changeFrontendsSettings(); - } -); - -let volumeElement = document.getElementById("invidious-volume"); -let volumeValueElement = document.getElementById("volume-value"); - -volumeElement.addEventListener("input", () => volumeValueElement.textContent = `${volumeElement.value}%`); -volumeElement.addEventListener("change", () => youtubeHelper.setVolume(volumeElement.value)); - -let autoplayElement = document.getElementById("invidious-youtubeAutoplay"); -autoplayElement.addEventListener("change", - event => youtubeHelper.setAutoplay(event.target.checked) -); - -let OnlyEmbeddedVideoElement = document.getElementById("only-embed"); -OnlyEmbeddedVideoElement.addEventListener("change", - event => youtubeHelper.setOnlyEmbeddedVideo(event.target.options[OnlyEmbeddedVideoElement.selectedIndex].value) -); - -let bypassWatchOnYoutubeElement = document.getElementById("bypass-watch-on-youtube") -bypassWatchOnYoutubeElement.addEventListener("change", - event => youtubeHelper.setBypassWatchOnYoutube(event.target.checked) -); - -let protocolElement = document.getElementById("protocol") -protocolElement.addEventListener("change", - event => { - let protocol = event.target.options[protocolElement.selectedIndex].value - youtubeHelper.setProtocol(protocol); - changeProtocolSettings(protocol); - } -); - function changeProtocolSettings(protocol) { - let normalPipedDiv = document.getElementById("piped-normal"); - let torPipedDiv = document.getElementById("piped-tor"); + let normalPipedDiv = document.getElementById('piped').getElementsByClassName("normal")[0]; + let torPipedDiv = document.getElementById('piped').getElementsByClassName("tor")[0]; - let normalPipedMaterialDiv = document.getElementById("pipedMaterial-normal"); - let torPipedMaterialDiv = document.getElementById("pipedMaterial-tor"); + let normalPipedMaterialDiv = document.getElementById('pipedMaterial').getElementsByClassName("normal")[0]; + let torPipedMaterialDiv = document.getElementById('pipedMaterial').getElementsByClassName("tor")[0]; - let normalInvidiousDiv = document.getElementById("invidious-normal"); - let torInvidiousDiv = document.getElementById("invidious-tor"); + let normalInvidiousDiv = document.getElementById('invidious').getElementsByClassName("normal")[0]; + let torInvidiousDiv = document.getElementById('invidious').getElementsByClassName("tor")[0]; if (protocol == 'normal') { normalInvidiousDiv.style.display = 'block'; @@ -157,14 +95,29 @@ function changeProtocolSettings(protocol) { } } + +document.addEventListener("change", () => { + youtubeHelper.setYoutubeSettings({ + disableYoutube: !disableYoutubeElement.checked, + youtubeFrontend: youtubeFrontendElement.value, + youtubeEmbedFrontend: youtubeEmbedFrontendElement.value, + enableYoutubeCustomSettings: enableYoutubeCustomSettingsElement.checked, + OnlyEmbeddedVideo: OnlyEmbeddedVideoElement.value, + bypassWatchOnYoutube: bypassWatchOnYoutubeElement.checked, + youtubeProtocol: protocolElement.value, + }) + changeYoutubeEmbedFrontendsSettings(youtubeEmbedFrontendElement.value); + changeProtocolSettings(protocolElement.value); + changeFrontendsSettings(); +}) + youtubeHelper.init().then(() => { disableYoutubeElement.checked = !youtubeHelper.getDisable(); enableYoutubeCustomSettingsElement.checked = youtubeHelper.getEnableCustomSettings(); - volumeElement.value = youtubeHelper.getVolume(); - volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`; + OnlyEmbeddedVideoElement.value = youtubeHelper.getOnlyEmbeddedVideo(); bypassWatchOnYoutubeElement.checked = youtubeHelper.getBypassWatchOnYoutube(); - autoplayElement.checked = youtubeHelper.getAutoplay(); + let frontend = youtubeHelper.getFrontend(); youtubeFrontendElement.value = frontend; changeFrontendsSettings(); diff --git a/src/pages/stylesheets/styles.css b/src/pages/stylesheets/styles.css index 58f3a62..a98adc2 100644 --- a/src/pages/stylesheets/styles.css +++ b/src/pages/stylesheets/styles.css @@ -90,7 +90,7 @@ select { background-color: var(--bg-secondary); border: none; margin: 0; - width: 200px; + width: 180px; border-radius: 3px; } @@ -108,6 +108,9 @@ section.option-block { width: 700px; margin: 0 50px; } +section.option-block h2{ + margin: 0; +} body.option { display: flex;