Closes #111 - Adds ability to customise random instance pools
This commit is contained in:
parent
056af8aff6
commit
4bf5f20ad4
|
@ -110,5 +110,17 @@
|
|||
"useFreeTube": {
|
||||
"message": "Use FreeTube over Invidious when possible",
|
||||
"description": "Label for 'Use FreeTube over Invidious when possible' option (options)."
|
||||
},
|
||||
"nitterRandomPool": {
|
||||
"message": "Nitter random instance pool (comma-separated)",
|
||||
"description": "Label for 'Nitter random instance pool (comma-separated)' option (options)."
|
||||
},
|
||||
"invidiousRandomPool": {
|
||||
"message": "Invidious random instance pool (comma-separated)",
|
||||
"description": "Label for 'Invidious random instance pool (comma-separated)' option (options)."
|
||||
},
|
||||
"bibliogramRandomPool": {
|
||||
"message": "Bibliogram random instance pool (comma-separated)",
|
||||
"description": "Label for 'Bibliogram random instance pool (comma-separated)' option (options)."
|
||||
}
|
||||
}
|
||||
|
|
104
background.js
104
background.js
|
@ -11,21 +11,6 @@ const youtubeDomains = [
|
|||
"s.ytimg.com",
|
||||
"music.youtube.com",
|
||||
];
|
||||
const invidiousInstances = [
|
||||
"https://invidious.snopyta.org",
|
||||
"https://invidious.site",
|
||||
"https://invidious.zapashcanon.fr",
|
||||
"https://invidiou.site",
|
||||
"https://invidious.kavin.rocks",
|
||||
"https://tube.connect.cafe",
|
||||
];
|
||||
const twitterDomains = [
|
||||
"twitter.com",
|
||||
"www.twitter.com",
|
||||
"mobile.twitter.com",
|
||||
"pbs.twimg.com",
|
||||
"video.twimg.com",
|
||||
];
|
||||
const nitterInstances = [
|
||||
"https://nitter.net",
|
||||
"https://nitter.snopyta.org",
|
||||
|
@ -34,13 +19,41 @@ const nitterInstances = [
|
|||
"https://nitter.13ad.de",
|
||||
"https://nitter.pussthecat.org",
|
||||
"https://nitter.mastodont.cat",
|
||||
"https://nitter.dark.fail",
|
||||
"https://nitter.tedomum.net",
|
||||
"https://nitter.cattube.org",
|
||||
"https://nitter.fdn.fr",
|
||||
"https://nitter.1d4.us",
|
||||
"https://nitter.kavin.rocks",
|
||||
"https://nitter.dark.fail",
|
||||
"https://tweet.lambda.dance",
|
||||
"https://nitter.cc",
|
||||
"https://nitter.weaponizedhumiliation.com",
|
||||
"https://nitter.vxempire.xyz",
|
||||
"http://3nzoldnxplag42gqjs23xvghtzf6t6yzssrtytnntc6ppc7xxuoneoad.onion",
|
||||
"http://nitter.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd.onion",
|
||||
"http://nitterlgj3n5fgwesu3vxc5h67ruku33nqaoeoocae2mvlzhsu6k7fqd.onion",
|
||||
"http://npf37k3mtzwxreiw52ccs5ay4e6qt2fkcs2ndieurdyn2cuzzsfyfvid.onion",
|
||||
];
|
||||
const twitterDomains = [
|
||||
"twitter.com",
|
||||
"www.twitter.com",
|
||||
"mobile.twitter.com",
|
||||
"pbs.twimg.com",
|
||||
"video.twimg.com",
|
||||
];
|
||||
const invidiousInstances = [
|
||||
"https://invidious.snopyta.org",
|
||||
"https://invidious.xyz",
|
||||
"https://invidious.kavin.rocks",
|
||||
"https://tube.connect.cafe",
|
||||
"https://invidious.zapashcanon.fr",
|
||||
"https://invidiou.site",
|
||||
"https://vid.mint.lgbt",
|
||||
"https://invidious.site",
|
||||
"http://fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad.onion",
|
||||
"http://qklhadlycap4cnod.onion",
|
||||
"http://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion",
|
||||
"http://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion",
|
||||
];
|
||||
const instagramDomains = [
|
||||
"instagram.com",
|
||||
|
@ -82,6 +95,7 @@ const bibliogramInstances = [
|
|||
"https://bg.endl.site",
|
||||
"https://bibliogram.13ad.de",
|
||||
"https://bibliogram.pixelfed.uno",
|
||||
"https://bibliogram.ethibox.fr",
|
||||
"https://bibliogram.hamster.dance",
|
||||
"https://bibliogram.kavin.rocks",
|
||||
"https://bibliogram.ggc-project.de",
|
||||
|
@ -96,7 +110,7 @@ const redditDomains = [
|
|||
const redditBypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/;
|
||||
const oldRedditViews = [
|
||||
"https://old.reddit.com", // desktop
|
||||
"https://i.reddit.com" // mobile
|
||||
"https://i.reddit.com", // mobile
|
||||
];
|
||||
const oldRedditDefaultView = oldRedditViews[0];
|
||||
const googleMapsRegex = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/;
|
||||
|
@ -135,10 +149,17 @@ let invidiousPlayerStyle;
|
|||
let invidiousSubtitles;
|
||||
let invidiousAutoplay;
|
||||
let useFreeTube;
|
||||
let nitterRandomPool;
|
||||
let invidiousRandomPool;
|
||||
let bibliogramRandomPool;
|
||||
let exceptions;
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
function filterInstances(instances) {
|
||||
return instances.filter((instance) => !instance.includes(".onion"));
|
||||
}
|
||||
|
||||
browser.storage.sync.get(
|
||||
[
|
||||
"nitterInstance",
|
||||
|
@ -160,6 +181,9 @@ browser.storage.sync.get(
|
|||
"invidiousSubtitles",
|
||||
"invidiousAutoplay",
|
||||
"useFreeTube",
|
||||
"nitterRandomPool",
|
||||
"invidiousRandomPool",
|
||||
"bibliogramRandomPool",
|
||||
"exceptions",
|
||||
],
|
||||
(result) => {
|
||||
|
@ -187,6 +211,15 @@ browser.storage.sync.get(
|
|||
invidiousSubtitles = result.invidiousSubtitles || "";
|
||||
invidiousAutoplay = result.invidiousAutoplay;
|
||||
useFreeTube = result.useFreeTube;
|
||||
nitterRandomPool = result.nitterRandomPool
|
||||
? result.nitterRandomPool.split(",")
|
||||
: filterInstances(nitterInstances);
|
||||
invidiousRandomPool = result.invidiousRandomPool
|
||||
? result.invidiousRandomPool.split(",")
|
||||
: filterInstances(invidiousInstances);
|
||||
bibliogramRandomPool = result.bibliogramRandomPool
|
||||
? result.bibliogramRandomPool.split(",")
|
||||
: filterInstances(bibliogramInstances);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -248,6 +281,15 @@ browser.storage.onChanged.addListener((changes) => {
|
|||
if ("useFreeTube" in changes) {
|
||||
useFreeTube = changes.useFreeTube.newValue;
|
||||
}
|
||||
if ("nitterRandomPool" in changes) {
|
||||
nitterRandomPool = changes.nitterRandomPool.newValue.split(",");
|
||||
}
|
||||
if ("invidiousRandomPool" in changes) {
|
||||
invidiousRandomPool = changes.invidiousRandomPool.newValue.split(",");
|
||||
}
|
||||
if ("bibliogramRandomPool" in changes) {
|
||||
bibliogramRandomPool = changes.bibliogramRandomPool.newValue.split(",");
|
||||
}
|
||||
if ("exceptions" in changes) {
|
||||
exceptions = changes.exceptions.newValue.map((e) => {
|
||||
return new RegExp(e);
|
||||
|
@ -318,7 +360,7 @@ function redirectYouTube(url, initiator, type) {
|
|||
if (onlyEmbeddedVideo && type !== "sub_frame") {
|
||||
return null;
|
||||
}
|
||||
if (useFreeTube && type !== "sub_frame") {
|
||||
if (useFreeTube && type === "main_frame") {
|
||||
return `freetube://${url}`;
|
||||
}
|
||||
// Apply settings
|
||||
|
@ -343,7 +385,7 @@ function redirectYouTube(url, initiator, type) {
|
|||
url.searchParams.append("autoplay", invidiousAutoplay ? 1 : 0);
|
||||
|
||||
return `${
|
||||
invidiousInstance || getRandomInstance(invidiousInstances)
|
||||
invidiousInstance || getRandomInstance(invidiousRandomPool)
|
||||
}${url.pathname.replace("/shorts", "")}${url.search}`;
|
||||
}
|
||||
|
||||
|
@ -368,18 +410,18 @@ function redirectTwitter(url, initiator) {
|
|||
}
|
||||
if (url.host.split(".")[0] === "pbs") {
|
||||
return `${
|
||||
nitterInstance || getRandomInstance(nitterInstances)
|
||||
nitterInstance || getRandomInstance(nitterRandomPool)
|
||||
}/pic/${encodeURIComponent(url.href)}`;
|
||||
} else if (url.host.split(".")[0] === "video") {
|
||||
return `${
|
||||
nitterInstance || getRandomInstance(nitterInstances)
|
||||
nitterInstance || getRandomInstance(nitterRandomPool)
|
||||
}/gif/${encodeURIComponent(url.href)}`;
|
||||
} else if (url.pathname.includes("tweets")) {
|
||||
return `${
|
||||
nitterInstance || getRandomInstance(nitterInstances)
|
||||
nitterInstance || getRandomInstance(nitterRandomPool)
|
||||
}${url.pathname.replace("/tweets", "")}${url.search}`;
|
||||
} else {
|
||||
return `${nitterInstance || getRandomInstance(nitterInstances)}${
|
||||
return `${nitterInstance || getRandomInstance(nitterRandomPool)}${
|
||||
url.pathname
|
||||
}${url.search}`;
|
||||
}
|
||||
|
@ -406,12 +448,12 @@ function redirectInstagram(url, initiator, type) {
|
|||
url.pathname === "/" ||
|
||||
instagramReservedPaths.includes(url.pathname.split("/")[1])
|
||||
) {
|
||||
return `${bibliogramInstance || getRandomInstance(bibliogramInstances)}${
|
||||
return `${bibliogramInstance || getRandomInstance(bibliogramRandomPool)}${
|
||||
url.pathname
|
||||
}${url.search}`;
|
||||
} else {
|
||||
// Likely a user profile, redirect to '/u/...'
|
||||
return `${bibliogramInstance || getRandomInstance(bibliogramInstances)}/u${
|
||||
return `${bibliogramInstance || getRandomInstance(bibliogramRandomPool)}/u${
|
||||
url.pathname
|
||||
}${url.search}`;
|
||||
}
|
||||
|
@ -514,7 +556,10 @@ function redirectReddit(url, initiator, type) {
|
|||
return null;
|
||||
}
|
||||
// Do not redirect when already on the selected view
|
||||
if (initiator && initiator.origin === oldRedditView || url.origin === oldRedditView) {
|
||||
if (
|
||||
(initiator && initiator.origin === oldRedditView) ||
|
||||
url.origin === oldRedditView
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
// Do not redirect exclusions nor anything other than main_frame
|
||||
|
@ -550,10 +595,13 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
redirect = {
|
||||
redirectUrl: redirectGoogleMaps(url, initiator),
|
||||
};
|
||||
} else if (redditDomains.includes(url.host) || oldRedditViews.includes(url.origin)) {
|
||||
} else if (
|
||||
redditDomains.includes(url.host) ||
|
||||
oldRedditViews.includes(url.origin)
|
||||
) {
|
||||
redirect = {
|
||||
redirectUrl: redirectReddit(url, initiator, details.type),
|
||||
}
|
||||
};
|
||||
}
|
||||
if (redirect && redirect.redirectUrl) {
|
||||
console.info(
|
||||
|
|
|
@ -204,6 +204,20 @@
|
|||
</div>
|
||||
|
||||
<div id="advanced" class="tabcontent">
|
||||
<div class="subheading">
|
||||
<h1>Invidious</h1>
|
||||
<hr>
|
||||
</div>
|
||||
<section class="settings-block">
|
||||
<h1 data-localise="__MSG_invidiousRandomPool__">
|
||||
Invidious random instance pool (comma-separated)
|
||||
</h1>
|
||||
<input
|
||||
id="invidious-random-pool"
|
||||
name="invidious-random-pool"
|
||||
type="text"
|
||||
/>
|
||||
</section>
|
||||
<section class="settings-block">
|
||||
<table
|
||||
class="option"
|
||||
|
@ -219,11 +233,11 @@
|
|||
<td>
|
||||
<input
|
||||
aria-hidden="true"
|
||||
id="useFreeTube"
|
||||
id="use-freetube"
|
||||
type="checkbox"
|
||||
checked
|
||||
/>
|
||||
<label for="useFreeTube" class="checkbox-label"> </label>
|
||||
<label for="use-freetube" class="checkbox-label"> </label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -392,6 +406,20 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<div class="subheading">
|
||||
<h1>Nitter</h1>
|
||||
<hr>
|
||||
</div>
|
||||
<section class="settings-block">
|
||||
<h1 data-localise="__MSG_nitterRandomPool__">
|
||||
Nitter random instance pool (comma-separated)
|
||||
</h1>
|
||||
<input
|
||||
id="nitter-random-pool"
|
||||
name="nitter-random-pool"
|
||||
type="text"
|
||||
/>
|
||||
</section>
|
||||
<section class="settings-block">
|
||||
<table
|
||||
class="option"
|
||||
|
@ -417,6 +445,20 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<div class="subheading">
|
||||
<h1>Bibliogram</h1>
|
||||
<hr>
|
||||
</div>
|
||||
<section class="settings-block">
|
||||
<h1 data-localise="__MSG_bibliogramRandomPool__">
|
||||
Bibliogram random instance pool (comma-separated)
|
||||
</h1>
|
||||
<input
|
||||
id="bibliogram-random-pool"
|
||||
name="bibliogram-random-pool"
|
||||
type="text"
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div id="exceptions" class="tabcontent">
|
||||
|
|
|
@ -10,45 +10,48 @@ const nitterInstances = [
|
|||
"https://nitter.mastodont.cat",
|
||||
"https://nitter.dark.fail",
|
||||
"https://nitter.tedomum.net",
|
||||
"https://t.maisputain.ovh",
|
||||
"https://nitter.cattube.org",
|
||||
"https://nitter.fdn.fr",
|
||||
"https://nitter.1d4.us",
|
||||
"https://nitter.kavin.rocks",
|
||||
"https://tweet.lambda.dance",
|
||||
"https://nitter.cc",
|
||||
"https://nitter.weaponizedhumiliation.com",
|
||||
"https://nitter.vxempire.xyz",
|
||||
"http://3nzoldnxplag42gqjs23xvghtzf6t6yzssrtytnntc6ppc7xxuoneoad.onion",
|
||||
"http://nitter.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd.onion",
|
||||
"http://nitterlgj3n5fgwesu3vxc5h67ruku33nqaoeoocae2mvlzhsu6k7fqd.onion",
|
||||
"http://npf37k3mtzwxreiw52ccs5ay4e6qt2fkcs2ndieurdyn2cuzzsfyfvid.onion",
|
||||
];
|
||||
const invidiousInstances = [
|
||||
"https://invidious.snopyta.org",
|
||||
"https://yewtu.be",
|
||||
"https://invidious.ggc-project.de",
|
||||
"https://invidious.13ad.de",
|
||||
"https://invidious.xyz",
|
||||
"https://invidious.toot.koeln",
|
||||
"https://invidious.site",
|
||||
"https://invidious.kavin.rocks",
|
||||
"https://tube.connect.cafe",
|
||||
"https://invidious.zapashcanon.fr",
|
||||
"https://invidiou.site",
|
||||
"https://invidious.fdn.fr",
|
||||
"https://watch.nettohikari.com",
|
||||
"https://yt.iswleuven.be",
|
||||
"https://yt.maisputain.ovh",
|
||||
"http://kgg2m7yk5aybusll.onion",
|
||||
"http://axqzx4s6s54s32yentfqojs3x5i7faxza6xo3ehd4bzzsg2ii4fv2iid.onion",
|
||||
"https://vid.mint.lgbt",
|
||||
"https://invidious.site",
|
||||
"http://fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad.onion",
|
||||
"http://qklhadlycap4cnod.onion",
|
||||
"http://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion",
|
||||
"http://mfqczy4mysscub2s.onion",
|
||||
"http://4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd.onion",
|
||||
"http://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion",
|
||||
];
|
||||
const bibliogramInstances = [
|
||||
"https://bibliogram.art",
|
||||
"https://bibliogram.snopyta.org",
|
||||
"https://bibliogram.pussthecat.org",
|
||||
"https://bibliogram.nixnet.services",
|
||||
"https://bg.endl.site",
|
||||
"https://bibliogram.13ad.de",
|
||||
"https://bibliogram.pixelfed.uno",
|
||||
"https://bibliogram.ethibox.fr",
|
||||
"https://bibliogram.hamster.dance",
|
||||
"https://insta.maisputain.ovh",
|
||||
"https://bibliogram.kavin.rocks",
|
||||
"https://bibliogram.ggc-project.de",
|
||||
];
|
||||
const osmInstances = ["https://openstreetmap.org"];
|
||||
const oldRedditViews = [
|
||||
"https://old.reddit.com", // desktop
|
||||
"https://i.reddit.com" // mobile
|
||||
];
|
||||
const oldRedditViews = ["https://old.reddit.com", "https://i.reddit.com"];
|
||||
const autocompletes = [
|
||||
{ id: "nitter-instance", instances: nitterInstances },
|
||||
{ id: "invidious-instance", instances: invidiousInstances },
|
||||
|
@ -78,7 +81,10 @@ let invidiousPlayerStyle = document.getElementById("invidious-player-style");
|
|||
let invidiousSubtitles = document.getElementById("invidious-subtitles");
|
||||
let invidiousAutoplay = document.getElementById("invidious-autoplay");
|
||||
let theme = document.getElementById("theme");
|
||||
let useFreeTube = document.getElementById("useFreeTube");
|
||||
let useFreeTube = document.getElementById("use-freetube");
|
||||
let nitterRandomPool = document.getElementById("nitter-random-pool");
|
||||
let invidiousRandomPool = document.getElementById("invidious-random-pool");
|
||||
let bibliogramRandomPool = document.getElementById("bibliogram-random-pool");
|
||||
let exceptions;
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
@ -105,6 +111,10 @@ function prependExceptionsItem(item, index) {
|
|||
});
|
||||
}
|
||||
|
||||
function filterInstances(instances) {
|
||||
return instances.filter((instance) => !instance.includes(".onion")).join();
|
||||
}
|
||||
|
||||
browser.storage.sync.get(
|
||||
[
|
||||
"nitterInstance",
|
||||
|
@ -130,6 +140,9 @@ browser.storage.sync.get(
|
|||
"exceptions",
|
||||
"theme",
|
||||
"useFreeTube",
|
||||
"nitterRandomPool",
|
||||
"invidiousRandomPool",
|
||||
"bibliogramRandomPool",
|
||||
],
|
||||
(result) => {
|
||||
theme.value = result.theme || "";
|
||||
|
@ -160,6 +173,12 @@ browser.storage.sync.get(
|
|||
invidiousSubtitles.value = result.invidiousSubtitles || "";
|
||||
invidiousAutoplay.checked = result.invidiousAutoplay;
|
||||
useFreeTube.checked = result.useFreeTube;
|
||||
nitterRandomPool.value =
|
||||
result.nitterRandomPool || filterInstances(nitterInstances);
|
||||
invidiousRandomPool.value =
|
||||
result.invidiousRandomPool || filterInstances(invidiousInstances);
|
||||
bibliogramRandomPool.value =
|
||||
result.bibliogramRandomPool || filterInstances(bibliogramInstances);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -364,11 +383,7 @@ invidiousPlayerStyle.addEventListener("change", (event) => {
|
|||
});
|
||||
|
||||
let invidiousSubtitlesChange = debounce(() => {
|
||||
if (invidiousInstance.checkValidity()) {
|
||||
browser.storage.sync.set({
|
||||
invidiousSubtitles: invidiousSubtitles.value,
|
||||
});
|
||||
}
|
||||
browser.storage.sync.set({ invidiousSubtitles: invidiousSubtitles.value });
|
||||
}, 500);
|
||||
invidiousSubtitles.addEventListener("input", invidiousSubtitlesChange);
|
||||
|
||||
|
@ -376,6 +391,23 @@ invidiousAutoplay.addEventListener("change", (event) => {
|
|||
browser.storage.sync.set({ invidiousAutoplay: event.target.checked });
|
||||
});
|
||||
|
||||
let nitterRandomPoolChange = debounce(() => {
|
||||
browser.storage.sync.set({ nitterRandomPool: nitterRandomPool.value });
|
||||
}, 500);
|
||||
nitterRandomPool.addEventListener("input", nitterRandomPoolChange);
|
||||
|
||||
let invidiousRandomPoolChange = debounce(() => {
|
||||
browser.storage.sync.set({ invidiousRandomPool: invidiousRandomPool.value });
|
||||
}, 500);
|
||||
invidiousRandomPool.addEventListener("input", invidiousRandomPoolChange);
|
||||
|
||||
let bibliogramRandomPoolChange = debounce(() => {
|
||||
browser.storage.sync.set({
|
||||
bibliogramRandomPool: bibliogramRandomPool.value,
|
||||
});
|
||||
}, 500);
|
||||
bibliogramRandomPool.addEventListener("input", bibliogramRandomPoolChange);
|
||||
|
||||
theme.addEventListener("change", (event) => {
|
||||
const value = event.target.options[theme.selectedIndex].value;
|
||||
switch (value) {
|
||||
|
|
|
@ -237,7 +237,7 @@ input:invalid {
|
|||
background-color: var(--bg-secondary);
|
||||
position: fixed;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
width: 400px;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
|
@ -465,3 +465,17 @@ input[type="range"]::-moz-range-thumb {
|
|||
#volume-value {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.subheading {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.subheading h1 {
|
||||
color: var(--active);
|
||||
}
|
||||
|
||||
.subheading hr {
|
||||
height: 1px;
|
||||
background-color: var(--active);
|
||||
border: none;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue