-
-
Save superkeyor/e1000f6ab5d2aabf01141b7f0e0d3d96 to your computer and use it in GitHub Desktop.
UserScript to redirect medium.com articles to scribe.rip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Medium to Scribe | |
// @description Redirects Medium.com articles to scribe.rip | |
// @match *://*/* | |
// @exclude /^https?://(www\.)?medium\.com/((\?.*)|((m|about|creators|membership)/.*))$/ | |
// @run-at document-end | |
// @version 1.2.4 | |
// @updateURL https://gist.githubusercontent.com/samhenrigold/4a082dde823bc3cb62e43a2fc2b12b8e/raw/medium-to-scribe.js | |
// ==/UserScript== | |
/* | |
I rewrote this script to be more efficient and less prone to breaking. Here's how it works: | |
0. Before the script even runs, check to see if the current page is a Medium URL but NOT an article URL. This is to prevent the script from redirecting you from Medium's terms of service or signup pages. | |
1. We check if the page you're on is a Medium article by checking for the presence of a specific meta tag in the document head. | |
2. Check if we've already written the datetime to this article's localstorage (we use the key "scribeRedirected"). | |
a. If scribeRedirected is present, we know we've already redirected this article to scribe.rip and you've gone back to Medium for whatever reason (If scribe broke the article or something). | |
b. If it doesn't exist OR if the datetime is older than 30 seconds in the past, we assume you've been sent to this Medium article and want to get redirected to scribe, so we write the current datetime to localStorage and send you on your way. | |
*/ | |
// Match <meta property="al:android:package" content="com.medium.reader"> in the document head | |
if (document.querySelector("meta[property='al:android:package']") && document.querySelector("meta[property='al:android:package']").content === "com.medium.reader") { | |
// check if localStorage.getItem("scribeRedirected") is empty or if the value is within the last 10 minutes | |
if (localStorage.getItem("scribeRedirected") === null || (new Date().getTime() - localStorage.getItem("scribeRedirected")) > 30_000) { | |
localStorage.setItem("scribeRedirected", Date.now()); | |
window.history.pushState({}, "", window.location.href); | |
window.location.hostname = "scribe.rip"; | |
// Make sure the old url is in the history so we can go back to it | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment