Add redirect from Medium to Scribe
Multiple Medium domains would be redirected to two known Scribe instances: scribe.rip scribe.nixnet.services
This commit is contained in:
parent
4c1290acb2
commit
df07b8a7f4
|
@ -0,0 +1,26 @@
|
|||
const targets = [
|
||||
"medium.com",
|
||||
/.*.medium.com/,
|
||||
/* Other domains of medium blogs, source(s):
|
||||
* https://findingtom.com/best-medium-blogs-to-follow/#1-forge
|
||||
* */
|
||||
"towardsdatascience.com",
|
||||
"uxdesign.cc",
|
||||
"uxplanet.org",
|
||||
"betterprogramming.pub",
|
||||
"aninjusticemag.com",
|
||||
"betterhumans.pub",
|
||||
"psiloveyou.xyz",
|
||||
"entrepreneurshandbook.co",
|
||||
"blog.coinbase.com"
|
||||
];
|
||||
|
||||
const redirects = [
|
||||
"https://scribe.rip",
|
||||
"https://scribe.nixnet.services/"
|
||||
];
|
||||
|
||||
export default {
|
||||
targets,
|
||||
redirects,
|
||||
};
|
|
@ -5,6 +5,7 @@ import twitterHelper from "../../assets/javascripts/helpers/twitter.js";
|
|||
import youtubeHelper from "../../assets/javascripts/helpers/youtube.js";
|
||||
import instagramHelper from "../../assets/javascripts/helpers/instagram.js";
|
||||
import mapsHelper from "../../assets/javascripts/helpers/google-maps.js";
|
||||
import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
||||
import redditHelper from "../../assets/javascripts/helpers/reddit.js";
|
||||
import searchHelper from "../../assets/javascripts/helpers/google-search.js";
|
||||
import googleTranslateHelper from "../../assets/javascripts/helpers/google-translate.js";
|
||||
|
@ -13,6 +14,9 @@ import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
|
|||
const nitterInstances = twitterHelper.redirects;
|
||||
const twitterDomains = twitterHelper.targets;
|
||||
const youtubeDomains = youtubeHelper.targets;
|
||||
const mediumDomains = mediumHelper.targets;
|
||||
const scribeInstances = mediumHelper.redirects;
|
||||
const scribeDefault = mediumHelper.redirects[0];
|
||||
const invidiousInstances = youtubeHelper.redirects;
|
||||
const instagramDomains = instagramHelper.targets;
|
||||
const bibliogramInstances = instagramHelper.redirects;
|
||||
|
@ -43,6 +47,7 @@ let disableInvidious;
|
|||
let disableBibliogram;
|
||||
let disableOsm;
|
||||
let disableReddit;
|
||||
let disableScribe;
|
||||
let disableSearchEngine;
|
||||
let disableSimplyTranslate;
|
||||
let disableWikipedia;
|
||||
|
@ -50,6 +55,7 @@ let nitterInstance;
|
|||
let invidiousInstance;
|
||||
let bibliogramInstance;
|
||||
let osmInstance;
|
||||
let scribeInstance;
|
||||
let redditInstance;
|
||||
let searchEngineInstance;
|
||||
let simplyTranslateInstance;
|
||||
|
@ -77,6 +83,7 @@ browser.storage.sync.get(
|
|||
"bibliogramInstance",
|
||||
"osmInstance",
|
||||
"redditInstance",
|
||||
"scribeInstance",
|
||||
"searchEngineInstance",
|
||||
"simplyTranslateInstance",
|
||||
"wikipediaInstance",
|
||||
|
@ -85,6 +92,7 @@ browser.storage.sync.get(
|
|||
"disableBibliogram",
|
||||
"disableOsm",
|
||||
"disableReddit",
|
||||
"disableScribe",
|
||||
"disableSearchEngine",
|
||||
"disableSimplyTranslate",
|
||||
"disableWikipedia",
|
||||
|
@ -108,6 +116,7 @@ browser.storage.sync.get(
|
|||
bibliogramInstance = result.bibliogramInstance;
|
||||
osmInstance = result.osmInstance || osmDefault;
|
||||
redditInstance = result.redditInstance || redditDefault;
|
||||
scribeInstance = result.scribeInstance || scribeDefault;
|
||||
searchEngineInstance = result.searchEngineInstance;
|
||||
simplyTranslateInstance =
|
||||
result.simplyTranslateInstance || simplyTranslateDefault;
|
||||
|
@ -169,6 +178,9 @@ browser.storage.onChanged.addListener((changes) => {
|
|||
if ("redditInstance" in changes) {
|
||||
redditInstance = changes.redditInstance.newValue || redditDefault;
|
||||
}
|
||||
if ("scribeInstance" in changes) {
|
||||
scribeInstance = changes.scribeInstance.newValue || scribeDefault;
|
||||
}
|
||||
if ("searchEngineInstance" in changes) {
|
||||
searchEngineInstance = changes.searchEngineInstance.newValue;
|
||||
}
|
||||
|
@ -515,6 +527,53 @@ function redirectReddit(url, initiator, type) {
|
|||
return `${redditInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function redirectScribe(url, initiator, type) {
|
||||
if (disableScribe || isException(url, initiator)) {
|
||||
return null;
|
||||
}
|
||||
// Do not redirect when already on the selected view
|
||||
if (
|
||||
(initiator && initiator.origin === scribeInstance) ||
|
||||
url.origin === scribeInstance
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
// Do not redirect exclusions nor anything other than main_frame
|
||||
if (type !== "main_frame") {
|
||||
return null;
|
||||
}
|
||||
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) {
|
||||
if (disableSearchEngine || isException(url, initiator)) {
|
||||
return null;
|
||||
|
@ -607,6 +666,10 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||
redirect = {
|
||||
redirectUrl: redirectReddit(url, initiator, details.type),
|
||||
};
|
||||
} else if (mediumDomains.includes(url.host)) {
|
||||
redirect = {
|
||||
redirectUrl: redirectScribe(url, initiator, details.type),
|
||||
};
|
||||
} else if (url.href.match(googleSearchRegex)) {
|
||||
redirect = {
|
||||
redirectUrl: redirectSearchEngine(url, initiator),
|
||||
|
|
|
@ -141,6 +141,28 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section class="settings-block">
|
||||
<table class="option" aria-label="Toggle Scribe redirects">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<h1 data-localise="__MSG_disableScribe__">
|
||||
Scribe Redirects
|
||||
</h1>
|
||||
</td>
|
||||
<td>
|
||||
<input
|
||||
aria-hidden="true"
|
||||
id="disable-scribe"
|
||||
type="checkbox"
|
||||
checked
|
||||
/>
|
||||
<label for="disable-scribe" class="checkbox-label"> </label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
<section class="settings-block">
|
||||
<table class="option" aria-label="Toggle Search Engine redirects">
|
||||
|
@ -256,6 +278,16 @@
|
|||
/>
|
||||
</div>
|
||||
</section>
|
||||
<section class="settings-block">
|
||||
<h1 data-localise="__MSG_scribeInstance__">Scribe Instance</h1>
|
||||
<div class="autocomplete">
|
||||
<input
|
||||
id="scribe-instance"
|
||||
type="url"
|
||||
placeholder="https://libredd.it"
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
<section class="settings-block">
|
||||
<h1 data-localise="__MSG_searchEngineInstance__">Search Engine Instance</h1>
|
||||
<div class="autocomplete">
|
||||
|
|
|
@ -6,6 +6,7 @@ import youtubeHelper from "../../assets/javascripts/helpers/youtube.js";
|
|||
import instagramHelper from "../../assets/javascripts/helpers/instagram.js";
|
||||
import mapsHelper from "../../assets/javascripts/helpers/google-maps.js";
|
||||
import redditHelper from "../../assets/javascripts/helpers/reddit.js";
|
||||
import mediumHelper from "../../assets/javascripts/helpers/medium.js";
|
||||
import searchHelper from "../../assets/javascripts/helpers/google-search.js";
|
||||
import googleTranslateHelper from "../../assets/javascripts/helpers/google-translate.js";
|
||||
import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
|
||||
|
@ -15,6 +16,7 @@ const invidiousInstances = youtubeHelper.redirects;
|
|||
const bibliogramInstances = instagramHelper.redirects;
|
||||
const osmInstances = mapsHelper.redirects;
|
||||
const redditInstances = redditHelper.redirects;
|
||||
const scribeInstances = mediumHelper.redirects;
|
||||
const searchEngineInstances = searchHelper.redirects;
|
||||
const simplyTranslateInstances = googleTranslateHelper.redirects;
|
||||
const wikipediaInstances = wikipediaHelper.redirects;
|
||||
|
@ -24,6 +26,7 @@ const autocompletes = [
|
|||
{ id: "bibliogram-instance", instances: bibliogramInstances },
|
||||
{ id: "osm-instance", instances: osmInstances },
|
||||
{ id: "reddit-instance", instances: redditInstances },
|
||||
{ id: "scribe-instance", instances: scribeInstances },
|
||||
{
|
||||
id: "search-engine-instance",
|
||||
instances: searchEngineInstances.map((instance) => instance.link),
|
||||
|
@ -38,6 +41,7 @@ let invidiousInstance = document.getElementById("invidious-instance");
|
|||
let bibliogramInstance = document.getElementById("bibliogram-instance");
|
||||
let osmInstance = document.getElementById("osm-instance");
|
||||
let redditInstance = document.getElementById("reddit-instance");
|
||||
let scribeInstance = document.getElementById("scribe-instance");
|
||||
let searchEngineInstance = document.getElementById("search-engine-instance");
|
||||
let simplyTranslateInstance = document.getElementById(
|
||||
"simply-translate-instance"
|
||||
|
@ -48,6 +52,7 @@ let disableInvidious = document.getElementById("disable-invidious");
|
|||
let disableBibliogram = document.getElementById("disable-bibliogram");
|
||||
let disableOsm = document.getElementById("disable-osm");
|
||||
let disableReddit = document.getElementById("disable-reddit");
|
||||
let disableScribe = document.getElementById("disable-scribe");
|
||||
let disableSearchEngine = document.getElementById("disable-search-engine");
|
||||
let disableSimplyTranslate = document.getElementById(
|
||||
"disable-simply-translate"
|
||||
|
@ -103,6 +108,7 @@ browser.storage.sync.get(
|
|||
"bibliogramInstance",
|
||||
"osmInstance",
|
||||
"redditInstance",
|
||||
"scribeInstance",
|
||||
"searchEngineInstance",
|
||||
"simplyTranslateInstance",
|
||||
"wikipediaInstance",
|
||||
|
@ -111,6 +117,7 @@ browser.storage.sync.get(
|
|||
"disableBibliogram",
|
||||
"disableOsm",
|
||||
"disableReddit",
|
||||
"disableScribe",
|
||||
"disableSearchEngine",
|
||||
"disableSimplyTranslate",
|
||||
"disableWikipedia",
|
||||
|
@ -139,6 +146,7 @@ browser.storage.sync.get(
|
|||
bibliogramInstance.value = result.bibliogramInstance || "";
|
||||
osmInstance.value = result.osmInstance || "";
|
||||
redditInstance.value = result.redditInstance || "";
|
||||
scribeInstance.value = result.scribeInstance || "";
|
||||
searchEngineInstance.value =
|
||||
(result.searchEngineInstance && result.searchEngineInstance.link) || "";
|
||||
simplyTranslateInstance.value = result.simplyTranslateInstance || "";
|
||||
|
@ -148,6 +156,7 @@ browser.storage.sync.get(
|
|||
disableBibliogram.checked = !result.disableBibliogram;
|
||||
disableOsm.checked = !result.disableOsm;
|
||||
disableReddit.checked = !result.disableReddit;
|
||||
disableScribe.checked = !result.disableScribe;
|
||||
disableSearchEngine.checked = !result.disableSearchEngine;
|
||||
disableSimplyTranslate.checked = !result.disableSimplyTranslate;
|
||||
disableWikipedia.checked = !result.disableWikipedia;
|
||||
|
@ -311,6 +320,15 @@ const redditInstanceChange = debounce(() => {
|
|||
}, 500);
|
||||
redditInstance.addEventListener("input", redditInstanceChange);
|
||||
|
||||
const scribeInstanceChange = debounce(() => {
|
||||
if (scribeInstance.checkValidity()) {
|
||||
browser.storage.sync.set({
|
||||
scribeInstance: parseURL(scribeInstance.value),
|
||||
});
|
||||
}
|
||||
}, 500);
|
||||
scribeInstance.addEventListener("input", scribeInstanceChange);
|
||||
|
||||
const searchEngineInstanceChange = debounce(() => {
|
||||
const instance = searchEngineInstances.find(
|
||||
(instance) => instance.link === searchEngineInstance.value
|
||||
|
@ -369,6 +387,10 @@ disableReddit.addEventListener("change", (event) => {
|
|||
browser.storage.sync.set({ disableReddit: !event.target.checked });
|
||||
});
|
||||
|
||||
disableScribe.addEventListener("change", (event) => {
|
||||
browser.storage.sync.set({ disableScribe: !event.target.checked });
|
||||
});
|
||||
|
||||
disableSearchEngine.addEventListener("change", (event) => {
|
||||
browser.storage.sync.set({ disableSearchEngine: !event.target.checked });
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue