Fix copy-and-replace mistakes
- Change scribe's default input to 'Random instance (none selected)' - Add random pool variables and functions for scribe
This commit is contained in:
parent
df07b8a7f4
commit
362bef8658
@ -72,6 +72,7 @@ let useFreeTube;
|
|||||||
let nitterRandomPool;
|
let nitterRandomPool;
|
||||||
let invidiousRandomPool;
|
let invidiousRandomPool;
|
||||||
let bibliogramRandomPool;
|
let bibliogramRandomPool;
|
||||||
|
let scribeRandomPool;
|
||||||
let exceptions;
|
let exceptions;
|
||||||
|
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
@ -108,6 +109,7 @@ browser.storage.sync.get(
|
|||||||
"nitterRandomPool",
|
"nitterRandomPool",
|
||||||
"invidiousRandomPool",
|
"invidiousRandomPool",
|
||||||
"bibliogramRandomPool",
|
"bibliogramRandomPool",
|
||||||
|
"scribeRandomPool",
|
||||||
"exceptions",
|
"exceptions",
|
||||||
],
|
],
|
||||||
(result) => {
|
(result) => {
|
||||||
@ -152,6 +154,9 @@ browser.storage.sync.get(
|
|||||||
bibliogramRandomPool = result.bibliogramRandomPool
|
bibliogramRandomPool = result.bibliogramRandomPool
|
||||||
? result.bibliogramRandomPool.split(",")
|
? result.bibliogramRandomPool.split(",")
|
||||||
: commonHelper.filterInstances(bibliogramInstances);
|
: commonHelper.filterInstances(bibliogramInstances);
|
||||||
|
scribeRandomPool = result.scribeRandomPool
|
||||||
|
? result.scribeRandomPool.split(",")
|
||||||
|
: commonHelper.filterInstances(bibliogramInstances);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -244,6 +249,9 @@ browser.storage.onChanged.addListener((changes) => {
|
|||||||
if ("bibliogramRandomPool" in changes) {
|
if ("bibliogramRandomPool" in changes) {
|
||||||
bibliogramRandomPool = changes.bibliogramRandomPool.newValue.split(",");
|
bibliogramRandomPool = changes.bibliogramRandomPool.newValue.split(",");
|
||||||
}
|
}
|
||||||
|
if ("scribeRandomPool" in changes) {
|
||||||
|
scribeRandomPool = changes.scribeRandomPool.newValue.split(",");
|
||||||
|
}
|
||||||
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);
|
||||||
@ -527,51 +535,38 @@ function redirectReddit(url, initiator, type) {
|
|||||||
return `${redditInstance}${url.pathname}${url.search}`;
|
return `${redditInstance}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirectScribe(url, initiator, type) {
|
function redirectMedium(url, initiator) {
|
||||||
if (disableScribe || isException(url, initiator)) {
|
if (disableScribe || isException(url, initiator)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Do not redirect when already on the selected view
|
if (url.pathname.split("/").includes("home")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
(initiator && initiator.origin === scribeInstance) ||
|
isFirefox() &&
|
||||||
url.origin === scribeInstance
|
initiator &&
|
||||||
|
(initiator.origin === scribeInstance ||
|
||||||
|
scribeInstances.includes(initiator.origin) ||
|
||||||
|
mediumDomains.includes(initiator.host))
|
||||||
) {
|
) {
|
||||||
|
browser.storage.sync.set({
|
||||||
|
redirectBypassFlag: true,
|
||||||
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Do not redirect exclusions nor anything other than main_frame
|
if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") {
|
||||||
if (type !== "main_frame") {
|
return `${
|
||||||
return null;
|
scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
|
||||||
|
}/pic/${encodeURIComponent(url.href)}`;
|
||||||
|
} else if (url.pathname.split("/").includes("tweets")) {
|
||||||
|
return `${
|
||||||
|
scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
|
||||||
|
}${url.pathname.replace("/tweets", "")}${url.search}`;
|
||||||
|
} else {
|
||||||
|
return `${
|
||||||
|
scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
|
||||||
|
}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
if (url.host === "i.redd.it") {
|
|
||||||
if (scribeInstance.includes("libredd")) {
|
|
||||||
return `${scribeInstance}/img${url.pathname}${url.search}`;
|
|
||||||
} else if (scribeInstance.includes("teddit")) {
|
|
||||||
// As of 2021-04-09, redirects for teddit images are nontrivial:
|
|
||||||
// - navigating to the image before ever navigating to its page causes
|
|
||||||
// 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 null;
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else if (url.host === "redd.it") {
|
|
||||||
if (
|
|
||||||
scribeInstance.includes("teddit") &&
|
|
||||||
!url.pathname.match(/^\/+[^\/]+\/+[^\/]/)
|
|
||||||
) {
|
|
||||||
// As of 2021-04-22, redirects for teddit redd.it/foo links don't work.
|
|
||||||
// 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 `${scribeInstance}/comments${url.pathname}${url.search}`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return `${scribeInstance}${url.pathname}${url.search}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirectSearchEngine(url, initiator) {
|
function redirectSearchEngine(url, initiator) {
|
||||||
@ -668,7 +663,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||||||
};
|
};
|
||||||
} else if (mediumDomains.includes(url.host)) {
|
} else if (mediumDomains.includes(url.host)) {
|
||||||
redirect = {
|
redirect = {
|
||||||
redirectUrl: redirectScribe(url, initiator, details.type),
|
redirectUrl: redirectMedium(url, initiator, details.type),
|
||||||
};
|
};
|
||||||
} else if (url.href.match(googleSearchRegex)) {
|
} else if (url.href.match(googleSearchRegex)) {
|
||||||
redirect = {
|
redirect = {
|
||||||
|
@ -284,7 +284,7 @@
|
|||||||
<input
|
<input
|
||||||
id="scribe-instance"
|
id="scribe-instance"
|
||||||
type="url"
|
type="url"
|
||||||
placeholder="https://libredd.it"
|
placeholder="Random instance (none selected)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
@ -73,6 +73,7 @@ let useFreeTube = document.getElementById("use-freetube");
|
|||||||
let nitterRandomPool = document.getElementById("nitter-random-pool");
|
let nitterRandomPool = document.getElementById("nitter-random-pool");
|
||||||
let invidiousRandomPool = document.getElementById("invidious-random-pool");
|
let invidiousRandomPool = document.getElementById("invidious-random-pool");
|
||||||
let bibliogramRandomPool = document.getElementById("bibliogram-random-pool");
|
let bibliogramRandomPool = document.getElementById("bibliogram-random-pool");
|
||||||
|
let scribeRandomPool = document.getElementById("scribe-random-pool");
|
||||||
let exceptions;
|
let exceptions;
|
||||||
|
|
||||||
window.browser = window.browser || window.chrome;
|
window.browser = window.browser || window.chrome;
|
||||||
@ -137,6 +138,7 @@ browser.storage.sync.get(
|
|||||||
"nitterRandomPool",
|
"nitterRandomPool",
|
||||||
"invidiousRandomPool",
|
"invidiousRandomPool",
|
||||||
"bibliogramRandomPool",
|
"bibliogramRandomPool",
|
||||||
|
"scribeRandomPool",
|
||||||
],
|
],
|
||||||
(result) => {
|
(result) => {
|
||||||
theme.value = result.theme || "";
|
theme.value = result.theme || "";
|
||||||
@ -184,6 +186,9 @@ browser.storage.sync.get(
|
|||||||
bibliogramRandomPool.value =
|
bibliogramRandomPool.value =
|
||||||
result.bibliogramRandomPool ||
|
result.bibliogramRandomPool ||
|
||||||
commonHelper.filterInstances(bibliogramInstances);
|
commonHelper.filterInstances(bibliogramInstances);
|
||||||
|
scribeRandomPool.value =
|
||||||
|
result.scribeRandomPool ||
|
||||||
|
commonHelper.filterInstances(scribeInstances);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -474,7 +479,13 @@ const bibliogramRandomPoolChange = debounce(() => {
|
|||||||
bibliogramRandomPool: bibliogramRandomPool.value,
|
bibliogramRandomPool: bibliogramRandomPool.value,
|
||||||
});
|
});
|
||||||
}, 500);
|
}, 500);
|
||||||
bibliogramRandomPool.addEventListener("input", bibliogramRandomPoolChange);
|
|
||||||
|
const scribeRandomPoolChange = debounce(() => {
|
||||||
|
browser.storage.sync.set({
|
||||||
|
scribeRandomPool: scribeRandomPool.value,
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
scribeRandomPool.addEventListener("input", scribeRandomPoolChange);
|
||||||
|
|
||||||
theme.addEventListener("change", (event) => {
|
theme.addEventListener("change", (event) => {
|
||||||
const value = event.target.options[theme.selectedIndex].value;
|
const value = event.target.options[theme.selectedIndex].value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user