changing redirects from const to let, cleaning

This commit is contained in:
ManeraKai 2022-02-03 13:41:23 +03:00
parent d2313e4f2e
commit 4b983d03ce
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
12 changed files with 26 additions and 82 deletions

View File

@ -5,7 +5,7 @@ import mediumHelper from "./medium.js";
import redditHelper from "./reddit.js";
import searchHelper from "./search.js";
import data from '../data.js'
import googleTranslateHelper from "./translate.js";
import translateHelper from "./translate.js";
import wikipediaHelper from "./wikipedia.js";
import mapsHelper from "./maps.js";
import medium from "./medium.js";

View File

@ -6,7 +6,7 @@ const targets = [
"help.instagram.com",
"about.instagram.com",
];
const redirects = {
let redirects = {
"normal": [
"https://bibliogram.art",
"https://bibliogram.snopyta.org",

View File

@ -1,7 +1,7 @@
import commonHelper from './common.js'
const targets = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/;
const redirects = {
let redirects = {
"normal": [
"https://openstreetmap.org"
]

View File

@ -16,7 +16,7 @@ const targets = [
/blog\.coinbase\.com/
];
const redirects = {
let redirects = {
"normal": [
"https://scribe.rip",
"https://scribe.nixnet.services"

View File

@ -8,7 +8,7 @@ const targets = [
"i.redd.it",
"redd.it",
];
const redirects = {
let redirects = {
// modern UI
"libreddit": {
"normal": [

View File

@ -5,7 +5,7 @@ const targets = [
/https:\/\/.*\.google\.com/,
/https?:\/\/(((www|maps)\.)?(google\.).*(\/search)|search\.(google\.).*)/
];
const redirects = {
let redirects = {
"searx": {
"normal": [
"https://a.searx.space",

View File

@ -5,7 +5,7 @@ const targets = [
"translate.google.no"
];
const redirects = {
let redirects = {
"simplyTranslate": {
"normal": [
"https://simplytranslate.org",

View File

@ -17,7 +17,7 @@ const targets = [
src/assets/javascripts/remove-twitter-sw.js file
(const nitterInstances) when updating this list:
*/
const redirects = {
let redirects = {
"normal": [
"https://nitter.net",
"https://nitter.snopyta.org",

View File

@ -1,6 +1,6 @@
const targets = /wikipedia.org/;
const redirects = {
let redirects = {
"normal": [
"https://wikiless.org"
]

View File

@ -20,7 +20,7 @@ const targets = [
(content_scripts > matches, 'persist-invidious-prefs.js')
when updating this list:
*/
const redirects = {
let redirects = {
"normal": [
"https://invidious.snopyta.org",
"https://invidious.xyz",

View File

@ -7,26 +7,15 @@ import instagramHelper from "../../assets/javascripts/helpers/instagram.js";
import mediumHelper from "../../assets/javascripts/helpers/medium.js";
import redditHelper from "../../assets/javascripts/helpers/reddit.js";
import searchHelper from "../../assets/javascripts/helpers/search.js";
import googleTranslateHelper from "../../assets/javascripts/helpers/translate.js";
import translateHelper from "../../assets/javascripts/helpers/translate.js";
import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
import data from "../../assets/javascripts/data.js";
import googleMaps from "../../assets/javascripts/helpers/maps.js";
import mapsHelper from "../../assets/javascripts/helpers/maps.js";
window.browser = window.browser || window.chrome;
// data.osmInstance = result.osmInstance || data.osmDefault;
// data.simplyTranslateInstance = result.simplyTranslateInstance || data.simplyTranslateDefault;
// data.wikipediaInstance = result.wikipediaInstance || data.wikipediaDefault;
// data.exceptions = result.exceptions
// ? result.exceptions.map((e) => {
// return new RegExp(e);
// })
// : [];
// data.invidiousSubtitles = result.invidiousSubtitles || "";
googleMaps.init()
mapsHelper.init()
searchHelper.init()
googleTranslateHelper.init()
translateHelper.init()
instagramHelper.init()
mediumHelper.init()
redditHelper.init()
@ -58,7 +47,7 @@ browser.webRequest.onBeforeRequest.addListener(
else if (mediumHelper.targets.some((rx) => rx.test(url.host))) newUrl = await mediumHelper.redirect(url, initiator);
else if (googleTranslateHelper.targets.includes(url.host)) newUrl = await googleTranslateHelper.redirect(url, initiator);
else if (translateHelper.targets.includes(url.host)) newUrl = await translateHelper.redirect(url, initiator);
else if (searchHelper.targets.some((rx) => rx.test(url.href))) newUrl = await searchHelper.redirect(url, initiator)
@ -74,6 +63,7 @@ browser.webRequest.onBeforeRequest.addListener(
["blocking"]
);
browser.tabs.onUpdated.addListener((tabId, changeInfo, _) => {
let url;
try {
@ -93,8 +83,8 @@ browser.tabs.onUpdated.addListener((tabId, changeInfo, _) => {
redditHelper.redirects.mobile,
...searchHelper.redirects.searx.normal,
...searchHelper.redirects.whoogle.normal,
...googleTranslateHelper.redirects.simplyTranslate.normal,
...googleTranslateHelper.redirects.lingva.normal,
...translateHelper.redirects.simplyTranslate.normal,
...translateHelper.redirects.lingva.normal,
...mediumHelper.redirects.normal,
...wikipediaHelper.redirects.normal
);
@ -129,8 +119,8 @@ browser.pageAction.onClicked.addListener((tab) => {
) newUrl = 'https://google.com';
if (
googleTranslateHelper.redirects.simplyTranslate.normal.includes(protocolHost) ||
googleTranslateHelper.redirects.lingva.normal.includes(protocolHost)
translateHelper.redirects.simplyTranslate.normal.includes(protocolHost) ||
translateHelper.redirects.lingva.normal.includes(protocolHost)
) newUrl = 'https://translate.google.com';
if (mediumHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://medium.com';
@ -138,50 +128,4 @@ browser.pageAction.onClicked.addListener((tab) => {
if (wikipediaHelper.redirects.normal.includes(protocolHost)) newUrl = 'https://wikipedia.com';
if (newUrl) browser.tabs.update({ url: tabUrl.href.replace(protocolHost, newUrl) });
});
browser.runtime.onInstalled.addListener((details) => {
browser.storage.sync.get(
[
"disableSearch",
"disableTranslate",
"disableWikipedia",
"redditFrontend",
"searchFrontend",
],
(result) => {
if (result.disableSearch === undefined) browser.storage.sync.set({ disableSearch: true });
if (result.disableTranslate === undefined) browser.storage.sync.set({ disableTranslate: true });
if (result.disableWikipedia === undefined) browser.storage.sync.set({ disableWikipedia: true });
if (result.redditFrontend === undefined) browser.storage.sync.set({ redditFrontend: 'libreddit' })
if (result.searchFrontend === undefined) {
data.searchFrontend = 'searx';
browser.storage.sync.set({ searchFrontend: data.searchFrontend })
}
}
);
if (details.reason === "update") {
browser.storage.sync.get(
["whitelist", "exceptions", "invidiousInstance", "disableSearch"],
(result) => {
if (result.whitelist) {
let whitelist = result.whitelist.map((e) =>
e.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")
);
browser.storage.sync.set({
exceptions: result.exceptions.concat(whitelist),
whitelist: null,
});
}
if (result.invidiousInstance === "https://invidio.us")
browser.storage.sync.set({ invidiousInstance: null });
}
);
}
});

View File

@ -1,18 +1,18 @@
import googleTranslateHelper from "../../assets/javascripts/helpers/translate.js";
import translateHelper from "../../assets/javascripts/helpers/translate.js";
let disableTranslateElement = document.getElementById("disable-simplyTranslate");
let translateFrontendElement = document.getElementById("translate-frontend");
googleTranslateHelper.init().then(() => {
disableTranslateElement.checked = !googleTranslateHelper.getDisableTranslate();
translateFrontendElement.value = googleTranslateHelper.getFrontend();
translateHelper.init().then(() => {
disableTranslateElement.checked = !translateHelper.getDisableTranslate();
translateFrontendElement.value = translateHelper.getFrontend();
});
disableTranslateElement.addEventListener("change",
(event) => googleTranslateHelper.setDisableTranslate(!event.target.checked)
(event) => translateHelper.setDisableTranslate(!event.target.checked)
);
translateFrontendElement.addEventListener("change",
(event) => googleTranslateHelper.setFrontend(event.target.options[translateFrontendElement.selectedIndex].value)
(event) => translateHelper.setFrontend(event.target.options[translateFrontendElement.selectedIndex].value)
);