2020-08-27 07:22:46 +02:00
|
|
|
"use strict";
|
2019-10-07 13:59:31 +02:00
|
|
|
|
2022-02-04 16:48:24 +01:00
|
|
|
import youtubeHelper from "../../assets/javascripts/helpers/youtube/youtube.js";
|
2022-02-03 15:33:24 +01:00
|
|
|
import twitterHelper from "../../assets/javascripts/helpers/twitter.js";
|
2021-01-10 12:04:03 +01:00
|
|
|
import instagramHelper from "../../assets/javascripts/helpers/instagram.js";
|
|
|
|
import redditHelper from "../../assets/javascripts/helpers/reddit.js";
|
2022-02-02 19:22:34 +01:00
|
|
|
import searchHelper from "../../assets/javascripts/helpers/search.js";
|
2022-02-03 11:41:23 +01:00
|
|
|
import translateHelper from "../../assets/javascripts/helpers/translate.js";
|
|
|
|
import mapsHelper from "../../assets/javascripts/helpers/maps.js";
|
2022-02-03 15:33:24 +01:00
|
|
|
import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
|
|
|
|
import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
2022-02-08 21:04:18 +01:00
|
|
|
import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
|
2022-02-09 22:04:00 +01:00
|
|
|
import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
|
2022-03-08 17:12:09 +01:00
|
|
|
import pixivHelper from "../../assets/javascripts/helpers/pixiv.js";
|
2022-03-02 22:46:29 +01:00
|
|
|
import generalHelper from "../../assets/javascripts/helpers/general.js";
|
2022-02-23 21:45:22 +01:00
|
|
|
import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js";
|
2019-10-07 13:59:31 +02:00
|
|
|
|
2020-02-24 04:19:56 +01:00
|
|
|
window.browser = window.browser || window.chrome;
|
|
|
|
|
2022-02-20 17:00:12 +01:00
|
|
|
async function wholeInit() {
|
|
|
|
youtubeHelper.init()
|
2022-02-23 21:45:22 +01:00
|
|
|
youtubeMusicHelper.init()
|
2022-02-20 17:00:12 +01:00
|
|
|
twitterHelper.init()
|
|
|
|
instagramHelper.init()
|
2022-02-04 00:13:37 +01:00
|
|
|
mapsHelper.init()
|
|
|
|
searchHelper.init()
|
|
|
|
translateHelper.init()
|
|
|
|
mediumHelper.init()
|
|
|
|
redditHelper.init()
|
|
|
|
wikipediaHelper.init()
|
2022-02-08 21:04:18 +01:00
|
|
|
imgurHelper.init()
|
2022-02-09 22:04:00 +01:00
|
|
|
tiktokHelper.init()
|
2022-03-08 17:12:09 +01:00
|
|
|
pixivHelper.init()
|
2022-03-02 22:46:29 +01:00
|
|
|
generalHelper.init()
|
2022-02-20 17:00:12 +01:00
|
|
|
}
|
2022-02-04 00:13:37 +01:00
|
|
|
wholeInit();
|
|
|
|
|
|
|
|
browser.storage.onChanged.addListener(wholeInit);
|
2021-07-12 18:16:23 +02:00
|
|
|
|
2022-03-01 20:42:48 +01:00
|
|
|
let BYPASSTABs = [];
|
2022-02-26 13:38:13 +01:00
|
|
|
|
2020-02-24 04:19:56 +01:00
|
|
|
browser.webRequest.onBeforeRequest.addListener(
|
2022-03-05 09:44:59 +01:00
|
|
|
details => {
|
2022-03-07 04:37:58 +01:00
|
|
|
// console.log("url", details.url);
|
2020-02-01 04:17:51 +01:00
|
|
|
const url = new URL(details.url);
|
2020-03-31 08:39:57 +02:00
|
|
|
let initiator;
|
2022-01-30 21:36:07 +01:00
|
|
|
if (details.originUrl)
|
2020-03-31 08:39:57 +02:00
|
|
|
initiator = new URL(details.originUrl);
|
2022-01-30 21:36:07 +01:00
|
|
|
else if (details.initiator)
|
2020-07-12 03:26:48 +02:00
|
|
|
initiator = new URL(details.initiator);
|
2022-01-29 19:01:49 +01:00
|
|
|
|
2022-02-02 15:46:14 +01:00
|
|
|
var newUrl;
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (!newUrl) newUrl = youtubeHelper.redirect(url, details, initiator)
|
2022-03-05 09:44:59 +01:00
|
|
|
if (youtubeHelper.isPipedorInvidious(newUrl ?? url, details.type, 'invidious')) newUrl = youtubeHelper.addUrlParams(newUrl ?? url);
|
2022-02-26 13:38:13 +01:00
|
|
|
if (youtubeMusicHelper.isYoutubeMusic(url, initiator)) newUrl = youtubeMusicHelper.redirect(url, details.type)
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-03-01 20:42:48 +01:00
|
|
|
if (!newUrl) newUrl = twitterHelper.redirect(url, initiator);
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-03-05 17:37:16 +01:00
|
|
|
if (!newUrl) newUrl = instagramHelper.redirect(url, details.type, initiator);
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-03-07 04:37:58 +01:00
|
|
|
if (!newUrl) newUrl = mapsHelper.redirect(url, initiator);
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-02-26 16:28:19 +01:00
|
|
|
if (!newUrl) newUrl = redditHelper.redirect(url, details.type, initiator);
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (mediumHelper.isMedium(url, initiator)) newUrl = mediumHelper.redirect(url, details.type);
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (imgurHelper.isImgur(url, initiator)) newUrl = imgurHelper.redirect(url, details.type);
|
2022-02-08 21:04:18 +01:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (tiktokHelper.isTiktok(url, initiator)) newUrl = tiktokHelper.redirect(url, details.type);
|
2022-02-09 22:04:00 +01:00
|
|
|
|
2022-03-08 17:12:09 +01:00
|
|
|
if (!newUrl) newUrl = pixivHelper.redirect(url, details.type, initiator);
|
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (translateHelper.isTranslate(url, initiator)) newUrl = translateHelper.redirect(url);
|
2022-02-02 17:13:44 +01:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (searchHelper.isSearch(url)) newUrl = searchHelper.redirect(url)
|
2022-01-31 19:01:16 +01:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
if (wikipediaHelper.isWikipedia(url, initiator)) newUrl = wikipediaHelper.redirect(url);
|
2022-01-29 19:01:49 +01:00
|
|
|
|
2022-03-02 22:46:29 +01:00
|
|
|
if (generalHelper.isException(url, initiator)) newUrl = null;
|
2022-02-19 11:04:10 +01:00
|
|
|
|
2022-03-01 20:42:48 +01:00
|
|
|
if (BYPASSTABs.includes(details.tabId)) newUrl = null;
|
2022-02-26 13:38:13 +01:00
|
|
|
|
2022-01-29 19:01:49 +01:00
|
|
|
if (newUrl) {
|
2022-02-05 13:49:12 +01:00
|
|
|
if (newUrl == 'CANCEL') {
|
|
|
|
console.log(`Canceled ${url}`);
|
|
|
|
return { cancel: true };
|
|
|
|
}
|
2022-03-01 20:42:48 +01:00
|
|
|
else if (newUrl == 'BYPASSTAB') {
|
|
|
|
console.log(`Bybassed ${details.tabId} ${url}`);
|
|
|
|
BYPASSTABs.push(details.tabId);
|
2022-02-26 13:38:13 +01:00
|
|
|
return null;
|
|
|
|
}
|
2022-02-05 13:49:12 +01:00
|
|
|
else {
|
|
|
|
console.info("Redirecting", url.href, "=>", newUrl);
|
|
|
|
return { redirectUrl: newUrl };
|
|
|
|
}
|
2020-01-14 10:48:37 +01:00
|
|
|
}
|
2022-01-30 21:36:07 +01:00
|
|
|
return null;
|
2019-09-20 12:45:58 +02:00
|
|
|
},
|
2022-01-30 21:36:07 +01:00
|
|
|
{ urls: ["<all_urls>"], },
|
2020-08-27 07:22:46 +02:00
|
|
|
["blocking"]
|
2019-09-20 12:45:58 +02:00
|
|
|
);
|
2020-04-09 11:37:56 +02:00
|
|
|
|
2022-02-26 13:38:13 +01:00
|
|
|
browser.tabs.onRemoved.addListener((tabId) => {
|
2022-03-01 20:42:48 +01:00
|
|
|
let index = BYPASSTABs.indexOf(tabId);
|
|
|
|
if (index > -1) {
|
|
|
|
BYPASSTABs.splice(index, 1);
|
|
|
|
console.log("Removed BYPASSTABs", tabId);
|
|
|
|
}
|
2022-02-26 13:38:13 +01:00
|
|
|
});
|
|
|
|
|
2022-02-19 13:48:28 +01:00
|
|
|
browser.tabs.onUpdated.addListener(
|
2022-03-01 16:37:28 +01:00
|
|
|
(tabId, changeInfo, _) => {
|
2022-03-05 09:44:59 +01:00
|
|
|
let url;
|
|
|
|
try { url = new URL(changeInfo.url); }
|
|
|
|
catch (_) { return }
|
|
|
|
if (youtubeHelper.isPipedorInvidious(url, 'main_frame', 'piped')) youtubeHelper.initPipedLocalStorage(tabId);
|
2022-03-08 04:36:11 +01:00
|
|
|
if (twitterHelper.isNitter(url, 'main_frame')) twitterHelper.initNitterCookies(url);
|
2022-03-05 12:16:58 +01:00
|
|
|
if (instagramHelper.isBibliogram(url)) instagramHelper.initBibliogramCookies(url);
|
2022-03-05 09:44:59 +01:00
|
|
|
// if (changeInfo.url && youtubeHelper.isPipedorInvidious(url, 'main_frame', 'pipedMaterial')) youtubeHelper.initPipedMaterialLocalStorage(tabId);
|
2022-03-01 18:53:45 +01:00
|
|
|
// if (changeInfo.url && youtubeHelper.isUrlPipedorInvidious(changeInfo.url, 'invidious')) youtubeHelper.initInvidiousCookies(tabId);
|
2022-02-25 23:31:48 +01:00
|
|
|
});
|