Added alwaysUsePreferred to Twitter and Reddit
This commit is contained in:
parent
45ee90c9bb
commit
01020800a2
|
@ -1,10 +1,19 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
|
let alwaysUsePreferred;
|
||||||
|
const getAlwaysUsePreferred = () => alwaysUsePreferred;
|
||||||
|
function setAlwaysUsePreferred(val) {
|
||||||
|
alwaysUsePreferred = val;
|
||||||
|
browser.storage.local.set({ alwaysUsePreferred })
|
||||||
|
console.log("alwaysUsePreferred: ", alwaysUsePreferred)
|
||||||
|
}
|
||||||
|
|
||||||
let exceptions = {
|
let exceptions = {
|
||||||
"url": [],
|
"url": [],
|
||||||
"regex": [],
|
"regex": [],
|
||||||
};
|
};
|
||||||
|
|
||||||
const getExceptions = () => exceptions;
|
const getExceptions = () => exceptions;
|
||||||
function setExceptions(val) {
|
function setExceptions(val) {
|
||||||
exceptions = val;
|
exceptions = val;
|
||||||
|
@ -12,15 +21,6 @@ function setExceptions(val) {
|
||||||
console.log("exceptions: ", val)
|
console.log("exceptions: ", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
browser.storage.local.get("exceptions", (result) => {
|
|
||||||
if (result.exceptions) exceptions = result.exceptions;
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function isException(url) {
|
function isException(url) {
|
||||||
for (const item of exceptions.url) {
|
for (const item of exceptions.url) {
|
||||||
console.log(item, `${url.protocol}//${url.host}`)
|
console.log(item, `${url.protocol}//${url.host}`)
|
||||||
|
@ -31,10 +31,29 @@ function isException(url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
return new Promise(
|
||||||
|
resolve => browser.storage.local.get(
|
||||||
|
[
|
||||||
|
"exceptions",
|
||||||
|
"alwaysUsePreferred"
|
||||||
|
],
|
||||||
|
r => { // r = result
|
||||||
|
if (r.exceptions) exceptions = r.exceptions;
|
||||||
|
alwaysUsePreferred = r.alwaysUsePreferred ?? false;
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getExceptions,
|
getExceptions,
|
||||||
setExceptions,
|
setExceptions,
|
||||||
|
|
||||||
|
getAlwaysUsePreferred,
|
||||||
|
setAlwaysUsePreferred,
|
||||||
|
|
||||||
isException,
|
isException,
|
||||||
init,
|
init,
|
||||||
}
|
}
|
|
@ -3,13 +3,13 @@ window.browser = window.browser || window.chrome;
|
||||||
import commonHelper from './common.js'
|
import commonHelper from './common.js'
|
||||||
|
|
||||||
const targets = [
|
const targets = [
|
||||||
"reddit.com",
|
/^https?:\/\/reddit\.com/,
|
||||||
"www.reddit.com",
|
/^https?:\/\/www\.reddit\.com/,
|
||||||
"np.reddit.com",
|
/^https?:\/\/np\.reddit\.com/,
|
||||||
"new.reddit.com",
|
/^https?:\/\/new\.reddit\.com/,
|
||||||
"amp.reddit.com",
|
/^https?:\/\/amp\.reddit\.com/,
|
||||||
"i.redd.it",
|
/^https?:\/\/i\.redd\.it/,
|
||||||
"redd.it",
|
/^https?:\/\/redd\.it/,
|
||||||
];
|
];
|
||||||
let redirects = {
|
let redirects = {
|
||||||
// modern UI
|
// modern UI
|
||||||
|
@ -184,10 +184,6 @@ function setProtocol(val) {
|
||||||
console.log("redditProtocol: ", val)
|
console.log("redditProtocol: ", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isReddit(url,) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let bypassWatchOnReddit;
|
let bypassWatchOnReddit;
|
||||||
const getBypassWatchOnReddit = () => bypassWatchOnReddit;
|
const getBypassWatchOnReddit = () => bypassWatchOnReddit;
|
||||||
function setBypassWatchOnReddit(val) {
|
function setBypassWatchOnReddit(val) {
|
||||||
|
@ -196,9 +192,61 @@ function setBypassWatchOnReddit(val) {
|
||||||
console.log("bypassWatchOnReddit: ", bypassWatchOnReddit)
|
console.log("bypassWatchOnReddit: ", bypassWatchOnReddit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let alwaysUsePreferred;
|
||||||
|
|
||||||
|
|
||||||
|
// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4
|
||||||
|
// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png
|
||||||
|
|
||||||
|
// https://teddit.net/vids/1mq8d0ma3yk81.mp4
|
||||||
|
// https://teddit.net/pics/w:null_4v3t1vgvrzk81.png
|
||||||
|
|
||||||
|
|
||||||
|
// redd.it/t5379n
|
||||||
|
// https://v.redd.it/z08avb339n801/DASH_1_2_M
|
||||||
|
// https://i.redd.it/bfkhs659tzk81.jpg
|
||||||
|
|
||||||
function redirect(url, type, initiator) {
|
function redirect(url, type, initiator) {
|
||||||
if (disableReddit) return null;
|
if (disableReddit) return null;
|
||||||
|
|
||||||
|
let protocolHost = `${url.protocol}//${url.host}`;
|
||||||
|
|
||||||
|
let isTeddit = [
|
||||||
|
...redirects.teddit.normal,
|
||||||
|
...redirects.teddit.tor
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
|
let isCheckedTeddit = [
|
||||||
|
...tedditNormalRedirectsChecks,
|
||||||
|
...tedditNormalCustomRedirects,
|
||||||
|
...tedditTorRedirectsChecks,
|
||||||
|
...tedditTorCustomRedirects,
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
|
let isLibreddit = [
|
||||||
|
...redirects.libreddit.normal,
|
||||||
|
...redirects.libreddit.tor
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
|
let isCheckedLibreddit = [
|
||||||
|
...libredditNormalRedirectsChecks,
|
||||||
|
...libredditNormalCustomRedirects,
|
||||||
|
...libredditTorRedirectsChecks,
|
||||||
|
...libredditTorCustomRedirects,
|
||||||
|
].includes(protocolHost)
|
||||||
|
|
||||||
|
if (
|
||||||
|
alwaysUsePreferred && frontend == 'teddit' &&
|
||||||
|
(isTeddit || isLibreddit) && !isCheckedTeddit
|
||||||
|
) return changeInstance(url);
|
||||||
|
|
||||||
|
if (
|
||||||
|
alwaysUsePreferred && frontend == 'libreddit' &&
|
||||||
|
(isTeddit || isLibreddit) && !isCheckedLibreddit
|
||||||
|
) return changeInstance(url);
|
||||||
|
|
||||||
|
if (!targets.some((rx) => rx.test(url.href))) return null;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
bypassWatchOnReddit &&
|
bypassWatchOnReddit &&
|
||||||
initiator &&
|
initiator &&
|
||||||
|
@ -211,20 +259,15 @@ function redirect(url, type, initiator) {
|
||||||
...redirects.teddit.tor,
|
...redirects.teddit.tor,
|
||||||
...tedditNormalCustomRedirects,
|
...tedditNormalCustomRedirects,
|
||||||
...tedditTorCustomRedirects,
|
...tedditTorCustomRedirects,
|
||||||
].includes(initiator.origin) ||
|
].includes(initiator.origin)
|
||||||
targets.includes(initiator.host)
|
|
||||||
)
|
)
|
||||||
) return 'BYPASSTAB';
|
) return 'BYPASSTAB';
|
||||||
|
|
||||||
if ((!targets.includes(url.host))) return null;
|
|
||||||
|
|
||||||
if (type !== "main_frame" || url.pathname.match(bypassPaths)) return null;
|
if (type !== "main_frame" || url.pathname.match(bypassPaths)) return null;
|
||||||
|
|
||||||
if (frontend == 'old') {
|
if (frontend == 'old' && url.host !== "i.redd.it")
|
||||||
if (url.host === "i.redd.it") return null;
|
|
||||||
|
|
||||||
return `${redirects.desktop}${url.pathname}${url.search}`;
|
return `${redirects.desktop}${url.pathname}${url.search}`;
|
||||||
}
|
|
||||||
let libredditInstancesList;
|
let libredditInstancesList;
|
||||||
let tedditInstancesList;
|
let tedditInstancesList;
|
||||||
if (protocol == 'normal') {
|
if (protocol == 'normal') {
|
||||||
|
@ -236,31 +279,28 @@ function redirect(url, type, initiator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url.host === "i.redd.it") {
|
if (url.host === "i.redd.it") {
|
||||||
if (libredditInstancesList.length === 0) return null;
|
if (frontend == 'teddit') {
|
||||||
let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
|
if (tedditInstancesList.length === 0) return null;
|
||||||
// As of 2021-04-09, redirects for teddit images are nontrivial:
|
let tedditRandomInstance = commonHelper.getRandomInstance(tedditInstancesList);
|
||||||
// - navigating to the image before ever navigating to its page causes
|
return `${tedditRandomInstance}/pics/w:null_${url.pathname.substring(1)}${url.search}`;
|
||||||
// 404 error (probably needs fix on teddit project)
|
}
|
||||||
// - some image links on teddit are very different
|
|
||||||
// Therefore, don't support redirecting image links for teddit.
|
|
||||||
return `${libredditRandomInstance}/img${url.pathname}${url.search}`;
|
|
||||||
}
|
|
||||||
else if (url.host === "redd.it") {
|
|
||||||
if (frontend == 'libreddit') {
|
if (frontend == 'libreddit') {
|
||||||
if (libredditInstancesList.length === 0) return null;
|
if (libredditInstancesList.length === 0) return null;
|
||||||
let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
|
let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
|
||||||
return `${libredditRandomInstance}${url.pathname}${url.search}`;
|
return `${libredditRandomInstance}/img${url.pathname}${url.search}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (url.host === "redd.it") {
|
||||||
|
if (frontend == 'libreddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
||||||
|
if (libredditInstancesList.length === 0) return null;
|
||||||
|
let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
|
||||||
|
// https://redd.it/foo => https://libredd.it/comments/foo
|
||||||
|
return `${libredditRandomInstance}/comments${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
if (frontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
if (frontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
|
||||||
if (tedditInstancesList.length === 0) return null;
|
if (tedditInstancesList.length === 0) return null;
|
||||||
let tedditRandomInstance = commonHelper.getRandomInstance(tedditInstancesList);
|
let tedditRandomInstance = commonHelper.getRandomInstance(tedditInstancesList);
|
||||||
// As of 2021-04-22, redirects for teddit redd.it/foo links don't work.
|
// https://redd.it/foo => https://teddit.net/comments/foo
|
||||||
// It appears that adding "/comments" as a prefix works, so manually add
|
|
||||||
// that prefix if it is missing. Even though redd.it/comments/foo links
|
|
||||||
// don't seem to work or exist, guard against affecting those kinds of
|
|
||||||
// paths.
|
|
||||||
// Note the difference between redd.it/comments/foo (doesn't work) and
|
|
||||||
// teddit.net/comments/foo (works).
|
|
||||||
return `${tedditRandomInstance}/comments${url.pathname}${url.search}`;
|
return `${tedditRandomInstance}/comments${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,6 +319,16 @@ function redirect(url, type, initiator) {
|
||||||
function changeInstance(url) {
|
function changeInstance(url) {
|
||||||
let protocolHost = `${url.protocol}//${url.host}`;
|
let protocolHost = `${url.protocol}//${url.host}`;
|
||||||
|
|
||||||
|
let isTeddit = [
|
||||||
|
...redirects.teddit.normal,
|
||||||
|
...redirects.teddit.tor
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
|
let isLibreddit = [
|
||||||
|
...redirects.libreddit.normal,
|
||||||
|
...redirects.libreddit.tor
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
let redditList = [
|
let redditList = [
|
||||||
...redirects.libreddit.normal,
|
...redirects.libreddit.normal,
|
||||||
...redirects.libreddit.tor,
|
...redirects.libreddit.tor,
|
||||||
|
@ -299,20 +349,21 @@ function changeInstance(url) {
|
||||||
if (frontend == 'libreddit') {
|
if (frontend == 'libreddit') {
|
||||||
if (protocol == 'normal') instancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects];
|
if (protocol == 'normal') instancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects];
|
||||||
else if (protocol == 'tor') instancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects];
|
else if (protocol == 'tor') instancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects];
|
||||||
|
if (isTeddit) url.pathname = url.pathname.replace("/pics/w:null_", "/img/");
|
||||||
}
|
}
|
||||||
else if (frontend == 'teddit') {
|
else if (frontend == 'teddit') {
|
||||||
if (protocol == 'normal') instancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects];
|
if (protocol == 'normal') instancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects];
|
||||||
else if (protocol == 'tor') instancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects];
|
else if (protocol == 'tor') instancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects];
|
||||||
|
if (isLibreddit) url.pathname = url.pathname.replace("/img/", "/pics/w:null_");
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("instancesList", instancesList);
|
|
||||||
let index = instancesList.indexOf(protocolHost);
|
let index = instancesList.indexOf(protocolHost);
|
||||||
if (index > -1) instancesList.splice(index, 1);
|
if (index > -1) instancesList.splice(index, 1);
|
||||||
|
|
||||||
if (instancesList.length === 0) return null;
|
if (instancesList.length === 0) return null;
|
||||||
|
|
||||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||||
return randomInstance;
|
|
||||||
|
return `${randomInstance}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
|
@ -337,6 +388,8 @@ async function init() {
|
||||||
|
|
||||||
"redditProtocol",
|
"redditProtocol",
|
||||||
"bypassWatchOnReddit",
|
"bypassWatchOnReddit",
|
||||||
|
|
||||||
|
"alwaysUsePreferred",
|
||||||
], (result) => {
|
], (result) => {
|
||||||
disableReddit = result.disableReddit ?? false;
|
disableReddit = result.disableReddit ?? false;
|
||||||
protocol = result.redditProtocol ?? 'normal';
|
protocol = result.redditProtocol ?? 'normal';
|
||||||
|
@ -344,6 +397,8 @@ async function init() {
|
||||||
|
|
||||||
bypassWatchOnReddit = result.bypassWatchOnReddit ?? true;
|
bypassWatchOnReddit = result.bypassWatchOnReddit ?? true;
|
||||||
|
|
||||||
|
alwaysUsePreferred = result.alwaysUsePreferred ?? true;
|
||||||
|
|
||||||
redirects.teddit = dataJson.teddit;
|
redirects.teddit = dataJson.teddit;
|
||||||
if (result.redditRedirects) redirects = result.redditRedirects;
|
if (result.redditRedirects) redirects = result.redditRedirects;
|
||||||
|
|
||||||
|
@ -408,7 +463,6 @@ export default {
|
||||||
setTedditTorCustomRedirects,
|
setTedditTorCustomRedirects,
|
||||||
|
|
||||||
redirect,
|
redirect,
|
||||||
isReddit,
|
|
||||||
init,
|
init,
|
||||||
changeInstance,
|
changeInstance,
|
||||||
};
|
};
|
||||||
|
|
|
@ -102,7 +102,23 @@ function setBypassWatchOnTwitter(val) {
|
||||||
console.log("bypassWatchOnTwitter: ", bypassWatchOnTwitter)
|
console.log("bypassWatchOnTwitter: ", bypassWatchOnTwitter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let alwaysUsePreferred;
|
||||||
|
|
||||||
function redirect(url, initiator) {
|
function redirect(url, initiator) {
|
||||||
|
let protocolHost = `${url.protocol}//${url.host}`;
|
||||||
|
let isNitter = [
|
||||||
|
...redirects.nitter.normal,
|
||||||
|
...redirects.nitter.tor
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
|
let isCheckedNitter = [
|
||||||
|
...nitterNormalRedirectsChecks,
|
||||||
|
...nitterNormalCustomRedirects,
|
||||||
|
...nitterTorRedirectsChecks,
|
||||||
|
...nitterTorCustomRedirects
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
|
if (alwaysUsePreferred && isNitter && !isCheckedNitter) return changeInstance(url);
|
||||||
|
|
||||||
if (disable) return null;
|
if (disable) return null;
|
||||||
|
|
||||||
|
@ -112,13 +128,13 @@ function redirect(url, initiator) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
bypassWatchOnTwitter &&
|
bypassWatchOnTwitter &&
|
||||||
initiator && (
|
initiator &&
|
||||||
[...redirects.nitter.normal,
|
[...redirects.nitter.normal,
|
||||||
...redirects.nitter.tor,
|
...redirects.nitter.tor,
|
||||||
...nitterTorCustomRedirects,
|
...nitterTorCustomRedirects,
|
||||||
...nitterNormalCustomRedirects
|
...nitterNormalCustomRedirects
|
||||||
].includes(initiator.origin)
|
].includes(initiator.origin)
|
||||||
)
|
|
||||||
) return 'BYPASSTAB';
|
) return 'BYPASSTAB';
|
||||||
|
|
||||||
let instancesList;
|
let instancesList;
|
||||||
|
@ -179,6 +195,7 @@ async function init() {
|
||||||
"nitterTorRedirectsChecks",
|
"nitterTorRedirectsChecks",
|
||||||
"nitterTorCustomRedirects",
|
"nitterTorCustomRedirects",
|
||||||
"twitterProtocol",
|
"twitterProtocol",
|
||||||
|
"alwaysUsePreferred",
|
||||||
],
|
],
|
||||||
(result) => {
|
(result) => {
|
||||||
disable = result.disableTwitter ?? false;
|
disable = result.disableTwitter ?? false;
|
||||||
|
@ -187,6 +204,8 @@ async function init() {
|
||||||
|
|
||||||
bypassWatchOnTwitter = result.bypassWatchOnTwitter ?? true;
|
bypassWatchOnTwitter = result.bypassWatchOnTwitter ?? true;
|
||||||
|
|
||||||
|
alwaysUsePreferred = result.alwaysUsePreferred ?? true;
|
||||||
|
|
||||||
redirects.nitter = dataJson.nitter;
|
redirects.nitter = dataJson.nitter;
|
||||||
if (result.twitterRedirects) redirects = result.twitterRedirects;
|
if (result.twitterRedirects) redirects = result.twitterRedirects;
|
||||||
|
|
||||||
|
|
|
@ -233,14 +233,6 @@ function setPersistInvidiousPrefs(val) {
|
||||||
console.log("persistInvidiousPrefs: ", persistInvidiousPrefs)
|
console.log("persistInvidiousPrefs: ", persistInvidiousPrefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
let alwaysusePreferred;
|
|
||||||
const getAlwaysusePreferred = () => alwaysusePreferred;
|
|
||||||
function setAlwaysusePreferred(val) {
|
|
||||||
alwaysusePreferred = val;
|
|
||||||
browser.storage.local.set({ alwaysusePreferred })
|
|
||||||
console.log("alwaysusePreferred: ", alwaysusePreferred)
|
|
||||||
}
|
|
||||||
|
|
||||||
let bypassWatchOnYoutube;
|
let bypassWatchOnYoutube;
|
||||||
const getBypassWatchOnYoutube = () => bypassWatchOnYoutube;
|
const getBypassWatchOnYoutube = () => bypassWatchOnYoutube;
|
||||||
function setBypassWatchOnYoutube(val) {
|
function setBypassWatchOnYoutube(val) {
|
||||||
|
@ -271,57 +263,54 @@ function isException(url) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let alwaysUsePreferred;
|
||||||
function redirect(url, details, initiator) {
|
function redirect(url, details, initiator) {
|
||||||
if (disable) return null;
|
if (disable) return null;
|
||||||
|
|
||||||
let isTargets = targets.some((rx) => rx.test(url.href));
|
|
||||||
let protocolHost = `${url.protocol}//${url.host}`;
|
let protocolHost = `${url.protocol}//${url.host}`;
|
||||||
|
|
||||||
let isInvidious = [...redirects.invidious.normal, ...redirects.invidious.tor].includes(protocolHost);
|
let isInvidious = [
|
||||||
if (isInvidious) {
|
...redirects.invidious.normal,
|
||||||
let myInvidiousInstances = [
|
...redirects.invidious.tor
|
||||||
...invidiousNormalRedirectsChecks,
|
].includes(protocolHost);
|
||||||
...invidiousNormalCustomRedirects,
|
|
||||||
|
|
||||||
...invidiousTorRedirectsChecks,
|
let isCheckedInvidious = [
|
||||||
...invidiousTorCustomRedirects,
|
...invidiousNormalRedirectsChecks,
|
||||||
];
|
...invidiousNormalCustomRedirects,
|
||||||
for (const item of myInvidiousInstances) if (item == protocolHost) isInvidious = false;
|
...invidiousTorRedirectsChecks,
|
||||||
}
|
...invidiousTorCustomRedirects,
|
||||||
|
].includes(protocolHost);
|
||||||
|
|
||||||
let isPiped = [...redirects.piped.normal, ...redirects.piped.tor].includes(protocolHost);
|
let isPiped = [
|
||||||
if (isPiped) {
|
...redirects.piped.normal,
|
||||||
let myPipedInstances = [
|
...redirects.piped.tor
|
||||||
...pipedNormalRedirectsChecks,
|
].includes(protocolHost);
|
||||||
...pipedNormalCustomRedirects,
|
|
||||||
|
|
||||||
...pipedTorRedirectsChecks,
|
let isCheckedPiped = [
|
||||||
...pipedTorCustomRedirects,
|
...pipedNormalRedirectsChecks,
|
||||||
];
|
...pipedNormalCustomRedirects,
|
||||||
for (const item of myPipedInstances) if (item == protocolHost) isPiped = false;
|
...pipedTorRedirectsChecks,
|
||||||
}
|
...pipedTorCustomRedirects,
|
||||||
|
].includes(protocolHost)
|
||||||
|
|
||||||
if (frontend == 'invidious') {
|
if (
|
||||||
if (alwaysusePreferred) {
|
alwaysUsePreferred && frontend == 'invidious' &&
|
||||||
if (!(isTargets | redirects.piped.normal.includes(protocolHost) | isInvidious)) return null;
|
(isInvidious || isPiped) && !isCheckedInvidious
|
||||||
}
|
) return changeInstance(url);
|
||||||
else {
|
|
||||||
if (!(isTargets | isPiped)) return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (frontend == 'piped') {
|
|
||||||
if (alwaysusePreferred) {
|
|
||||||
if (!(isTargets | isPiped | redirects.invidious.normal.includes(protocolHost))) return null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!(isTargets | isInvidious)) return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (!isTargets) return null;
|
|
||||||
|
|
||||||
|
if (
|
||||||
|
alwaysUsePreferred && frontend == 'piped' &&
|
||||||
|
(isInvidious || isPiped) && !isCheckedPiped
|
||||||
|
) return changeInstance(url);
|
||||||
|
|
||||||
if (details.type != "main_frame" && details.frameAncestors && details.frameAncestors.length > 0 && isException(new URL(details.frameAncestors[0].url))) {
|
if (!targets.some((rx) => rx.test(url.href))) return null;
|
||||||
|
|
||||||
|
if (
|
||||||
|
details.type != "main_frame" &&
|
||||||
|
details.frameAncestors && details.frameAncestors.length > 0 &&
|
||||||
|
isException(new URL(details.frameAncestors[0].url))
|
||||||
|
) {
|
||||||
console.log(`Canceled ${url.href}`, details.frameAncestors[0].url)
|
console.log(`Canceled ${url.href}`, details.frameAncestors[0].url)
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -366,11 +355,10 @@ function redirect(url, details, initiator) {
|
||||||
let instancesList;
|
let instancesList;
|
||||||
if (protocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
|
if (protocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
|
||||||
else if (protocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
|
else if (protocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
|
||||||
|
|
||||||
if (instancesList.length === 0) return null;
|
if (instancesList.length === 0) return null;
|
||||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||||
|
|
||||||
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
return `${randomInstance}${url.pathname}${url.search}`;
|
||||||
|
|
||||||
} else if (
|
} else if (
|
||||||
frontend == 'piped' ||
|
frontend == 'piped' ||
|
||||||
|
@ -389,7 +377,7 @@ function redirect(url, details, initiator) {
|
||||||
if (instancesList.length === 0) return null;
|
if (instancesList.length === 0) return null;
|
||||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||||
|
|
||||||
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
return `${randomInstance}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
return 'CANCEL';
|
return 'CANCEL';
|
||||||
}
|
}
|
||||||
|
@ -612,7 +600,7 @@ async function init() {
|
||||||
|
|
||||||
"pipedTorRedirectsChecks",
|
"pipedTorRedirectsChecks",
|
||||||
"pipedTorCustomRedirects",
|
"pipedTorCustomRedirects",
|
||||||
"alwaysusePreferred",
|
"alwaysUsePreferred",
|
||||||
"youtubeEmbedFrontend",
|
"youtubeEmbedFrontend",
|
||||||
|
|
||||||
"youtubeProtocol",
|
"youtubeProtocol",
|
||||||
|
@ -653,7 +641,7 @@ async function init() {
|
||||||
|
|
||||||
persistInvidiousPrefs = result.persistInvidiousPrefs ?? false;
|
persistInvidiousPrefs = result.persistInvidiousPrefs ?? false;
|
||||||
|
|
||||||
alwaysusePreferred = result.alwaysusePreferred ?? true;
|
alwaysUsePreferred = result.alwaysUsePreferred ?? true;
|
||||||
|
|
||||||
bypassWatchOnYoutube = result.bypassWatchOnYoutube ?? true;
|
bypassWatchOnYoutube = result.bypassWatchOnYoutube ?? true;
|
||||||
|
|
||||||
|
@ -746,9 +734,6 @@ export default {
|
||||||
getPipedTorCustomRedirects,
|
getPipedTorCustomRedirects,
|
||||||
setPipedTorCustomRedirects,
|
setPipedTorCustomRedirects,
|
||||||
|
|
||||||
getAlwaysusePreferred,
|
|
||||||
setAlwaysusePreferred,
|
|
||||||
|
|
||||||
getExceptions,
|
getExceptions,
|
||||||
setExceptions,
|
setExceptions,
|
||||||
isException,
|
isException,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
|
||||||
import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
||||||
import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
|
import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
|
||||||
import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
|
import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
|
||||||
import exceptionsHelper from "../../assets/javascripts/helpers/exceptions.js";
|
import generalHelper from "../../assets/javascripts/helpers/general.js";
|
||||||
import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js";
|
import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js";
|
||||||
|
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
@ -29,7 +29,7 @@ async function wholeInit() {
|
||||||
wikipediaHelper.init()
|
wikipediaHelper.init()
|
||||||
imgurHelper.init()
|
imgurHelper.init()
|
||||||
tiktokHelper.init()
|
tiktokHelper.init()
|
||||||
exceptionsHelper.init()
|
generalHelper.init()
|
||||||
|
|
||||||
}
|
}
|
||||||
wholeInit();
|
wholeInit();
|
||||||
|
@ -73,7 +73,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
||||||
|
|
||||||
if (wikipediaHelper.isWikipedia(url, initiator)) newUrl = wikipediaHelper.redirect(url);
|
if (wikipediaHelper.isWikipedia(url, initiator)) newUrl = wikipediaHelper.redirect(url);
|
||||||
|
|
||||||
if (exceptionsHelper.isException(url, initiator)) newUrl = null;
|
if (generalHelper.isException(url, initiator)) newUrl = null;
|
||||||
|
|
||||||
if (BYPASSTABs.includes(details.tabId)) newUrl = null;
|
if (BYPASSTABs.includes(details.tabId)) newUrl = null;
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,10 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="some-block option-block">
|
||||||
|
<h4>Always use Preferred Instances</h4>
|
||||||
|
<input id="always-use-preferred" type="checkbox" checked />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<h4>Exceptions</h4>
|
<h4>Exceptions</h4>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
|
|
||||||
import commonHelper from "../../../assets/javascripts/helpers/common.js";
|
import commonHelper from "../../../assets/javascripts/helpers/common.js";
|
||||||
import exceptionsHelper from "../../../assets/javascripts/helpers/exceptions.js";
|
import generalHelper from "../../../assets/javascripts/helpers/general.js";
|
||||||
|
|
||||||
let themeElement = document.getElementById("theme");
|
let themeElement = document.getElementById("theme");
|
||||||
|
|
||||||
|
@ -44,32 +44,42 @@ function exportSettings() {
|
||||||
}
|
}
|
||||||
exportSettings();
|
exportSettings();
|
||||||
|
|
||||||
|
browser.storage.onChanged.addListener(exportSettings);
|
||||||
|
|
||||||
let importSettingsElement = document.getElementById("import-settings");
|
let importSettingsElement = document.getElementById("import-settings");
|
||||||
importSettingsElement.addEventListener("change",
|
importSettingsElement.addEventListener("change",
|
||||||
_ => {
|
() => {
|
||||||
let file = importSettingsElement.files[0];
|
let file = importSettingsElement.files[0];
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
reader.onload = () => browser.storage.local.set({ ...JSON.parse(reader.result) })
|
reader.onload = () => browser.storage.local.set({ ...JSON.parse(reader.result) })
|
||||||
reader.onerror = error => reject(error);
|
reader.onerror = error => reject(error);
|
||||||
exportSettings();
|
location.reload();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
let resetSettingsElement = document.getElementById("reset-settings");
|
let resetSettingsElement = document.getElementById("reset-settings");
|
||||||
|
|
||||||
resetSettingsElement.addEventListener("click",
|
resetSettingsElement.addEventListener("click",
|
||||||
() => {
|
() => {
|
||||||
console.log("reset");
|
console.log("reset");
|
||||||
browser.storage.local.clear();
|
browser.storage.local.clear();
|
||||||
exportSettings();
|
location.reload();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let alwaysUsePreferredElement = document.getElementById("always-use-preferred")
|
||||||
|
alwaysUsePreferredElement.addEventListener("change",
|
||||||
|
event => generalHelper.setAlwaysUsePreferred(event.target.checked)
|
||||||
|
);
|
||||||
|
|
||||||
let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance");
|
let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance");
|
||||||
let instanceTypeElement = document.getElementById("exceptions-custom-instance-type");
|
let instanceTypeElement = document.getElementById("exceptions-custom-instance-type");
|
||||||
let instanceType = "url"
|
let instanceType = "url"
|
||||||
|
|
||||||
exceptionsHelper.init().then(() => {
|
generalHelper.init().then(() => {
|
||||||
|
alwaysUsePreferredElement.checked = generalHelper.getAlwaysUsePreferred();
|
||||||
|
console.log("generalHelper.getAlwaysUsePreferred()");
|
||||||
instanceTypeElement.addEventListener("change",
|
instanceTypeElement.addEventListener("change",
|
||||||
(event) => {
|
(event) => {
|
||||||
instanceType = event.target.options[instanceTypeElement.selectedIndex].value
|
instanceType = event.target.options[instanceTypeElement.selectedIndex].value
|
||||||
|
@ -83,7 +93,7 @@ exceptionsHelper.init().then(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
let exceptionsCustomInstances = exceptionsHelper.getExceptions();
|
let exceptionsCustomInstances = generalHelper.getExceptions();
|
||||||
function calcExceptionsCustomInstances() {
|
function calcExceptionsCustomInstances() {
|
||||||
console.log("exceptionsCustomInstances", exceptionsCustomInstances)
|
console.log("exceptionsCustomInstances", exceptionsCustomInstances)
|
||||||
document.getElementById("exceptions-custom-checklist").innerHTML =
|
document.getElementById("exceptions-custom-checklist").innerHTML =
|
||||||
|
@ -112,7 +122,7 @@ exceptionsHelper.init().then(() => {
|
||||||
if (index > -1)
|
if (index > -1)
|
||||||
exceptionsCustomInstances.regex.splice(index, 1);
|
exceptionsCustomInstances.regex.splice(index, 1);
|
||||||
}
|
}
|
||||||
exceptionsHelper.setExceptions(exceptionsCustomInstances);
|
generalHelper.setExceptions(exceptionsCustomInstances);
|
||||||
calcExceptionsCustomInstances();
|
calcExceptionsCustomInstances();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -133,7 +143,7 @@ exceptionsHelper.init().then(() => {
|
||||||
if (val.trim() != '' && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val)
|
if (val.trim() != '' && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val)
|
||||||
}
|
}
|
||||||
if (val) {
|
if (val) {
|
||||||
exceptionsHelper.setExceptions(exceptionsCustomInstances);
|
generalHelper.setExceptions(exceptionsCustomInstances);
|
||||||
console.log("exceptionsCustomInstances", exceptionsCustomInstances)
|
console.log("exceptionsCustomInstances", exceptionsCustomInstances)
|
||||||
nameCustomInstanceInput.value = '';
|
nameCustomInstanceInput.value = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,6 +78,7 @@ redditHelper.init().then(() => {
|
||||||
protocolElement.value = protocol;
|
protocolElement.value = protocol;
|
||||||
changeProtocolSettings(protocol);
|
changeProtocolSettings(protocol);
|
||||||
|
|
||||||
|
|
||||||
commonHelper.processDefaultCustomInstances(
|
commonHelper.processDefaultCustomInstances(
|
||||||
'libreddit',
|
'libreddit',
|
||||||
'normal',
|
'normal',
|
||||||
|
|
|
@ -136,11 +136,6 @@
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="some-block option-block">
|
|
||||||
<h4>Always use Preferred Instances</h4>
|
|
||||||
<input id="always-use-preferred" type="checkbox" checked />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<h4>Bypass Watch On YouTube</h4>
|
<h4>Bypass Watch On YouTube</h4>
|
||||||
<input id="bypass-watch-on-youtube" type="checkbox" checked />
|
<input id="bypass-watch-on-youtube" type="checkbox" checked />
|
||||||
|
|
|
@ -100,11 +100,6 @@ OnlyEmbeddedVideoElement.addEventListener("change",
|
||||||
event => youtubeHelper.setOnlyEmbeddedVideo(event.target.options[OnlyEmbeddedVideoElement.selectedIndex].value)
|
event => youtubeHelper.setOnlyEmbeddedVideo(event.target.options[OnlyEmbeddedVideoElement.selectedIndex].value)
|
||||||
);
|
);
|
||||||
|
|
||||||
let alwaysUsePreferredElement = document.getElementById("always-use-preferred")
|
|
||||||
alwaysUsePreferredElement.addEventListener("change",
|
|
||||||
event => youtubeHelper.setAlwaysusePreferred(event.target.checked)
|
|
||||||
);
|
|
||||||
|
|
||||||
let bypassWatchOnYoutubeElement = document.getElementById("bypass-watch-on-youtube")
|
let bypassWatchOnYoutubeElement = document.getElementById("bypass-watch-on-youtube")
|
||||||
bypassWatchOnYoutubeElement.addEventListener("change",
|
bypassWatchOnYoutubeElement.addEventListener("change",
|
||||||
event => youtubeHelper.setBypassWatchOnYoutube(event.target.checked)
|
event => youtubeHelper.setBypassWatchOnYoutube(event.target.checked)
|
||||||
|
@ -145,7 +140,6 @@ youtubeHelper.init().then(() => {
|
||||||
volumeElement.value = youtubeHelper.getVolume();
|
volumeElement.value = youtubeHelper.getVolume();
|
||||||
volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`;
|
volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`;
|
||||||
OnlyEmbeddedVideoElement.value = youtubeHelper.getOnlyEmbeddedVideo();
|
OnlyEmbeddedVideoElement.value = youtubeHelper.getOnlyEmbeddedVideo();
|
||||||
alwaysUsePreferredElement.checked = youtubeHelper.getAlwaysusePreferred();
|
|
||||||
bypassWatchOnYoutubeElement.checked = youtubeHelper.getBypassWatchOnYoutube();
|
bypassWatchOnYoutubeElement.checked = youtubeHelper.getBypassWatchOnYoutube();
|
||||||
autoplayElement.value = youtubeHelper.getAutoplay();
|
autoplayElement.value = youtubeHelper.getAutoplay();
|
||||||
let frontend = youtubeHelper.getFrontend();
|
let frontend = youtubeHelper.getFrontend();
|
||||||
|
|
Loading…
Reference in New Issue