Started optimizing popup.js

This commit is contained in:
Hygna 2022-09-23 20:57:25 +01:00
parent 320d0175a8
commit f87eb20cee
6 changed files with 159 additions and 438 deletions

View File

@ -20,10 +20,10 @@ async function getConfig() {
function init() {
return new Promise(async resolve => {
browser.storage.local.get(["network", "networkFallback"], r => {
browser.storage.local.get(["network", "networkFallback", "redirects"], r => {
options.network = r.network
options.networkFallback = r.networkFallback
options.redirects = r.redirects
redirects = r.redirects
})
for (const service in config.services) {
options[service] = {}
@ -50,14 +50,26 @@ function init() {
function all(service) {
let tmp = []
for (frontend in config.services[service].frontends) {
for (network in config.networks) tmp.push([...redirects[frontend][network]])
for (const frontend in config.services[service].frontends) {
if (config.services[service].frontends[frontend].instanceList) {
for (const network in config.networks) {
tmp.push(...redirects[frontend][network])
}
}
}
return tmp
}
function regexArray(service, url) {
for (const targetString in config.services[service].targets) {
const target = new RegExp(config.services[service].targets[targetString])
if (target.test(url.href)) return true
}
return false
}
await getConfig()
init()
await init()
browser.storage.onChanged.addListener(init)
function redirect(url, type, initiator) {
@ -69,7 +81,7 @@ function redirect(url, type, initiator) {
if (url.pathname == "/") return
for (const service in config.services) {
if (!options[service].enabled) continue
let targets = service.targets
let targets = config.services[service].targets
if (targets == "datajson") {
browser.storage.local.get(`${service}Targets`, (targets = r[service + "Targets"]))
}
@ -424,12 +436,29 @@ function initDefaults() {
browser.storage.local.set({
redirects: dataJson,
})
;() => resolve()
resolve()
})
})
}
function computeService(url) {
for (const service in config.services) {
const regex = config.services[service].targets
console.log(regex)
if (regexArray(service, url)) {
console.log(service + "gi")
return service
} else if (all(service).includes(utils.protocolHost(url))) {
console.log(service)
return service
}
}
console.log("moment")
return null
}
export default {
redirect,
initDefaults,
computeService,
}

View File

@ -87,12 +87,12 @@
},
"singleInstanceFrontends": ["freetube", "yatte"],
"targets": [
"^https?:\\/{2}(www\\.|music\\.|m\\.|)youtube.com(\\(?!iframe_api)/.*|$)",
"^https?:\\/{2}(?:www\\.|music\\.|m\\.|)youtube.com(\\(?!iframe_api/.*|$)",
"^https?:\\/{2}img\\.youtube.com\\/vi\\/.*\\/..*",
"^https?:\\/{2}(i|s)\\.ytimg.com\\/vi\\/.*\\/..*",
"^https?:\\/{2}(www\\.|music\\.|)youtube.com\\/watch?v=..*",
"^https?:\\/{2}(?:i|s)\\.ytimg.com\\/vi\\/.*\\/..*",
"^https?:\\/{2}(?:www\\.|music\\.|)youtube.com\\/watch?v=..*",
"^https?:\\/{2}youtu\\.be\\/..*",
"^https?:\\/{2}(www\\.|)(youtube|youtube-nocookie)\\.com\\/embed\\/..*"
"^https?:\\/{2}(?:www\\.|)(youtube|youtube-nocookie)\\.com\\/embed\\/..*"
],
"name": "Youtube",
"options": {
@ -275,7 +275,7 @@
"instanceList": true
}
},
"targets": ["^https?:\\/{2}([a-z]+\\.)*wikipedia\\.org"],
"targets": ["^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org"],
"name": "Wikipedia",
"options": { "enabled": false },
"imageType": "svg",

View File

@ -145,6 +145,7 @@ browser.tabs.onRemoved.addListener(tabId => {
}
})
/*
browser.webRequest.onHeadersReceived.addListener(
e => {
let response = youtubeHelper.removeXFrameOptions(e)
@ -154,6 +155,7 @@ browser.webRequest.onHeadersReceived.addListener(
{ urls: ["<all_urls>"] },
["blocking", "responseHeaders"]
)
*/
async function redirectOfflineInstance(url, tabId) {
let newUrl = await youtubeHelper.switchInstance(url, true)

View File

@ -16,28 +16,28 @@
<a href="#general" data-localise="__MSG_general__">General</a></div>
<div class="title">
<img src="../../../assets/images/youtube-icon.png">
<a href="#youtube" data-localise="__MSG_youtube__">youtube</a></div>
<a href="#youtube" data-localise="__MSG_youtube__">Youtube</a></div>
<div class="title">
<img src="../../../assets/images/youtubeMusic-icon.png">
<a href="#youtubeMusic" data-localise="__MSG_youtubeMusic__">youtubeMusic</a></div>
<a href="#youtubeMusic" data-localise="__MSG_youtubeMusic__">YT Music</a></div>
<div class="title">
<img src="../../../assets/images/twitter-icon.png">
<a href="#twitter" data-localise="__MSG_twitter__">twitter</a></div>
<a href="#twitter" data-localise="__MSG_twitter__">Twitter</a></div>
<div class="title">
<img src="../../../assets/images/instagram-icon.png">
<a href="#instagram" data-localise="__MSG_instagram__">instagram</a></div>
<a href="#instagram" data-localise="__MSG_instagram__">Instagram</a></div>
<div class="title">
<img src="../../../assets/images/tiktok-icon.png">
<a href="#tiktok" data-localise="__MSG_tiktok__">tiktok</a></div>
<a href="#tiktok" data-localise="__MSG_tiktok__">TikTok</a></div>
<div class="title">
<img src="../../../assets/images/reddit-icon.png">
<a href="#reddit" data-localise="__MSG_reddit__">reddit</a></div>
<a href="#reddit" data-localise="__MSG_reddit__">Reddit</a></div>
<div class="title">
<img src="../../../assets/images/imgur-icon.png">
<a href="#imgur" data-localise="__MSG_imgur__">imgur</a></div>
<a href="#imgur" data-localise="__MSG_imgur__">Imgur</a></div>
<div class="title">
<img src="../../../assets/images/wikipedia-icon.svg">
<a href="#wikipedia" data-localise="__MSG_wikipedia__">wikipedia</a></div>
<a href="#wikipedia" data-localise="__MSG_wikipedia__">Wikipedia</a></div>
<div class="title">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1770 1000" fill="currentColor">
<circle cx="500" cy="500" r="500"></circle>
@ -45,46 +45,46 @@
<ellipse cx="1682" cy="502" rx="88" ry="424"></ellipse>
</svg>
<a href="#medium" data-localise="__MSG_medium__">medium</a></div>
<a href="#medium" data-localise="__MSG_medium__">Medium</a></div>
<div class="title">
<img src="../../../assets/images/quora-icon.png">
<a href="#quora" data-localise="__MSG_quora__">quora</a></div>
<a href="#quora" data-localise="__MSG_quora__">Quora</a></div>
<div class="title">
<img src="../../../assets/images/imdb-icon.svg">
<a href="#imdb" data-localise="__MSG_imdb__">imdb</a></div>
<a href="#imdb" data-localise="__MSG_imdb__">IMDb</a></div>
<div class="title">
<img src="../../../assets/images/reuters-icon.svg">
<a href="#reuters" data-localise="__MSG_reuters__">reuters</a></div>
<a href="#reuters" data-localise="__MSG_reuters__">Reuters</a></div>
<div class="title">
<img src="../../../assets/images/peertube-icon.svg">
<a href="#peertube" data-localise="__MSG_peertube__">peertube</a></div>
<a href="#peertube" data-localise="__MSG_peertube__">PeerTube</a></div>
<div class="title">
<img src="../../../assets/images/lbry-icon.png">
<a href="#lbry" data-localise="__MSG_lbry__">lbry</a></div>
<a href="#lbry" data-localise="__MSG_lbry__">LBRY</a></div>
<div class="title">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
<path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
<a href="#search" data-localise="__MSG_search__">search</a></div>
<a href="#search" data-localise="__MSG_search__">Search</a></div>
<div class="title">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
<path d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"></path>
</svg>
<a href="#translate" data-localise="__MSG_translate__">translate</a></div>
<a href="#translate" data-localise="__MSG_translate__">Translate</a></div>
<div class="title">
<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>
<a href="#maps" data-localise="__MSG_maps__">maps</a></div>
<a href="#maps" data-localise="__MSG_maps__">Maps</a></div>
<div class="title">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
<path d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z"></path>
</svg>
<a href="#sendTargets" data-localise="__MSG_sendTargets__">sendTargets</a></div>
<a href="#sendTargets" data-localise="__MSG_sendTargets__">Send Files</a></div>
<div class="title"><svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" fill="currentColor">
<path d="M11 17h2v-6h-2Zm1-8q.425 0 .713-.288Q13 8.425 13 8t-.287-.713Q12.425 7 12 7t-.712.287Q11 7.575 11 8t.288.712Q11.575 9 12 9Zm0 13q-2.075 0-3.9-.788-1.825-.787-3.175-2.137-1.35-1.35-2.137-3.175Q2 14.075 2 12t.788-3.9q.787-1.825 2.137-3.175 1.35-1.35 3.175-2.138Q9.925 2 12 2t3.9.787q1.825.788 3.175 2.138 1.35 1.35 2.137 3.175Q22 9.925 22 12t-.788 3.9q-.787 1.825-2.137 3.175-1.35 1.35-3.175 2.137Q14.075 22 12 22Zm0-2q3.35 0 5.675-2.325Q20 15.35 20 12q0-3.35-2.325-5.675Q15.35 4 12 4 8.65 4 6.325 6.325 4 8.65 4 12q0 3a.35 2.325 5.675Q8.65 20 12 20Zm0-8Z"></path>
</svg>

View File

@ -3,40 +3,7 @@ window.browser = window.browser || window.chrome
import utils from "../../assets/javascripts/utils.js"
import generalHelper from "../../assets/javascripts/general.js"
import youtubeHelper from "../../assets/javascripts/youtube/youtube.js"
import youtubeMusicHelper from "../../assets/javascripts/youtubeMusic.js"
import twitterHelper from "../../assets/javascripts/twitter.js"
import instagramHelper from "../../assets/javascripts/instagram.js"
import redditHelper from "../../assets/javascripts/reddit.js"
import searchHelper from "../../assets/javascripts/search.js"
import translateHelper from "../../assets/javascripts/translate/translate.js"
import mapsHelper from "../../assets/javascripts/maps.js"
import wikipediaHelper from "../../assets/javascripts/wikipedia.js"
import mediumHelper from "../../assets/javascripts/medium.js"
import quoraHelper from "../../assets/javascripts/quora.js"
import libremdbHelper from "../../assets/javascripts/imdb.js"
import reutersHelper from "../../assets/javascripts/reuters.js"
import imgurHelper from "../../assets/javascripts/imgur.js"
import tiktokHelper from "../../assets/javascripts/tiktok.js"
import sendTargetsHelper from "../../assets/javascripts/sendTargets.js"
import peertubeHelper from "../../assets/javascripts/peertube.js"
import lbryHelper from "../../assets/javascripts/lbry.js"
utils.unify(true).then(r => {
if (!r) document.getElementById("unify_div").style.display = "none"
else {
const unify = document.getElementById("unify")
const textElement = document.getElementById("unify").getElementsByTagName("h4")[0]
unify.addEventListener("click", () => {
const oldHtml = textElement.innerHTML
textElement.innerHTML = "..."
browser.runtime.sendMessage({ function: "unify" }, response => {
if (response && response.response) textElement.innerHTML = oldHtml
})
})
}
})
import serviceHelper from "../../assets/javascripts/services.js"
utils.switchInstance(true).then(r => {
if (!r) document.getElementById("change_instance_div").style.display = "none"
@ -52,389 +19,112 @@ utils.copyRaw(true).then(r => {
})
document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage())
let config
let divs = {}
async function getConfig() {
return new Promise(resolve => {
fetch("/config/config.json")
.then(response => response.text())
.then(data => {
const tmp = JSON.parse(data)
config = tmp.config
resolve()
})
})
}
await getConfig()
const allSites = document.getElementsByClassName("all_sites")[0]
const currSite = document.getElementsByClassName("current_site")[0]
const disableTwitterCurrentSite = currSite.getElementsByClassName("disable-nitter")[0]
const disableTwitterAllSites = allSites.getElementsByClassName("disable-nitter")[0]
function setDivs() {
return new Promise(resolve => {
for (const service in config.services) {
divs[service] = {}
divs[service].toggle = {}
divs[service].current = currSite.getElementsByClassName(service)[0]
divs[service].all = allSites.getElementsByClassName(service)[0]
divs[service].toggle.current = currSite.getElementsByClassName(service + "-enabled")[0]
divs[service].toggle.all = allSites.getElementsByClassName(service + "-enabled")[0]
}
resolve()
})
}
const disableYoutubeCurrentSite = currSite.getElementsByClassName("disable-youtube")[0]
const disableYoutubeAllSites = allSites.getElementsByClassName("disable-youtube")[0]
const disableYoutubeMusicCurrentSite = currSite.getElementsByClassName("disable-youtubeMusic")[0]
const disableYoutubeMusicAllSites = allSites.getElementsByClassName("disable-youtubeMusic")[0]
const disableInstagramCurrentSite = currSite.getElementsByClassName("disable-bibliogram")[0]
const disableInstagramAllSites = allSites.getElementsByClassName("disable-bibliogram")[0]
const disableMapsCurrentSite = currSite.getElementsByClassName("disable-osm")[0]
const disableMapsAllSites = allSites.getElementsByClassName("disable-osm")[0]
const disableRedditCurrentSite = currSite.getElementsByClassName("disable-reddit")[0]
const disableRedditAllSites = allSites.getElementsByClassName("disable-reddit")[0]
const disableSearchCurrentSite = currSite.getElementsByClassName("disable-search")[0]
const disableSearchAllSites = allSites.getElementsByClassName("disable-search")[0]
const disableTranslateCurrentSite = currSite.getElementsByClassName("disable-translate")[0]
const disableTranslateAllSites = allSites.getElementsByClassName("disable-translate")[0]
const disableWikipediaCurrentSite = currSite.getElementsByClassName("disable-wikipedia")[0]
const disableWikipediaAllSites = allSites.getElementsByClassName("disable-wikipedia")[0]
const disableMediumCurrentSite = currSite.getElementsByClassName("disable-medium")[0]
const disableMediumAllSites = allSites.getElementsByClassName("disable-medium")[0]
const disableQuoraCurrentSite = currSite.getElementsByClassName("disable-quora")[0]
const disableQuoraAllSites = allSites.getElementsByClassName("disable-quora")[0]
const disableImdbCurrentSite = currSite.getElementsByClassName("disable-imdb")[0]
const disableImdbAllSites = allSites.getElementsByClassName("disable-imdb")[0]
const disableReutersCurrentSite = currSite.getElementsByClassName("disable-reuters")[0]
const disableReutersAllSites = allSites.getElementsByClassName("disable-reuters")[0]
const disablePeertubeTargetsCurrentSite = currSite.getElementsByClassName("disable-peertube")[0]
const disablePeertubeTargetsAllSites = allSites.getElementsByClassName("disable-peertube")[0]
const disableLbryTargetsCurrentSite = currSite.getElementsByClassName("disable-lbry")[0]
const disableLbryTargetsAllSites = allSites.getElementsByClassName("disable-lbry")[0]
const disableSendTargetsCurrentSite = currSite.getElementsByClassName("disable-sendTargets")[0]
const disableSendTargetsAllSites = allSites.getElementsByClassName("disable-sendTargets")[0]
const disableImgurCurrentSite = currSite.getElementsByClassName("disable-imgur")[0]
const disableImgurAllSites = allSites.getElementsByClassName("disable-imgur")[0]
const disableTiktokCurrentSite = currSite.getElementsByClassName("disable-tiktok")[0]
const disableTiktokAllSites = allSites.getElementsByClassName("disable-tiktok")[0]
await setDivs()
const currentSiteIsFrontend = document.getElementById("current_site_divider")
browser.storage.local.get(
[
"disableTwitter",
"disableYoutube",
"disableYoutubeMusic",
"disableInstagram",
"disableMaps",
"disableReddit",
"disableSearch",
"translateDisable",
"disableWikipedia",
"disableImgur",
"disableTiktok",
"disableMedium",
"disableQuora",
"disableImdb",
"disableReuters",
"disablePeertubeTargets",
"disableLbryTargets",
"disableSendTarget",
"popupFrontends",
],
r => {
disableTwitterCurrentSite.checked = !r.disableTwitter
disableTwitterAllSites.checked = !r.disableTwitter
disableYoutubeCurrentSite.checked = !r.disableYoutube
disableYoutubeAllSites.checked = !r.disableYoutube
disableYoutubeMusicCurrentSite.checked = !r.disableYoutubeMusic
disableYoutubeMusicAllSites.checked = !r.disableYoutubeMusic
disableInstagramCurrentSite.checked = !r.disableInstagram
disableInstagramAllSites.checked = !r.disableInstagram
disableMapsCurrentSite.checked = !r.disableMaps
disableMapsAllSites.checked = !r.disableMaps
disableRedditCurrentSite.checked = !r.disableReddit
disableRedditAllSites.checked = !r.disableReddit
disableSearchCurrentSite.checked = !r.disableSearch
disableSearchAllSites.checked = !r.disableSearch
disableTranslateCurrentSite.checked = !r.translateDisable
disableTranslateAllSites.checked = !r.translateDisable
disableWikipediaCurrentSite.checked = !r.disableWikipedia
disableWikipediaAllSites.checked = !r.disableWikipedia
disableImgurCurrentSite.checked = !r.disableImgur
disableImgurAllSites.checked = !r.disableImgur
disableTiktokCurrentSite.checked = !r.disableTiktok
disableTiktokAllSites.checked = !r.disableTiktok
disableMediumCurrentSite.checked = !r.disableMedium
disableMediumAllSites.checked = !r.disableMedium
disableQuoraCurrentSite.checked = !r.disableQuora
disableQuoraAllSites.checked = !r.disableQuora
disableImdbCurrentSite.checked = !r.disableImdb
disableImdbAllSites.checked = !r.disableImdb
disableReutersCurrentSite.checked = !r.disableReuters
disableReutersAllSites.checked = !r.disableReuters
disablePeertubeTargetsCurrentSite.checked = !r.disablePeertubeTargets
disablePeertubeTargetsAllSites.checked = !r.disablePeertubeTargets
disableLbryTargetsCurrentSite.checked = !r.disableLbryTargets
disableLbryTargetsAllSites.checked = !r.disableLbryTargets
disableSendTargetsCurrentSite.checked = !r.disableSendTarget
disableSendTargetsAllSites.checked = !r.disableSendTarget
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
for (const frontend of generalHelper.allPopupFrontends) {
if (!r.popupFrontends.includes(frontend)) allSites.getElementsByClassName(frontend)[0].classList.add("hide")
else allSites.getElementsByClassName(frontend)[0].classList.remove("hide")
currSite.getElementsByClassName(frontend)[0].classList.add("hide")
}
let url
try {
url = new URL(tabs[0].url)
} catch {
currentSiteIsFrontend.classList.add("hide")
return
}
if (youtubeMusicHelper.redirect(url, "main_frame", false, true) || (await youtubeMusicHelper.switchInstance(url, true))) {
currSite.getElementsByClassName("youtubeMusic")[0].classList.remove("hide")
allSites.getElementsByClassName("youtubeMusic")[0].classList.add("hide")
} else if (twitterHelper.redirect(url, "main_frame", false, true) || (await twitterHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("twitter")[0].classList.remove("hide")
allSites.getElementsByClassName("twitter")[0].classList.add("hide")
} else if (instagramHelper.redirect(url, "main_frame", false, true) || (await instagramHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("instagram")[0].classList.remove("hide")
allSites.getElementsByClassName("instagram")[0].classList.add("hide")
} else if (mapsHelper.redirect(url, false)) {
currSite.getElementsByClassName("maps")[0].classList.remove("hide")
allSites.getElementsByClassName("maps")[0].classList.add("hide")
} else if (redditHelper.redirect(url, "main_frame", false, true) || (await redditHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("reddit")[0].classList.remove("hide")
allSites.getElementsByClassName("reddit")[0].classList.add("hide")
} else if (mediumHelper.redirect(url, "main_frame", false, true) || (await mediumHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("medium")[0].classList.remove("hide")
allSites.getElementsByClassName("medium")[0].classList.add("hide")
} else if (quoraHelper.redirect(url, "main_frame", false, true) || (await quoraHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("quora")[0].classList.remove("hide")
allSites.getElementsByClassName("quora")[0].classList.add("hide")
} else if (libremdbHelper.redirect(url, "main_frame", false, true) || (await libremdbHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("imdb")[0].classList.remove("hide")
allSites.getElementsByClassName("imdb")[0].classList.add("hide")
} else if (reutersHelper.redirect(url, "main_frame", false, true)) {
currSite.getElementsByClassName("reuters")[0].classList.remove("hide")
allSites.getElementsByClassName("reuters")[0].classList.add("hide")
} else if (imgurHelper.redirect(url, "main_frame", false, true) || (await imgurHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("imgur")[0].classList.remove("hide")
allSites.getElementsByClassName("imgur")[0].classList.add("hide")
} else if (tiktokHelper.redirect(url, "main_frame", false, true) || (await tiktokHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("tiktok")[0].classList.remove("hide")
allSites.getElementsByClassName("tiktok")[0].classList.add("hide")
} else if (sendTargetsHelper.redirect(url, "main_frame", false, true) || (await sendTargetsHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("sendTargets")[0].classList.remove("hide")
allSites.getElementsByClassName("sendTargets")[0].classList.add("hide")
} else if (peertubeHelper.redirect(url, "main_frame", false, true) || (await peertubeHelper.switchInstance(url, true))) {
currSite.getElementsByClassName("peertube")[0].classList.remove("hide")
allSites.getElementsByClassName("peertube")[0].classList.add("hide")
} else if (lbryHelper.redirect(url, "main_frame", false, true) || (await lbryHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("lbry")[0].classList.remove("hide")
allSites.getElementsByClassName("lbry")[0].classList.add("hide")
} else if (translateHelper.redirect(url, true) || (await translateHelper.switchInstance(url, true))) {
currSite.getElementsByClassName("translate")[0].classList.remove("hide")
allSites.getElementsByClassName("translate")[0].classList.add("hide")
} else if (searchHelper.redirect(url, true) || (await searchHelper.switchInstance(url, true))) {
currSite.getElementsByClassName("search")[0].classList.remove("hide")
allSites.getElementsByClassName("search")[0].classList.add("hide")
} else if (wikipediaHelper.redirect(url, true) || (await wikipediaHelper.switchInstance(url, true))) {
currSite.getElementsByClassName("wikipedia")[0].classList.remove("hide")
allSites.getElementsByClassName("wikipedia")[0].classList.add("hide")
} else if (youtubeHelper.redirect(url, "main_frame", false, true) || (await youtubeHelper.switchInstance(url, "main_frame", false, true))) {
currSite.getElementsByClassName("youtube")[0].classList.remove("hide")
allSites.getElementsByClassName("youtube")[0].classList.add("hide")
} else {
currentSiteIsFrontend.classList.add("hide")
}
})
}
)
document.addEventListener("change", () => {
browser.storage.local.get(
[
"disableTwitter",
"disableYoutube",
"disableYoutubeMusic",
"disableInstagram",
"disableMaps",
"disableReddit",
"disableSearch",
"translateDisable",
"disableWikipedia",
"disableImgur",
"disableTiktok",
"disableMedium",
"disableQuora",
"disableImdb",
"disableReuters",
"disablePeertubeTargets",
"disableLbryTargets",
"disableSendTarget",
],
r => {
if (!r.disableTwitter != disableTwitterCurrentSite.checked)
browser.storage.local.set({
disableTwitter: !disableTwitterCurrentSite.checked,
})
else if (!r.disableTwitter != disableTwitterAllSites.checked)
browser.storage.local.set({
disableTwitter: !disableTwitterAllSites.checked,
})
if (!r.disableYoutube != disableYoutubeCurrentSite.checked)
browser.storage.local.set({
disableYoutube: !disableYoutubeCurrentSite.checked,
})
else if (!r.disableYoutube != disableYoutubeAllSites.checked)
browser.storage.local.set({
disableYoutube: !disableYoutubeAllSites.checked,
})
if (!r.disableYoutubeMusic != disableYoutubeMusicCurrentSite.checked)
browser.storage.local.set({
disableYoutubeMusic: !disableYoutubeMusicCurrentSite.checked,
})
else if (!r.disableYoutubeMusic != disableYoutubeMusicAllSites.checked)
browser.storage.local.set({
disableYoutubeMusic: !disableYoutubeMusicAllSites.checked,
})
if (!r.disableInstagram != disableInstagramCurrentSite.checked)
browser.storage.local.set({
disableInstagram: !disableInstagramCurrentSite.checked,
})
else if (!r.disableInstagram != disableInstagramAllSites.checked)
browser.storage.local.set({
disableInstagram: !disableInstagramAllSites.checked,
})
if (!r.disableMaps != disableMapsCurrentSite.checked)
browser.storage.local.set({
disableMaps: !disableMapsCurrentSite.checked,
})
else if (!r.disableMaps != disableMapsAllSites.checked)
browser.storage.local.set({
disableMaps: !disableMapsAllSites.checked,
})
if (!r.disableReddit != disableRedditCurrentSite.checked)
browser.storage.local.set({
disableReddit: !disableRedditCurrentSite.checked,
})
else if (!r.disableReddit != disableRedditAllSites.checked)
browser.storage.local.set({
disableReddit: !disableRedditAllSites.checked,
})
if (!r.disableSearch != disableSearchCurrentSite.checked)
browser.storage.local.set({
disableSearch: !disableSearchCurrentSite.checked,
})
else if (!r.disableSearch != disableSearchAllSites.checked)
browser.storage.local.set({
disableSearch: !disableSearchAllSites.checked,
})
if (!r.translateDisable != disableTranslateCurrentSite.checked)
browser.storage.local.set({
translateDisable: !disableTranslateCurrentSite.checked,
})
else if (!r.translateDisable != disableTranslateAllSites.checked)
browser.storage.local.set({
translateDisable: !disableTranslateAllSites.checked,
})
if (!r.disableWikipedia != disableWikipediaCurrentSite.checked)
browser.storage.local.set({
disableWikipedia: !disableWikipediaCurrentSite.checked,
})
else if (!r.disableWikipedia != disableWikipediaAllSites.checked)
browser.storage.local.set({
disableWikipedia: !disableWikipediaAllSites.checked,
})
if (!r.disableImgur != disableImgurCurrentSite.checked)
browser.storage.local.set({
disableImgur: !disableImgurCurrentSite.checked,
})
else if (!r.disableImgur != disableImgurAllSites.checked)
browser.storage.local.set({
disableImgur: !disableImgurAllSites.checked,
})
if (!r.disableTiktok != disableTiktokCurrentSite.checked)
browser.storage.local.set({
disableTiktok: !disableTiktokCurrentSite.checked,
})
else if (!r.disableTiktok != disableTiktokAllSites.checked)
browser.storage.local.set({
disableTiktok: !disableTiktokAllSites.checked,
})
if (!r.disableMedium != disableMediumCurrentSite.checked)
browser.storage.local.set({
disableMedium: !disableMediumCurrentSite.checked,
})
else if (!r.disableMedium != disableMediumAllSites.checked)
browser.storage.local.set({
disableMedium: !disableMediumAllSites.checked,
})
if (!r.disableQuora != disableQuoraCurrentSite.checked)
browser.storage.local.set({
disableQuora: !disableQuoraCurrentSite.checked,
})
else if (!r.disableQuora != disableQuoraAllSites.checked)
browser.storage.local.set({
disableQuora: !disableQuoraAllSites.checked,
})
if (!r.disableImdb != disableImdbCurrentSite.checked)
browser.storage.local.set({
disableImdb: !disableImdbCurrentSite.checked,
})
else if (!r.disableImdb != disableImdbAllSites.checked)
browser.storage.local.set({
disableImdb: !disableImdbAllSites.checked,
})
if (!r.disableReuters != disableReutersCurrentSite.checked)
browser.storage.local.set({
disableReuters: !disableReutersCurrentSite.checked,
})
else if (!r.disableReuters != disableReutersAllSites.checked)
browser.storage.local.set({
disableReuters: !disableReutersAllSites.checked,
})
if (!r.disablePeertubeTargets != disablePeertubeTargetsCurrentSite.checked)
browser.storage.local.set({
disablePeertubeTargets: !disablePeertubeTargetsCurrentSite.checked,
})
else if (!r.disablePeertubeTargets != disablePeertubeTargetsAllSites.checked)
browser.storage.local.set({
disablePeertubeTargets: !disablePeertubeTargetsAllSites.checked,
})
if (!r.disableLbryTargets != disableLbryTargetsCurrentSite.checked)
browser.storage.local.set({
disableLbryTargets: !disableLbryTargetsCurrentSite.checked,
})
else if (!r.disableLbryTargets != disableLbryTargetsAllSites.checked)
browser.storage.local.set({
disableLbryTargets: !disableLbryTargetsAllSites.checked,
})
if (!r.disableSendTarget != disableSendTargetsCurrentSite.checked)
browser.storage.local.set({
disableSendTarget: !disableSendTargetsCurrentSite.checked,
})
else if (!r.disableSendTarget != disableSendTargetsAllSites.checked)
browser.storage.local.set({
disableSendTarget: !disableSendTargetsAllSites.checked,
})
function getEnabled() {
return new Promise(async resolve => {
for (const service in config.services) {
browser.storage.local.get(`${service}Enabled`, r => {
divs[service].toggle.all.checked = r[service + "Enabled"]
divs[service].toggle.current.checked = r[service + "Enabled"]
})
}
)
resolve()
})
}
browser.storage.local.get("popupFrontends", r => {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
for (const frontend of generalHelper.allPopupFrontends) {
if (!r.popupFrontends.includes(frontend)) allSites.getElementsByClassName(frontend)[0].classList.add("hide")
else allSites.getElementsByClassName(frontend)[0].classList.remove("hide")
currSite.getElementsByClassName(frontend)[0].classList.add("hide")
}
let url
try {
url = new URL(tabs[0].url)
console.log(url.href)
} catch {
currentSiteIsFrontend.classList.add("hide")
return
}
await getEnabled()
const currentService = serviceHelper.computeService(url)
if (currentService != null) {
divs[currentService].current.classList.remove("hide")
divs[currentService].all.classList.add("hide")
if (config.services[currentService].preferences != {}) {
const unify = document.getElementById("unify")
const textElement = document.getElementById("unify").getElementsByTagName("h4")[0]
unify.addEventListener("click", () => {
const oldHtml = textElement.innerHTML
textElement.innerHTML = "..."
browser.runtime.sendMessage({ function: "unify" }, response => {
if (response && response.response) textElement.innerHTML = oldHtml
})
})
} else {
document.getElementById("unify_div").style.display = "none"
}
} else {
currentSiteIsFrontend.classList.add("hide")
document.getElementById("unify_div").style.display = "none"
}
})
})
for (const service in config.services) {
divs[service].toggle.all.addEventListener("change", () => {
browser.storage.local.set({
[service + "Enabled"]: divs[service].toggle.all.checked,
})
})
divs[service].toggle.current.addEventListener("change", () => {
browser.storage.local.set({
[service + "Enabled"]: divs[service].toggle.current.checked,
})
})
}
for (const a of document.getElementsByTagName("a")) {
a.addEventListener("click", e => {
if (!a.classList.contains("prevent")) {

View File

@ -7,7 +7,7 @@
<% } else { _%>
<%- include ('src/assets/images/' + service + '-icon.svg') %>
<% } _%>
<a href="#<%= service %>" data-localise="__MSG_<%= service %>__"><%= service %></a></div>
<a href="#<%= service %>" data-localise="__MSG_<%= service %>__"><%= config.services[service].name %></a></div>
<% }; -%>
<div class="title"><%- include ('src/assets/images/about-icon.svg') %><a href="#about" data-localise="__MSG_about__">About</a></div>
</section>