Randomise Invidious instance if empty or https://invidio.us

This commit is contained in:
SimonBrazell 2020-08-27 15:22:46 +10:00
parent fcb450022a
commit 564e25db3d
4 changed files with 246 additions and 185 deletions

View File

@ -1,26 +1,36 @@
'use strict'; "use strict";
const invidiousDefault = 'https://invidio.us'; const invidiousDefault = "https://invidious.snopyta.org";
const youtubeDomains = [ const youtubeDomains = [
'm.youtube.com', "m.youtube.com",
'youtube.com', "youtube.com",
'img.youtube.com', "img.youtube.com",
'www.youtube.com', "www.youtube.com",
'youtube-nocookie.com', "youtube-nocookie.com",
'www.youtube-nocookie.com', "www.youtube-nocookie.com",
'youtu.be', "youtu.be",
's.ytimg.com', "s.ytimg.com",
'music.youtube.com' "music.youtube.com",
]; ];
const nitterDefault = 'https://nitter.net'; const invidiousInstances = [
"https://invidious.snopyta.org",
"https://yewtu.be",
"https://invidious.13ad.de",
"https://invidious.xyz",
"https://invidious.site",
"https://invidiou.site",
"https://invidious.fdn.fr",
"https://invidious.toot.koeln",
];
const nitterDefault = "https://nitter.net";
const twitterDomains = [ const twitterDomains = [
'twitter.com', "twitter.com",
'www.twitter.com', "www.twitter.com",
'mobile.twitter.com', "mobile.twitter.com",
'pbs.twimg.com', "pbs.twimg.com",
'video.twimg.com', "video.twimg.com",
]; ];
const bibliogramDefault = 'https://bibliogram.art'; const bibliogramDefault = "https://bibliogram.art";
const instagramDomains = [ const instagramDomains = [
"instagram.com", "instagram.com",
"www.instagram.com", "www.instagram.com",
@ -28,50 +38,50 @@ const instagramDomains = [
"about.instagram.com", "about.instagram.com",
]; ];
const instagramReservedPaths = [ const instagramReservedPaths = [
'about', "about",
'explore', "explore",
'support', "support",
'press', "press",
'api', "api",
'privacy', "privacy",
'safety', "safety",
'admin', "admin",
'graphql', "graphql",
'accounts', "accounts",
'help', "help",
'terms', "terms",
'contact', "contact",
'blog', "blog",
'igtv', "igtv",
'u', "u",
'p', "p",
'fragment', "fragment",
'imageproxy', "imageproxy",
'videoproxy', "videoproxy",
'.well-known' ".well-known",
]; ];
const bibliogramBypassPaths = /\/(accounts\/|embeds?.js)/; const bibliogramBypassPaths = /\/(accounts\/|embeds?.js)/;
const bibliogramInstances = [ const bibliogramInstances = [
'https://bibliogram.art', "https://bibliogram.art",
'https://bibliogram.snopyta.org' "https://bibliogram.snopyta.org",
]; ];
const osmDefault = 'https://openstreetmap.org'; const osmDefault = "https://openstreetmap.org";
const googleMapsRegex = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/; const googleMapsRegex = /https?:\/\/(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/;
const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/;
const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g; const dataLatLngRegex = /(!3d|!4d)(-?[0-9]{1,10}.[0-9]{1,10})/g;
const placeRegex = /\/place\/(.*)\//; const placeRegex = /\/place\/(.*)\//;
const travelModes = { const travelModes = {
'driving': 'fossgis_osrm_car', driving: "fossgis_osrm_car",
'walking': 'fossgis_osrm_foot', walking: "fossgis_osrm_foot",
'bicycling': 'fossgis_osrm_bike', bicycling: "fossgis_osrm_bike",
'transit': 'fossgis_osrm_car' // not implemented on OSM, default to car. transit: "fossgis_osrm_car", // not implemented on OSM, default to car.
}; };
const layers = { const layers = {
'none': 'S', none: "S",
'transit': 'T', transit: "T",
'traffic': 'S', // not implemented on OSM, default to standard. traffic: "S", // not implemented on OSM, default to standard.
'bicycling': 'C' bicycling: "C",
} };
let disableNitter; let disableNitter;
let disableInvidious; let disableInvidious;
@ -95,25 +105,25 @@ window.browser = window.browser || window.chrome;
browser.storage.sync.get( browser.storage.sync.get(
[ [
'nitterInstance', "nitterInstance",
'invidiousInstance', "invidiousInstance",
'bibliogramInstance', "bibliogramInstance",
'osmInstance', "osmInstance",
'disableNitter', "disableNitter",
'disableInvidious', "disableInvidious",
'disableBibliogram', "disableBibliogram",
'disableOsm', "disableOsm",
'alwaysProxy', "alwaysProxy",
'onlyEmbeddedVideo', "onlyEmbeddedVideo",
'videoQuality', "videoQuality",
'invidiousDarkMode', "invidiousDarkMode",
'invidiousVolume', "invidiousVolume",
'invidiousPlayerStyle', "invidiousPlayerStyle",
'invidiousSubtitles', "invidiousSubtitles",
'invidiousAutoplay', "invidiousAutoplay",
'exceptions' "exceptions",
], ],
result => { (result) => {
disableNitter = result.disableNitter; disableNitter = result.disableNitter;
disableInvidious = result.disableInvidious; disableInvidious = result.disableInvidious;
disableBibliogram = result.disableBibliogram; disableBibliogram = result.disableBibliogram;
@ -126,67 +136,70 @@ browser.storage.sync.get(
onlyEmbeddedVideo = result.onlyEmbeddedVideo; onlyEmbeddedVideo = result.onlyEmbeddedVideo;
videoQuality = result.videoQuality; videoQuality = result.videoQuality;
invidiousDarkMode = result.invidiousDarkMode; invidiousDarkMode = result.invidiousDarkMode;
exceptions = result.exceptions ? result.exceptions.map(e => { exceptions = result.exceptions
return new RegExp(e); ? result.exceptions.map((e) => {
}) : []; return new RegExp(e);
})
: [];
invidiousVolume = result.invidiousVolume; invidiousVolume = result.invidiousVolume;
invidiousPlayerStyle = result.invidiousPlayerStyle; invidiousPlayerStyle = result.invidiousPlayerStyle;
invidiousSubtitles = result.invidiousSubtitles || ''; invidiousSubtitles = result.invidiousSubtitles || "";
invidiousAutoplay = !result.invidiousAutoplay; invidiousAutoplay = !result.invidiousAutoplay;
} }
); );
browser.storage.onChanged.addListener(changes => { browser.storage.onChanged.addListener((changes) => {
if ('nitterInstance' in changes) { if ("nitterInstance" in changes) {
nitterInstance = changes.nitterInstance.newValue || nitterDefault; nitterInstance = changes.nitterInstance.newValue || nitterDefault;
} }
if ('invidiousInstance' in changes) { if ("invidiousInstance" in changes) {
invidiousInstance = changes.invidiousInstance.newValue || invidiousDefault; invidiousInstance = changes.invidiousInstance.newValue || invidiousDefault;
} }
if ('bibliogramInstance' in changes) { if ("bibliogramInstance" in changes) {
bibliogramInstance = changes.bibliogramInstance.newValue || bibliogramDefault; bibliogramInstance =
changes.bibliogramInstance.newValue || bibliogramDefault;
} }
if ('osmInstance' in changes) { if ("osmInstance" in changes) {
osmInstance = changes.osmInstance.newValue || osmDefault; osmInstance = changes.osmInstance.newValue || osmDefault;
} }
if ('disableNitter' in changes) { if ("disableNitter" in changes) {
disableNitter = changes.disableNitter.newValue; disableNitter = changes.disableNitter.newValue;
} }
if ('disableInvidious' in changes) { if ("disableInvidious" in changes) {
disableInvidious = changes.disableInvidious.newValue; disableInvidious = changes.disableInvidious.newValue;
} }
if ('disableBibliogram' in changes) { if ("disableBibliogram" in changes) {
disableBibliogram = changes.disableBibliogram.newValue; disableBibliogram = changes.disableBibliogram.newValue;
} }
if ('disableOsm' in changes) { if ("disableOsm" in changes) {
disableOsm = changes.disableOsm.newValue; disableOsm = changes.disableOsm.newValue;
} }
if ('alwaysProxy' in changes) { if ("alwaysProxy" in changes) {
alwaysProxy = changes.alwaysProxy.newValue; alwaysProxy = changes.alwaysProxy.newValue;
} }
if ('onlyEmbeddedVideo' in changes) { if ("onlyEmbeddedVideo" in changes) {
onlyEmbeddedVideo = changes.onlyEmbeddedVideo.newValue; onlyEmbeddedVideo = changes.onlyEmbeddedVideo.newValue;
} }
if ('videoQuality' in changes) { if ("videoQuality" in changes) {
videoQuality = changes.videoQuality.newValue; videoQuality = changes.videoQuality.newValue;
} }
if ('invidiousDarkMode' in changes) { if ("invidiousDarkMode" in changes) {
invidiousDarkMode = changes.invidiousDarkMode.newValue; invidiousDarkMode = changes.invidiousDarkMode.newValue;
} }
if ('invidiousVolume' in changes) { if ("invidiousVolume" in changes) {
invidiousVolume = changes.invidiousVolume.newValue; invidiousVolume = changes.invidiousVolume.newValue;
} }
if ('invidiousPlayerStyle' in changes) { if ("invidiousPlayerStyle" in changes) {
invidiousPlayerStyle = changes.invidiousPlayerStyle.newValue; invidiousPlayerStyle = changes.invidiousPlayerStyle.newValue;
} }
if ('invidiousSubtitles' in changes) { if ("invidiousSubtitles" in changes) {
invidiousSubtitles = changes.invidiousSubtitles.newValue; invidiousSubtitles = changes.invidiousSubtitles.newValue;
} }
if ('invidiousAutoplay' in changes) { if ("invidiousAutoplay" in changes) {
invidiousAutoplay = changes.invidiousAutoplay.newValue; invidiousAutoplay = changes.invidiousAutoplay.newValue;
} }
if ('exceptions' in changes) { if ("exceptions" in changes) {
exceptions = changes.exceptions.newValue.map(e => { exceptions = changes.exceptions.newValue.map((e) => {
return new RegExp(e); return new RegExp(e);
}); });
} }
@ -204,14 +217,13 @@ function addressToLatLng(address, callback) {
`${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}` `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`
); );
} }
} } else {
else {
console.info("Error: Status is " + xmlhttp.status); console.info("Error: Status is " + xmlhttp.status);
} }
} }
}; };
xmlhttp.open( xmlhttp.open(
'GET', "GET",
`https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`,
false false
); );
@ -219,52 +231,58 @@ function addressToLatLng(address, callback) {
} }
function isException(url, initiator) { function isException(url, initiator) {
return exceptions.some(regex => (regex.test(url.href))) || return (
(initiator && exceptions.some(regex => (regex.test(initiator.href)))); exceptions.some((regex) => regex.test(url.href)) ||
(initiator && exceptions.some((regex) => regex.test(initiator.href)))
);
} }
function isFirefox() { function isFirefox() {
return typeof InstallTrigger !== 'undefined'; return typeof InstallTrigger !== "undefined";
} }
function redirectYouTube(url, initiator, type) { function redirectYouTube(url, initiator, type) {
if (disableInvidious || isException(url, initiator)) { if (disableInvidious || isException(url, initiator)) {
return null; return null;
} }
if (initiator && (initiator.origin === invidiousInstance || youtubeDomains.includes(initiator.host))) { if (
initiator &&
(initiator.origin === invidiousInstance ||
youtubeDomains.includes(initiator.host))
) {
return null; return null;
} }
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) { if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) {
// Don't redirect YouTube Player API. // Don't redirect YouTube Player API.
return null; return null;
} }
if (url.host.split('.')[0] === 'studio') { if (url.host.split(".")[0] === "studio") {
// Avoid redirecting `studio.youtube.com` // Avoid redirecting `studio.youtube.com`
return null; return null;
} }
if (onlyEmbeddedVideo && type !== 'sub_frame') { if (onlyEmbeddedVideo && type !== "sub_frame") {
return null; return null;
} }
// Apply settings // Apply settings
if (alwaysProxy) { if (alwaysProxy) {
url.searchParams.append('local', true); url.searchParams.append("local", true);
} }
if (videoQuality) { if (videoQuality) {
url.searchParams.append('quality', videoQuality); url.searchParams.append("quality", videoQuality);
} }
if (invidiousDarkMode) { if (invidiousDarkMode) {
url.searchParams.append('dark_mode', invidiousDarkMode); url.searchParams.append("dark_mode", invidiousDarkMode);
} }
if (invidiousVolume) { if (invidiousVolume) {
url.searchParams.append('volume', invidiousVolume); url.searchParams.append("volume", invidiousVolume);
} }
if (invidiousPlayerStyle) { if (invidiousPlayerStyle) {
url.searchParams.append('player_style', invidiousPlayerStyle); url.searchParams.append("player_style", invidiousPlayerStyle);
} }
if (invidiousSubtitles) { if (invidiousSubtitles) {
url.searchParams.append('subtitles', invidiousSubtitles); url.searchParams.append("subtitles", invidiousSubtitles);
} }
url.searchParams.append('autoplay', invidiousAutoplay ? 1 : 0); url.searchParams.append("autoplay", invidiousAutoplay ? 1 : 0);
return `${invidiousInstance}${url.pathname}${url.search}`; return `${invidiousInstance}${url.pathname}${url.search}`;
} }
@ -273,21 +291,28 @@ function redirectTwitter(url, initiator) {
if (disableNitter || isException(url, initiator)) { if (disableNitter || isException(url, initiator)) {
return null; return null;
} }
if (url.pathname.includes('/home')) { if (url.pathname.includes("/home")) {
return null; return null;
} }
if (isFirefox() && initiator && (initiator.origin === nitterInstance || twitterDomains.includes(initiator.host))) { if (
isFirefox() &&
initiator &&
(initiator.origin === nitterInstance ||
twitterDomains.includes(initiator.host))
) {
browser.storage.sync.set({ browser.storage.sync.set({
redirectBypassFlag: true redirectBypassFlag: true,
}); });
return null; return null;
} }
if (url.host.split('.')[0] === 'pbs') { if (url.host.split(".")[0] === "pbs") {
return `${nitterInstance}/pic/${encodeURIComponent(url.href)}`; return `${nitterInstance}/pic/${encodeURIComponent(url.href)}`;
} else if (url.host.split('.')[0] === 'video') { } else if (url.host.split(".")[0] === "video") {
return `${nitterInstance}/gif/${encodeURIComponent(url.href)}`; return `${nitterInstance}/gif/${encodeURIComponent(url.href)}`;
} else if (url.pathname.includes('tweets')) { } else if (url.pathname.includes("tweets")) {
return `${nitterInstance}${url.pathname.replace('/tweets', '')}${url.search}`; return `${nitterInstance}${url.pathname.replace("/tweets", "")}${
url.search
}`;
} else { } else {
return `${nitterInstance}${url.pathname}${url.search}`; return `${nitterInstance}${url.pathname}${url.search}`;
} }
@ -298,14 +323,21 @@ function redirectInstagram(url, initiator, type) {
return null; return null;
} }
// Do not redirect Bibliogram view on Instagram links // Do not redirect Bibliogram view on Instagram links
if (initiator && (initiator.origin === bibliogramInstance || instagramDomains.includes(initiator.host))) { if (
initiator &&
(initiator.origin === bibliogramInstance ||
instagramDomains.includes(initiator.host))
) {
return null; return null;
} }
// Do not redirect /accounts, /embeds.js, or anything other than main_frame // Do not redirect /accounts, /embeds.js, or anything other than main_frame
if (type !== 'main_frame' || url.pathname.match(bibliogramBypassPaths)) { if (type !== "main_frame" || url.pathname.match(bibliogramBypassPaths)) {
return null; return null;
} }
if (url.pathname === '/' || instagramReservedPaths.includes(url.pathname.split('/')[1])) { if (
url.pathname === "/" ||
instagramReservedPaths.includes(url.pathname.split("/")[1])
) {
return `${bibliogramInstance}${url.pathname}${url.search}`; return `${bibliogramInstance}${url.pathname}${url.search}`;
} else { } else {
// Likely a user profile, redirect to '/u/...' // Likely a user profile, redirect to '/u/...'
@ -318,31 +350,33 @@ function redirectGoogleMaps(url, initiator) {
return null; return null;
} }
let redirect; let redirect;
let mapCentre = ''; let mapCentre = "";
let params = ''; let params = "";
// Set map centre if present // Set map centre if present
if (url.pathname.match(mapCentreRegex)) { if (url.pathname.match(mapCentreRegex)) {
const [, lat, lon, zoom] = url.pathname.match(mapCentreRegex); const [, lat, lon, zoom] = url.pathname.match(mapCentreRegex);
mapCentre = `#map=${zoom}/${lat}/${lon}`; mapCentre = `#map=${zoom}/${lat}/${lon}`;
} else if (url.search.includes('center=')) { } else if (url.search.includes("center=")) {
const [lat, lon] = url.searchParams.get('center').split(','); const [lat, lon] = url.searchParams.get("center").split(",");
mapCentre = `#map=${url.searchParams.get('zoom') || '17'}/${lat}/${lon}`; mapCentre = `#map=${url.searchParams.get("zoom") || "17"}/${lat}/${lon}`;
// Set default zoom if mapCentre not present // Set default zoom if mapCentre not present
} else { } else {
params = '&zoom=17'; params = "&zoom=17";
} }
// Set map layer // Set map layer
params = `${params}&layers=${layers[url.searchParams.get('layer')] || layers['none']}`; params = `${params}&layers=${
layers[url.searchParams.get("layer")] || layers["none"]
}`;
// Handle Google Maps Embed API // Handle Google Maps Embed API
if (url.pathname.includes('/embed')) { if (url.pathname.includes("/embed")) {
let query = ''; let query = "";
if (url.searchParams.has('q')) { if (url.searchParams.has("q")) {
query = url.searchParams.get('q'); query = url.searchParams.get("q");
} else if (url.searchParams.has('query')) { } else if (url.searchParams.has("query")) {
query = url.searchParams.has('query'); query = url.searchParams.has("query");
} else if (url.searchParams.has('pb')) { } else if (url.searchParams.has("pb")) {
try { try {
query = url.searchParams.get('pb').split(/!2s(.*?)!/)[1]; query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1];
} catch (error) { } catch (error) {
console.error(error); console.error(error);
// Unable to find map marker in URL. // Unable to find map marker in URL.
@ -355,47 +389,56 @@ function redirectGoogleMaps(url, initiator) {
}); });
redirect = `${osmInstance}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`; redirect = `${osmInstance}/export/embed.html?bbox=${bbox}&layer=mapnik&marker=${marker}`;
// Handle Google Maps Directions // Handle Google Maps Directions
} else if (url.pathname.includes('/dir')) { } else if (url.pathname.includes("/dir")) {
const travelMode = travelModes[url.searchParams.get('travelmode')] || travelModes['driving']; const travelMode =
travelModes[url.searchParams.get("travelmode")] || travelModes["driving"];
let origin; let origin;
addressToLatLng(url.searchParams.get('origin'), coords => { addressToLatLng(url.searchParams.get("origin"), (coords) => {
origin = coords; origin = coords;
}); });
let destination; let destination;
addressToLatLng(url.searchParams.get('destination'), coords => { addressToLatLng(url.searchParams.get("destination"), (coords) => {
destination = coords; destination = coords;
}); });
redirect = `${osmInstance}/directions?engine=${travelMode}&route=${origin}%3B${destination}${mapCentre}${params}`; redirect = `${osmInstance}/directions?engine=${travelMode}&route=${origin}%3B${destination}${mapCentre}${params}`;
// Get marker from data attribute // Get marker from data attribute
} else if (url.pathname.includes('data=') && url.pathname.match(dataLatLngRegex)) { } else if (
url.pathname.includes("data=") &&
url.pathname.match(dataLatLngRegex)
) {
const [mlat, mlon] = url.pathname.match(dataLatLngRegex); const [mlat, mlon] = url.pathname.match(dataLatLngRegex);
redirect = `${osmInstance}/?mlat=${mlat.replace('!3d', '')}&mlon=${mlon.replace('!4d', '')}${mapCentre}${params}`; redirect = `${osmInstance}/?mlat=${mlat.replace(
"!3d",
""
)}&mlon=${mlon.replace("!4d", "")}${mapCentre}${params}`;
// Get marker from ll param // Get marker from ll param
} else if (url.searchParams.has('ll')) { } else if (url.searchParams.has("ll")) {
const [mlat, mlon] = url.searchParams.get('ll').split(','); const [mlat, mlon] = url.searchParams.get("ll").split(",");
redirect = `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`; redirect = `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`;
// Get marker from viewpoint param. // Get marker from viewpoint param.
} else if (url.searchParams.has('viewpoint')) { } else if (url.searchParams.has("viewpoint")) {
const [mlat, mlon] = url.searchParams.get('viewpoint').split(','); const [mlat, mlon] = url.searchParams.get("viewpoint").split(",");
redirect = `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`; redirect = `${osmInstance}/?mlat=${mlat}&mlon=${mlon}${mapCentre}${params}`;
// Use query as search if present. // Use query as search if present.
} else { } else {
let query; let query;
if (url.searchParams.has('q')) { if (url.searchParams.has("q")) {
query = url.searchParams.get('q'); query = url.searchParams.get("q");
} else if (url.searchParams.has('query')) { } else if (url.searchParams.has("query")) {
query = url.searchParams.get('query'); query = url.searchParams.get("query");
} else if (url.pathname.match(placeRegex)) { } else if (url.pathname.match(placeRegex)) {
query = url.pathname.match(placeRegex)[1]; query = url.pathname.match(placeRegex)[1];
} }
redirect = `${osmInstance}/${query ? 'search?query=' + query : ''}${mapCentre || '#'}${params}`; redirect = `${osmInstance}/${query ? "search?query=" + query : ""}${
mapCentre || "#"
}${params}`;
} }
return redirect; return redirect;
} }
browser.webRequest.onBeforeRequest.addListener( browser.webRequest.onBeforeRequest.addListener(
details => { (details) => {
const url = new URL(details.url); const url = new URL(details.url);
let initiator; let initiator;
if (details.originUrl) { if (details.originUrl) {
@ -406,55 +449,69 @@ browser.webRequest.onBeforeRequest.addListener(
let redirect; let redirect;
if (youtubeDomains.includes(url.host)) { if (youtubeDomains.includes(url.host)) {
redirect = { redirect = {
redirectUrl: redirectYouTube(url, initiator, details.type) redirectUrl: redirectYouTube(url, initiator, details.type),
}; };
} else if (twitterDomains.includes(url.host)) { } else if (twitterDomains.includes(url.host)) {
redirect = { redirect = {
redirectUrl: redirectTwitter(url, initiator) redirectUrl: redirectTwitter(url, initiator),
}; };
} else if (instagramDomains.includes(url.host)) { } else if (instagramDomains.includes(url.host)) {
redirect = { redirect = {
redirectUrl: redirectInstagram(url, initiator, details.type) redirectUrl: redirectInstagram(url, initiator, details.type),
}; };
} else if (url.href.match(googleMapsRegex)) { } else if (url.href.match(googleMapsRegex)) {
redirect = { redirect = {
redirectUrl: redirectGoogleMaps(url, initiator) redirectUrl: redirectGoogleMaps(url, initiator),
}; };
} }
if (redirect && redirect.redirectUrl) { if (redirect && redirect.redirectUrl) {
console.info( console.info(
'Redirecting', `"${url.href}"`, '=>', `"${redirect.redirectUrl}"` "Redirecting",
`"${url.href}"`,
"=>",
`"${redirect.redirectUrl}"`
); );
console.info('Details', details); console.info("Details", details);
} }
return redirect; return redirect;
}, },
{ {
urls: ["<all_urls>"] urls: ["<all_urls>"],
}, },
['blocking'] ["blocking"]
); );
browser.runtime.onInstalled.addListener( browser.runtime.onInstalled.addListener((details) => {
details => { if (details.reason === "install") {
if (details.reason === 'install') { browser.storage.sync.set({
browser.storage.sync.set({ bibliogramInstance:
bibliogramInstance: bibliogramInstances[~~(bibliogramInstances.length * Math.random())] bibliogramInstances[~~(bibliogramInstances.length * Math.random())],
}); invidiousInstance:
} else if (details.reason === 'update') { invidiousInstances[~~(invidiousInstances.length * Math.random())],
browser.storage.sync.get(['whitelist', 'exceptions'], });
result => { } else if (details.reason === "update") {
if (result.whitelist) { browser.storage.sync.get(
let whitelist = result.whitelist.map( ["whitelist", "exceptions", "invidiousInstance"],
e => e.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') (result) => {
); if (result.whitelist) {
browser.storage.sync.set({ let whitelist = result.whitelist.map((e) =>
exceptions: result.exceptions.concat(whitelist), e.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")
whitelist: null );
}); browser.storage.sync.set({
} exceptions: result.exceptions.concat(whitelist),
whitelist: null,
});
} }
); if (
} result.invidiousInstance === "https://invidio.us" ||
result.invidiousInstance === null
) {
browser.storage.sync.set({
invidiousInstance:
invidiousInstances[~~(invidiousInstances.length * Math.random())],
});
}
}
);
} }
); });

View File

@ -1,7 +1,7 @@
{ {
"name": "__MSG_extensionName__", "name": "__MSG_extensionName__",
"description": "__MSG_extensionDescription__", "description": "__MSG_extensionDescription__",
"version": "1.1.39", "version": "1.1.40",
"manifest_version": 2, "manifest_version": 2,
"background": { "background": {
"scripts": ["background.js"], "scripts": ["background.js"],
@ -39,9 +39,11 @@
}, },
{ {
"matches": [ "matches": [
"*://invidio.us/*",
"*://invidious.snopyta.org/*", "*://invidious.snopyta.org/*",
"*://yewtu.be/*", "*://yewtu.be/*",
"*://invidious.xyz/*",
"*://invidious.site/*",
"*://invidiou.site/*",
"*://invidious.ggc-project.de/*", "*://invidious.ggc-project.de/*",
"*://invidious.13ad.de/*", "*://invidious.13ad.de/*",
"*://invidious.toot.koeln/*", "*://invidious.toot.koeln/*",
@ -54,8 +56,8 @@
"*://fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad.onion/*", "*://fz253lmuao3strwbfbmx46yu7acac2jz27iwtorgmbqlkurlclmancad.onion/*",
"*://qklhadlycap4cnod.onion/*", "*://qklhadlycap4cnod.onion/*",
"*://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion/*", "*://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion/*",
"*://mfqczy4mysscub2s.onion/*" "*://mfqczy4mysscub2s.onion/*",
"*://4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd.onion/*", "*://4l2dgddgsrkf2ous66i6seeyi6etzfgrue332grh2n7madpwopotugyd.onion/*"
], ],
"js": ["assets/javascript/persist-invidious-prefs.js"], "js": ["assets/javascript/persist-invidious-prefs.js"],
"run_at": "document_start" "run_at": "document_start"

View File

@ -137,7 +137,7 @@
<input <input
id="invidious-instance" id="invidious-instance"
type="url" type="url"
placeholder="https://invidio.us" placeholder="https://invidious.snopyta.org"
/> />
</div> </div>
</section> </section>

View File

@ -15,12 +15,14 @@ const nitterInstances = [
"http://nitter.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd.onion", "http://nitter.l4qlywnpwqsluw65ts7md3khrivpirse744un3x7mlskqauz5pyuzgqd.onion",
]; ];
const invidiousInstances = [ const invidiousInstances = [
"https://invidio.us",
"https://invidious.snopyta.org", "https://invidious.snopyta.org",
"https://yewtu.be", "https://yewtu.be",
"https://invidious.ggc-project.de", "https://invidious.ggc-project.de",
"https://invidious.13ad.de", "https://invidious.13ad.de",
"https://invidious.xyz",
"https://invidious.toot.koeln", "https://invidious.toot.koeln",
"https://invidious.site",
"https://invidiou.site",
"https://invidious.fdn.fr", "https://invidious.fdn.fr",
"https://watch.nettohikari.com", "https://watch.nettohikari.com",
"https://yt.iswleuven.be", "https://yt.iswleuven.be",