Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add redirect from Medium to Scribe #311

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
16 changes: 15 additions & 1 deletion README.md
Expand Up @@ -20,7 +20,17 @@

## About

A web extension that redirects _Twitter, YouTube, Instagram, Google Maps, Reddit, Google Search, & Google Translate_ requests to privacy friendly alternative frontends for those sites - [Nitter](https://github.com/zedeus/nitter), [Invidious](https://github.com/iv-org/invidious), [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Bibliogram](https://sr.ht/~cadence/bibliogram/), [OpenStreetMap](https://www.openstreetmap.org/), [SimplyTranslate](https://git.sr.ht/~metalune/simplytranslate_web) & Private Search Engines like [DuckDuckGo](https://duckduckgo.com) and [Startpage](https://startpage.com).
A web extension that redirects _Twitter, YouTube, Instagram, Google Maps,
Reddit, Medium, Google Search, & Google Translate_ requests to privacy friendly
alternatives for those sites - [Nitter](https://github.com/zedeus/nitter),
[Invidious](https://github.com/iv-org/invidious),
[FreeTube](https://github.com/FreeTubeApp/FreeTube),
[Bibliogram](https://sr.ht/~cadence/bibliogram/),
[OpenStreetMap](https://www.openstreetmap.org/),
[Scribe](https://sr.ht/~edwardloveall/scribe/),
[SimplyTranslate](https://git.sr.ht/~metalune/simplytranslate_web) &
Private Search Engines like [DuckDuckGo](https://duckduckgo.com) and
[Startpage](https://startpage.com).

It's possible to toggle all redirects on and off. The extension will default to using random instances if none are selected. If these instances are not working, you can try and set a custom instance from the list below.

Expand All @@ -47,6 +57,10 @@ Privacy Redirect allows setting custom instances, instances can be found here:
- [Mojeek](https://www.mojeek.com)
- [Presearch](https://www.presearch.org)
- [Whoogle](https://benbusby.com/projects/whoogle-search/)
- [Scribe](https://sr.ht/~edwardloveall/scribe/) instances:, an alternative frontend for Medium:
- [scribe.rip](https://scribe.rip/)
- [NixNet scribe](https://scribe.nixnet.services/)
- [Citizen4 scribe](https://scribe.citizen4.eu/)

## Development

Expand Down
12 changes: 12 additions & 0 deletions src/_locales/en/messages.json
Expand Up @@ -11,6 +11,10 @@
"message": "Nitter Instance",
"description": "Label for Nitter instance field option (options)."
},
"scribeInstance": {
"message": "Scribe Instance",
"description": "Label for Scribe instance field option (options)."
},
"invidiousInstance": {
"message": "Invidious Instance",
"description": "Label for Invidious instance field option (options)."
Expand Down Expand Up @@ -43,6 +47,10 @@
"message": "Nitter Redirects",
"description": "Label for enable/disable Nitter redirects option (options & pop-up)."
},
"disableScribe": {
"message": "Scribe Redirects",
"description": "Label for enable/disable Scribe redirects option (options & pop-up)."
},
"disableInvidious": {
"message": "Invidious Redirects",
"description": "Label for enable/disable Invidious redirects option (options & pop-up)."
Expand Down Expand Up @@ -147,6 +155,10 @@
"message": "Nitter random instance pool (comma-separated)",
"description": "Label for 'Nitter random instance pool (comma-separated)' option (options)."
},
"scribeRandomPool": {
"message": "Scribe random instance pool (comma-separated)",
"description": "Label for 'Scribe 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)."
Expand Down
27 changes: 27 additions & 0 deletions src/assets/javascripts/helpers/medium.js
@@ -0,0 +1,27 @@
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"
"https://scribe.citizen4.eu"
];

export default {
targets,
redirects,
};
49 changes: 49 additions & 0 deletions src/pages/background/background.js
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -43,13 +47,15 @@ let disableInvidious;
let disableBibliogram;
let disableOsm;
let disableReddit;
let disableScribe;
let disableSearchEngine;
let disableSimplyTranslate;
let disableWikipedia;
let nitterInstance;
let invidiousInstance;
let bibliogramInstance;
let osmInstance;
let scribeInstance;
let redditInstance;
let searchEngineInstance;
let simplyTranslateInstance;
Expand All @@ -66,6 +72,7 @@ let useFreeTube;
let nitterRandomPool;
let invidiousRandomPool;
let bibliogramRandomPool;
let scribeRandomPool;
let exceptions;

window.browser = window.browser || window.chrome;
Expand All @@ -77,6 +84,7 @@ browser.storage.sync.get(
"bibliogramInstance",
"osmInstance",
"redditInstance",
"scribeInstance",
"searchEngineInstance",
"simplyTranslateInstance",
"wikipediaInstance",
Expand All @@ -85,6 +93,7 @@ browser.storage.sync.get(
"disableBibliogram",
"disableOsm",
"disableReddit",
"disableScribe",
"disableSearchEngine",
"disableSimplyTranslate",
"disableWikipedia",
Expand All @@ -100,6 +109,7 @@ browser.storage.sync.get(
"nitterRandomPool",
"invidiousRandomPool",
"bibliogramRandomPool",
"scribeRandomPool",
"exceptions",
],
(result) => {
Expand All @@ -108,11 +118,13 @@ browser.storage.sync.get(
bibliogramInstance = result.bibliogramInstance;
osmInstance = result.osmInstance || osmDefault;
redditInstance = result.redditInstance || redditDefault;
scribeInstance = result.scribeInstance;
searchEngineInstance = result.searchEngineInstance;
simplyTranslateInstance =
result.simplyTranslateInstance || simplyTranslateDefault;
wikipediaInstance = result.wikipediaInstance || wikipediaDefault;
disableNitter = result.disableNitter;
disableScribe = result.disableScribe;
disableInvidious = result.disableInvidious;
disableBibliogram = result.disableBibliogram;
disableOsm = result.disableOsm;
Expand Down Expand Up @@ -143,6 +155,9 @@ browser.storage.sync.get(
bibliogramRandomPool = result.bibliogramRandomPool
? result.bibliogramRandomPool.split(",")
: commonHelper.filterInstances(bibliogramInstances);
scribeRandomPool = result.scribeRandomPool
? result.scribeRandomPool.split(",")
: commonHelper.filterInstances(scribeInstances);
}
);

Expand All @@ -169,12 +184,18 @@ 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;
}
if ("disableNitter" in changes) {
disableNitter = changes.disableNitter.newValue;
}
if ("disableScribe" in changes) {
disableScribe = changes.disableScribe.newValue;
}
if ("disableInvidious" in changes) {
disableInvidious = changes.disableInvidious.newValue;
}
Expand Down Expand Up @@ -232,6 +253,9 @@ browser.storage.onChanged.addListener((changes) => {
if ("bibliogramRandomPool" in changes) {
bibliogramRandomPool = changes.bibliogramRandomPool.newValue.split(",");
}
if ("scribeRandomPool" in changes) {
scribeRandomPool = changes.scribeRandomPool.newValue.split(",");
}
if ("exceptions" in changes) {
exceptions = changes.exceptions.newValue.map((e) => {
return new RegExp(e);
Expand Down Expand Up @@ -515,6 +539,27 @@ function redirectReddit(url, initiator, type) {
return `${redditInstance}${url.pathname}${url.search}`;
}

function redirectMedium(url, initiator) {
if (disableScribe || isException(url, initiator)) {
return null;
}
if (
isFirefox() &&
initiator &&
(initiator.origin === scribeInstance ||
scribeInstances.includes(initiator.origin) ||
mediumDomains.includes(initiator.host))
) {
browser.storage.sync.set({
redirectBypassFlag: true,
});
return null;
}
return `${
scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
}${url.pathname}${url.search}`;
}

function redirectSearchEngine(url, initiator) {
if (disableSearchEngine || isException(url, initiator)) {
return null;
Expand Down Expand Up @@ -607,6 +652,10 @@ browser.webRequest.onBeforeRequest.addListener(
redirect = {
redirectUrl: redirectReddit(url, initiator, details.type),
};
} else if (mediumDomains.includes(url.host)) {
redirect = {
redirectUrl: redirectMedium(url, initiator),
};
} else if (url.href.match(googleSearchRegex)) {
redirect = {
redirectUrl: redirectSearchEngine(url, initiator),
Expand Down
47 changes: 46 additions & 1 deletion src/pages/options/options.html
Expand Up @@ -141,6 +141,28 @@ <h1 data-localise="__MSG_disableReddit__">
</tr>
</tbody>
</table>
</section>
<section class="settings-block">
<table class="option" aria-label="Toggle Scribe redirects">
<tbody>
<tr>
<td>
<h1 data-localise="__MSG_disableScribe__">
Huy-Ngo marked this conversation as resolved.
Show resolved Hide resolved
Scribe Redirects
</h1>
</td>
<td>
<input
aria-hidden="true"
id="disable-scribe"
type="checkbox"
checked
/>&nbsp;
<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">
Expand Down Expand Up @@ -188,7 +210,7 @@ <h1 data-localise="__MSG_disableSimplyTranslate__">SimplyTranslate Redirects</h1
<tbody>
<tr>
<td>
<h1 data-localise="__MSG_disableWikipedia__" class="new-badge" data-new-badge>Wikipedia Redirects</h1>
<h1 data-localise="__MSG_disableWikipedia__">Wikipedia Redirects</h1>
</td>
<td>
<input
Expand Down Expand Up @@ -256,6 +278,19 @@ <h1 data-localise="__MSG_redditInstance__">Reddit Instance</h1>
/>
</div>
</section>
<section class="settings-block">
<h1 data-localise="__MSG_scribeInstance__"
class="new-badge" data-new-badge>Scribe Instance</h1>
<div class="autocomplete">
<input
id="scribe-instance"
type="url"
name="scribe-instance"
data-localise-placeholder="__MSG_randomInstancePlaceholder__"
placeholder="Random instance (none selected)"
/>
</div>
</section>
<section class="settings-block">
<h1 data-localise="__MSG_searchEngineInstance__">Search Engine Instance</h1>
<div class="autocomplete">
Expand Down Expand Up @@ -557,6 +592,16 @@ <h1 data-localise="__MSG_bibliogramRandomPool__">
type="text"
/>
</section>
<section class="settings-block">
<h1 data-localise="__MSG_scribeRandomPool__">
Scribe random instance pool (comma-separated)
</h1>
<input
id="scribe-random-pool"
name="scribe-random-pool"
type="text"
/>
</section>
<hr>
</div>
</div>
Expand Down