From ab44fd04ffa1055bd17a3da02017e8de3da88af2 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 15 May 2022 18:44:28 +0300 Subject: Complete on supporting Unify #234 --- src/pages/popup/popup.html | 291 +++++++++++++++++---------------------------- src/pages/popup/popup.js | 108 ++++++++++------- src/pages/popup/popup.pug | 123 +++++++++++++++++++ 3 files changed, 298 insertions(+), 224 deletions(-) create mode 100644 src/pages/popup/popup.pug (limited to 'src/pages/popup') diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 68831940..0cd1a4f7 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -1,183 +1,112 @@ - - - - - - - - - - -
- - -

YouTube

-
- -
- -
- - -

YT Music

-
- -
- -
- - -

Twitter

-
- -
- -
- - - -

Instagram

-
- -
- -
- - - -

TikTok

-
- -
- -
- - -

Imgur

-
- -
- -
- - - -

Reddit

-
- -
- -
- - -

Wikipedia

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

Medium

-
- -
- -
- - -

Peertube

-
- -
- -
- - -

LBRY

-
- -
- - -
- - - - -

Translate

-
- -
- -
- - - - - -

Maps

-
- -
- -
- - - - -

Send Files

-
- -
- -
- - - - - Instance - - - - - - Settings - - - - - - Copy Raw - -
- - - - - - + + + + + + + + +
+

YouTube

+ +
+
+

YT Music

+ +
+
+

Twitter

+ +
+
+

Instagram

+ +
+
+

TikTok

+ +
+
+

Imgur

+ +
+
+

Reddit

+ +
+
+

Wikipedia

+ +
+
+ + + + + +

Medium

+ +
+
+

Peertube

+ +
+
+

LBRY

+ +
+ +
+ + + +

Translate

+ +
+
+ + + +

Maps

+ +
+
+ + + +

Send Files

+ +
+
+ + + +

Change Instance

+
+ + + +

Settings

+
+ + + +

Copy Raw

+
+ + + + +

Unify Settings

