From c5a6623e0f320b2a789e0d2667ccfe2e1bd4335f Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Mon, 30 May 2022 01:02:59 +0300 Subject: Fixed settings theme and translation flashing #286 --- src/pages/popup/popup.html | 38 +++++++++---------- src/pages/popup/popup.js | 93 ++++++++++++++++++++++------------------------ src/pages/popup/popup.pug | 41 ++++++++++---------- 3 files changed, 84 insertions(+), 88 deletions(-) (limited to 'src/pages/popup') diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 3eb6ba19..5b00b084 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -8,35 +8,35 @@
-

YouTube

+

YouTube

-

YT Music

+

YT Music

-

Twitter

+

Twitter

-

Instagram

+

Instagram

-

TikTok

+

TikTok

-

Imgur

+

Imgur

-

Reddit

+

Reddit

-

Wikipedia

+

Wikipedia

@@ -45,63 +45,63 @@ -

Medium

+

Medium

-

PeerTube

+

PeerTube

-

LBRY

+

LBRY

-

Translate

+

Translate

-

Maps

+

Maps

-

Send Files

+

Send Files


-

Change Instance

+

Change Instance

-

Copy Raw

+

Copy Raw

-

Unify Settings

+

Unify Settings

-

Settings

+

Settings

diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 73890b07..5d309f63 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -1,8 +1,42 @@ "use strict"; window.browser = window.browser || window.chrome; -import utils from "../../assets/javascripts/helpers/utils.js"; -import generalHelper from "../../assets/javascripts/helpers/general.js"; +import utils from "../../assets/javascripts/utils.js"; +import generalHelper from "../../assets/javascripts/general.js"; + +utils.unify(true).then(r => { + if (!r) document.getElementById('unify_div').style.display = 'none'; + else { + const unify = document.getElementById('unify'); + unify.addEventListener("click", () => + browser.runtime.sendMessage({ function: 'unify' }, + response => { + if (response && response.response) { + const textElement = document.getElementById('unify').getElementsByTagName('h4')[0] + const oldHtml = textElement.innerHTML; + textElement.innerHTML = browser.i18n.getMessage('unified'); + setTimeout(() => textElement.innerHTML = oldHtml, 1000); + } + }) + ); + } +}) + +utils.switchInstance(true).then(r => { + if (!r) document.getElementById("change_instance_div").style.display = 'none'; + else document.getElementById("change_instance").addEventListener("click", () => utils.switchInstance(false)); +}); + +utils.copyRaw(true).then(r => { + if (!r) document.getElementById('copy_raw_div').style.display = 'none'; + else { + const copy_raw = document.getElementById('copy_raw'); + copy_raw.addEventListener("click", () => utils.copyRaw(false, copy_raw)); + } +}) + +document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage()); + let disableTwitterElement = document.getElementById("disable-nitter"); let disableYoutubeElement = document.getElementById("disable-youtube"); @@ -37,6 +71,8 @@ browser.storage.local.get( "disablePeertubeTargets", "disableLbryTargets", "disableSendTarget", + + 'popupFrontends', ], r => { disableTwitterElement.checked = !r.disableTwitter; @@ -53,7 +89,13 @@ browser.storage.local.get( disableMediumElement.checked = !r.disableMedium; disablePeertubeElement.checked = !r.disablePeertubeTargets; disableLbryElement.checked = !r.disableLbryTargets; - disableSendTargetsElement.checked = r.disableSendTarget; + disableSendTargetsElement.checked = !r.disableSendTarget; + + for (const frontend of generalHelper.allPopupFrontends) + if (!r.popupFrontends.includes(frontend)) + document.getElementById(frontend).classList.add("hide") + else + document.getElementById(frontend).classList.remove("hide") } ) @@ -77,51 +119,6 @@ document.addEventListener("change", () => { }); }) -utils.switchInstance(true).then(r => { - if (!r) document.getElementById("change_instance_div").style.display = 'none'; - else document.getElementById("change_instance").addEventListener("click", () => utils.switchInstance(false)); -}); - -utils.copyRaw(true).then(r => { - if (!r) document.getElementById('copy_raw_div').style.display = 'none'; - else { - const copy_raw = document.getElementById('copy_raw'); - copy_raw.addEventListener("click", () => utils.copyRaw(false, copy_raw)); - } -}) - - -utils.unify(true).then(r => { - if (!r) document.getElementById('unify_div').style.display = 'none'; - else { - const unify = document.getElementById('unify'); - unify.addEventListener("click", () => - browser.runtime.sendMessage({ function: 'unify' }, - response => { - if (response && response.response) { - const textElement = document.getElementById('unify').getElementsByTagName('h4')[0] - const oldHtml = textElement.innerHTML; - textElement.innerHTML = 'Unified'; - setTimeout(() => textElement.innerHTML = oldHtml, 1000); - } - }) - ); - } -}) - -document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage()); - -browser.storage.local.get( - 'popupFrontends', - r => { - for (const frontend of generalHelper.allPopupFrontends) - if (!r.popupFrontends.includes(frontend)) - document.getElementById(frontend).classList.add("hide") - else - document.getElementById(frontend).classList.remove("hide") - } -); - for (const a of document.getElementsByTagName('a')) { a.addEventListener('click', e => { if (!a.classList.contains('button')) { diff --git a/src/pages/popup/popup.pug b/src/pages/popup/popup.pug index 94f65eae..a2c8de93 100644 --- a/src/pages/popup/popup.pug +++ b/src/pages/popup/popup.pug @@ -11,117 +11,116 @@ html(lang="en") #youtube.some-block a.title(href="https://youtube.com") img(src="../../assets/images/youtube-icon.png") - h4 YouTube + h4(data-localise="__MSG_youtube__") YouTube input#disable-youtube(type="checkbox") #youtubeMusic.some-block a.title(href="https://music.youtube.com") img(src="../../assets/images/youtube-music-icon.png") - h4 YT Music + h4(data-localise="__MSG_ytmusic__") YT Music input#disable-youtubeMusic(type="checkbox") #twitter.some-block a.title(href="https://twitter.com") img(src="../../assets/images/twitter-icon.png") - h4 Twitter + h4(data-localise="__MSG_twitter__") Twitter input#disable-nitter(type="checkbox") #instagram.some-block a.title(href="https://instagram.com") img(src="../../assets/images/instagram-icon.png") - h4 Instagram + h4(data-localise="__MSG_instagram__") Instagram input#disable-bibliogram(type="checkbox") #tikTok.some-block a.title(href="https://tiktok.com") img(src="../../assets/images/tiktok-icon.png") - h4 TikTok + h4(data-localise="__MSG_tiktok__") TikTok input#disable-tiktok(type="checkbox") #imgur.some-block a.title(href="https://imgur.com") img(src="../../assets/images/imgur-icon.png") - h4 Imgur + h4(data-localise="__MSG_imgur__") Imgur input#disable-imgur(type="checkbox") #reddit.some-block a.title(href="https://reddit.com") img(src="../../assets/images/reddit-icon.png") - h4 Reddit + h4(data-localise="__MSG_reddit__") Reddit input#disable-reddit(type="checkbox") #wikipedia.some-block a.title(href="https://wikipedia.com") img(src="../../assets/images/wikipedia-icon.svg") - h4 Wikipedia + h4(data-localise="__MSG_wikipedia__") Wikipedia input#disable-wikipedia(type="checkbox") #medium.some-block a.title(href="https://medium.com") +medium - h4 Medium + h4(data-localise="__MSG_medium__") Medium input#disable-medium(type="checkbox") #peertube.some-block a.title(href="https://search.joinpeertube.org") img(src="../../assets/images/peertube-icon.svg") - h4 PeerTube + h4(data-localise="__MSG_peertube__") PeerTube input#disable-peertube(type="checkbox") #lbry.some-block a.title(href="https://odysee.com/") img(src="../../assets/images/lbry-icon.png") - h4 LBRY + h4(data-localise="__MSG_lbry__") LBRY input#disable-lbry(type="checkbox") #search.some-block a.title(href="https://search.libredirect.invalid") +search - h4 Search + h4(data-localise="__MSG_search__") Search input#disable-search(type="checkbox") #translate.some-block a.title(href="https://translate.google.com") +translate - h4 Translate + h4(data-localise="__MSG_translate__") Translate input#disable-simplyTranslate(type="checkbox") #maps.some-block a.title(href="https://www.openstreetmap.org") +maps - h4 Maps + h4(data-localise="__MSG_maps__") Maps input#disable-osm(type="checkbox") #sendTargets.some-block a.title(href="https://send.libredirect.invalid") +send - h4 Send Files + h4(data-localise="__MSG_sendFiles__") Send Files input#disable-sendTargets(type="checkbox") hr #change_instance_div.some-block a#change_instance.title.button - h4 Change Instance + h4(data-localise="__MSG_switchInstance__") Change Instance +change_instance #copy_raw_div.some-block(title="Copy the original redirected link") a#copy_raw.title.button - h4 Copy Raw + h4(data-localise="__MSG_copyRaw__") Copy Raw +copy_raw #unify_div.some-block(title="Unify cookies across all selected instances") a#unify.title.button - h4 Unify Settings + h4(data-localise="__MSG_unifySettings__") Unify Settings +unify .some-block a#more-options.title.button - h4 Settings + h4(data-localise="__MSG_settings__") Settings +settings .space script(type="module" src="../options/init.js") - script(type="module" src="./popup.js") - //- script(src="../../assets/javascripts/localise.js") \ No newline at end of file + script(type="module" src="./popup.js") \ No newline at end of file -- cgit 1.4.1