about summary refs log tree commit diff stats
path: root/src/pages/popup
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2022-05-21 01:46:47 +0300
committerManeraKai <manerakai@protonmail.com>2022-05-21 01:46:47 +0300
commitebc9bf35a60325330c6403fbd26987a0f864422b (patch)
treeb1df80514c6dedb2384bad50468bc9cb8f57777c /src/pages/popup
parentAlligned Buttons in Extension Popup (#267) (diff)
downloadlibredirect-ebc9bf35a60325330c6403fbd26987a0f864422b.zip
Cleaned code. Added shortcuts for the CopyRaw btn #268
Diffstat (limited to 'src/pages/popup')
-rw-r--r--src/pages/popup/popup.html5
-rw-r--r--src/pages/popup/popup.js124
-rw-r--r--src/pages/popup/popup.pug6
-rw-r--r--src/pages/popup/style.css9
4 files changed, 12 insertions, 132 deletions
diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html
index b4086ffd..b815bc1d 100644
--- a/src/pages/popup/popup.html
+++ b/src/pages/popup/popup.html
@@ -70,7 +70,7 @@
         <h4>Translate</h4></a>
       <input id="disable-simplyTranslate" type="checkbox">
     </div>
-    <div class="some-block" id="maps"><a class="title" href="https://maps.com">
+    <div class="some-block" id="maps"><a class="title" href="https://www.openstreetmap.org">
         <svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
           <path d="M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM10 5.47l4 1.4v11.66l-4-1.4V5.47zm-5 .99l3-1.01v11.7l-3 1.16V6.46zm14 11.08l-3 1.01V6.86l3-1.16v11.84z"></path>
         </svg>
@@ -84,7 +84,7 @@
         <h4>Send Files</h4></a>
       <input id="disable-sendTargets" type="checkbox">
     </div>
-    <div class="some-block"><a class="title button" id="change-instance">
+    <div class="some-block"><a class="title button" id="change_instance">
         <svg xmlns="http://www.w3.org/2000/svg" height="26px" viewBox="0 0 24 24" width="26px" fill="currentColor">
           <path d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z"></path>
         </svg>
@@ -107,5 +107,6 @@
         <h4>Unify Settings</h4></a></div>
     <script type="module" src="../options/init.js"></script>
     <script type="module" src="./popup.js"></script>
+    <script src="../../assets/javascripts/localise.js"></script>
   </body>
 </html>
\ No newline at end of file
diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js
index c6399aeb..e465a7e0 100644
--- a/src/pages/popup/popup.js
+++ b/src/pages/popup/popup.js
@@ -1,22 +1,7 @@
 "use strict";
 window.browser = window.browser || window.chrome;
 
-import commonHelper from "../../assets/javascripts/helpers/common.js";
-import youtubeHelper from "../../assets/javascripts/helpers/youtube/youtube.js";
-import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js";
-import twitterHelper from "../../assets/javascripts/helpers/twitter.js";
-import instagramHelper from "../../assets/javascripts/helpers/instagram.js";
-import mapsHelper from "../../assets/javascripts/helpers/maps.js";
-import redditHelper from "../../assets/javascripts/helpers/reddit.js";
-import searchHelper from "../../assets/javascripts/helpers/search.js";
-import translateHelper from "../../assets/javascripts/helpers/translate/translate.js";
-import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
-import mediumHelper from "../../assets/javascripts/helpers/medium.js";
-import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
-import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
-import sendTargetsHelper from "../../assets/javascripts/helpers/sendTargets.js";
-import peertubeHelper from "../../assets/javascripts/helpers/peertube.js";
-import lbryHelper from "../../assets/javascripts/helpers/lbry.js";
+import utils from "../../assets/javascripts/helpers/utils.js";
 import generalHelper from "../../assets/javascripts/helpers/general.js";
 
 let disableTwitterElement = document.getElementById("disable-nitter");
@@ -35,9 +20,6 @@ let disableSendTargetsElement = document.getElementById("disable-sendTargets");
 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",
@@ -95,109 +77,13 @@ document.addEventListener("change", () => {
   });
 })
 
-let changeInstanceElement = document.getElementById("change-instance")
-changeInstanceElement.addEventListener("click", switchInstance);
-copyRawElement.addEventListener("click", copyRaw);
+document.getElementById("change_instance").addEventListener("click", utils.switchInstance);
+document.getElementById('copy_raw').addEventListener("click", utils.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);
-
-        let result = await youtubeHelper.initInvidiousCookies(url);
-        if (!result) result = await youtubeHelper.initPipedLocalStorage(url, currTab.id);
-        if (!result) result = await youtubeHelper.initPipedMaterialLocalStorage(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 searchHelper.initSearxCookies(url);
-        if (!result) result = await searchHelper.initSearxngCookies(url);
-
-        if (!result) result = await tiktokHelper.initProxiTokCookies(url);
-
-        if (!result) result = await wikipediaHelper.initWikilessCookies(url);
-
-        if (!result) result = await translateHelper.initSimplyTranslateCookies(url);
-        if (!result) result = await translateHelper.initLingvaLocalStorage(url);
+document.getElementById('unify').addEventListener("click", unify);
 
-        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 = new URL(currTab.url);
-      let newUrl;
-
-      // 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 });
-        return true;
-      }
-    }
-  })
-  return false;
-}
-
-function copyRaw() {
-  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;
 generalHelper.init().then(() => {
-  popupFrontends = generalHelper.getPopupFrontends();
-
+  let popupFrontends = generalHelper.getPopupFrontends();
   for (const frontend of generalHelper.allPopupFrontends)
     if (!popupFrontends.includes(frontend))
       document.getElementById(frontend).classList.add("hide")
diff --git a/src/pages/popup/popup.pug b/src/pages/popup/popup.pug
index 31354a4b..97f6d045 100644
--- a/src/pages/popup/popup.pug
+++ b/src/pages/popup/popup.pug
@@ -87,7 +87,7 @@ html(lang="en")
             input#disable-simplyTranslate(type="checkbox")
 
         #maps.some-block
-            a.title(href="https://maps.com")
+            a.title(href="https://www.openstreetmap.org")
                 +maps
                 h4 Maps
             input#disable-osm(type="checkbox")
@@ -99,7 +99,7 @@ html(lang="en")
             input#disable-sendTargets(type="checkbox")
 
         .some-block
-            a#change-instance.title.button
+            a#change_instance.title.button
                 +change_instance
                 h4 Change Instance
 
@@ -120,4 +120,4 @@ html(lang="en")
 
         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(src="../../assets/javascripts/localise.js")
\ No newline at end of file
diff --git a/src/pages/popup/style.css b/src/pages/popup/style.css
index 6cd91b92..4cc56145 100644
--- a/src/pages/popup/style.css
+++ b/src/pages/popup/style.css
@@ -9,11 +9,4 @@ html, body {
 
 .hide {
     display: none !important;
-}
-
-.button {
-    margin: auto;
-    width: 50%;
-    border: 3px rgb(180, 201, 180);
-    padding: 10px;
-  }
\ No newline at end of file
+}
\ No newline at end of file