+ + + + \ No newline at end of file diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index e3f52baf..61e0ee1b 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -36,6 +36,8 @@ let disableImgurElement = document.getElementById("disable-imgur"); let disableTiktokElement = document.getElementById("disable-tiktok"); let copyRawElement = document.getElementById('copy_raw'); +let unifyElement = document.getElementById('unify'); + browser.storage.local.get( [ "disableTwitter", @@ -93,38 +95,60 @@ document.addEventListener("change", () => { }); }) - let changeInstanceElement = document.getElementById("change-instance") changeInstanceElement.addEventListener("click", switchInstance); copyRawElement.addEventListener("click", copyRaw); +document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage()); +unifyElement.addEventListener("click", unify) +function unify() { + browser.tabs.query( + { active: true, currentWindow: true }, + async tabs => { + let currTab = tabs[0] + if (currTab) { + let url = new URL(currTab.url); -document.getElementById("more-options").addEventListener("click", - () => browser.runtime.openOptionsPage() -); + let result = await youtubeHelper.initInvidiousCookies(url); + if (!result) result = await youtubeHelper.copyPipedLocalStorage(url, currTab.id); + if (!result) result = await twitterHelper.initNitterCookies(url); + if (!result) result = await redditHelper.initLibredditCookies(url); + if (!result) result = await redditHelper.initTedditCookies(url); + if (!result) result = await redditHelper.initSearxCookies(url); + if (!result) result = await redditHelper.initSearxngCookies(url); + if (!result) result = await tiktokHelper.initProxiTokCookies(url); + if (!result) result = await tiktokHelper.initWikilessCookies(url); + + if (result) { + const textElement = unifyElement.getElementsByTagName('h4')[0] + const oldHtml = textElement.innerHTML; + textElement.innerHTML = 'Unified'; + setTimeout(() => textElement.innerHTML = oldHtml, 1000); + } + } + } + ) +} function switchInstance() { browser.tabs.query({ active: true, currentWindow: true }, async tabs => { let currTab = tabs[0]; if (currTab) { - let url = currTab.url; - let tabUrl - try { tabUrl = new URL(url); } - catch (_) { return false; } + let url = new URL(currTab.url); let newUrl; - // newUrl = youtubeHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = twitterHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = instagramHelper.switchInstance(tabUrl); - if (!newUrl) newUrl = await redditHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = searchHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = translateHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = mediumHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = sendTargetsHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = peertubeHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = lbryHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = imgurHelper.switchInstance(tabUrl); - // if (!newUrl) newUrl = wikipediaHelper.switchInstance(tabUrl); + // newUrl = youtubeHelper.switchInstance(url); + // if (!newUrl) newUrl = twitterHelper.switchInstance(url); + // if (!newUrl) newUrl = instagramHelper.switchInstance(url); + if (!newUrl) newUrl = await redditHelper.switchInstance(url); + // if (!newUrl) newUrl = searchHelper.switchInstance(url); + // if (!newUrl) newUrl = translateHelper.switchInstance(url); + // if (!newUrl) newUrl = mediumHelper.switchInstance(url); + // if (!newUrl) newUrl = sendTargetsHelper.switchInstance(url); + // if (!newUrl) newUrl = peertubeHelper.switchInstance(url); + // if (!newUrl) newUrl = lbryHelper.switchInstance(url); + // if (!newUrl) newUrl = imgurHelper.switchInstance(url); + // if (!newUrl) newUrl = wikipediaHelper.switchInstance(url); if (newUrl) { browser.tabs.update({ url: newUrl }); @@ -136,31 +160,29 @@ function switchInstance() { } function copyRaw() { - browser.tabs.query({ active: true, currentWindow: true }, function (tabs) { - let currTab = tabs[0]; - if (currTab) { - let url = currTab.url; - let tabUrl - try { tabUrl = new URL(url); } - catch (_) { return false; } - let newUrl; - newUrl = youtubeHelper.reverse(tabUrl); - if (!newUrl) newUrl = twitterHelper.reverse(tabUrl); - if (!newUrl) newUrl = instagramHelper.reverse(tabUrl); - if (!newUrl) newUrl = tiktokHelper.reverse(tabUrl); - if (!newUrl) newUrl = imgurHelper.reverse(tabUrl); - if (newUrl) { - navigator.clipboard.writeText(newUrl); - const oldHtml = copyRawElement.innerHTML; - copyRawElement.innerHTML = ` - - - - Copied`; - setTimeout(() => copyRawElement.innerHTML = oldHtml, 1000); + browser.tabs.query( + { active: true, currentWindow: true }, tabs => { + let currTab = tabs[0]; + if (currTab) { + let url = new URL(currTab.url); + let newUrl; + newUrl = youtubeHelper.reverse(url); + + if (!newUrl) newUrl = twitterHelper.reverse(url); + if (!newUrl) newUrl = instagramHelper.reverse(url); + if (!newUrl) newUrl = tiktokHelper.reverse(url); + if (!newUrl) newUrl = imgurHelper.reverse(url); + + if (newUrl) { + navigator.clipboard.writeText(newUrl); + const textElement = copyRawElement.getElementsByTagName('h4')[0] + const oldHtml = textElement.innerHTML; + textElement.innerHTML = 'Copied'; + setTimeout(() => textElement.innerHTML = oldHtml, 1000); + } } } - }) + ) } let popupFrontends; diff --git a/src/pages/popup/popup.pug b/src/pages/popup/popup.pug new file mode 100644 index 00000000..f2cc4635 --- /dev/null +++ b/src/pages/popup/popup.pug @@ -0,0 +1,123 @@ +include ../widgets/icons.pug + +doctype html +html(lang="en") + head + meta(charset="utf-8") + meta(name="viewport" content="width=device-width, initial-scale=1") + link(href="../stylesheets/styles.css" rel="stylesheet") + link(href="./style.css" rel="stylesheet") + body(dir="auto") + #youtube.some-block + a.title(href="https://youtube.com") + img(src="../../assets/images/youtube-icon.png") + h4 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 + input#disable-youtubeMusic(type="checkbox") + + #twitter.some-block + a.title(href="https://twitter.com") + img(src="../../assets/images/twitter-icon.png") + h4 Twitter + input#disable-nitter(type="checkbox") + + #instagram.some-block + a.title(href="https://instagram.com") + img(src="../../assets/images/instagram-icon.png") + h4 Instagram + input#disable-bibliogram(type="checkbox") + + #tikTok.some-block + a.title(href="https://tiktok.com") + img(src="../../assets/images/tiktok-icon.png") + h4 TikTok + input#disable-tiktok(type="checkbox") + + #imgur.some-block + a.title(href="https://imgur.com") + img(src="../../assets/images/imgur-icon.png") + h4 Imgur + input#disable-imgur(type="checkbox") + + #reddit.some-block + a.title(href="https://reddit.com") + img(src="../../assets/images/reddit-icon.png") + h4 Reddit + input#disable-reddit(type="checkbox") + + #wikipedia.some-block + a.title(href="https://wikipedia.com") + img(src="../../assets/images/wikipedia-icon.png") + h4 Wikipedia + input#disable-wikipedia(type="checkbox") + + #medium.some-block + a.title(href="https://medium.com") + +medium + h4 Medium + input#disable-medium(type="checkbox") + + #peertube.some-block + a.title(href="https://peertube.com") + img(src="../../assets/images/peertube-icon.png") + h4 Peertube + input#disable-peertube(type="checkbox") + + #lbry.some-block + a.title(href="https://lbry.com") + img(src="../../assets/images/lbry-icon.png") + h4 LBRY + input#disable-lbry(type="checkbox") + + #search.some-block + a.title(href="https://search.com") + +search + h4 Search + input#disable-search(type="checkbox") + + #translate.some-block + a.title(href="https://translate.com") + +translate + h4 Translate + input#disable-simplyTranslate(type="checkbox") + + #maps.some-block + a.title(href="https://maps.com") + +maps + h4 Maps + input#disable-osm(type="checkbox") + + #sendTargets.some-block + a.title(href="https://send.invalid") + +send + h4 Send Files + input#disable-sendTargets(type="checkbox") + + .some-block + a#change-instance.title.button + +change_instance + h4 Change Instance + + .some-block + a#more-options.title.button + +settings + h4 Settings + + .some-block(title="Copy the original redirected link") + a#copy_raw.title.button + +copy_raw + h4 Copy Raw + + .some-block(title="Unify cookies across all selected instances") + a#unify.title.button + +unify + h4 Unify Settings + + 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 -- cgit 1.4.1