-
-
Save ymolliks/62dc5fd5037e27e1e845ea185dfe5a56 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 *://*/* | |
// @run-at document-start | |
// @version 1.1 | |
// @updateURL https://gist.githubusercontent.com/samhenrigold/4a082dde823bc3cb62e43a2fc2b12b8e/raw/893a9480a1922e87a5b1cd16c66e405db53e43b6/medium-to-scribe.js | |
// @downloadURL https://gist.githubusercontent.com/samhenrigold/4a082dde823bc3cb62e43a2fc2b12b8e/raw/893a9480a1922e87a5b1cd16c66e405db53e43b6/medium-to-scribe.js | |
// ==/UserScript== | |
const badHosts = [ | |
"android.jlelse.eu", | |
"betterhumans.coach.me", | |
"survivingtomorrow.org", | |
"blog.angularindepth.com", | |
"blog.bitsrc.io", | |
"blog.devartis.com", | |
"blog.getambassador.io", | |
"blog.hipolabs.com", | |
"blog.maddevs.io", | |
"blog.prototypr.io", | |
"blog.usejournal.com", | |
"calia.me", | |
"www.cantorsparadise.com", | |
"codeburst.io", | |
"engineering.opsgenie.com", | |
"entrepreneurshandbook.co", | |
"hackernoon.com", | |
"instagram-engineering.com", | |
"itnext.io", | |
"levelup.gitconnected.com", | |
"medium.com", | |
"medium.freecodecamp.org", | |
"medium.mybridge.co", | |
"proandroiddev.com", | |
"productcoalition.com", | |
"psiloveyou.xyz", | |
"robinhood.engineering", | |
"theascent.pub", | |
"thebolditalic.com", | |
"towardsdatascience.com", | |
"ux.shopify.co", | |
"uxdesign.cc", | |
"uxplanet.org", | |
"blog.gds-gov.tech" | |
]; | |
let subdomain = ""; | |
// Easy, general match with the list of known Medium hosts. Most of the time, this will be the case. | |
if (badHosts.includes(window.location.host)) { | |
window.location.href = `https://scribe.rip${window.location.pathname}`; | |
} else if (window.location.hostname.indexOf("medium.com") > -1) { | |
/* | |
If medium.com is somewhere hostname but the first if statement didn't catch it, we assume the hostname is <example>.medium.com. | |
Any article URL matching that subdomain pattern can be rewritten as medium.com/<example>/article-title. | |
*/ | |
let hostnameClone = window.location.hostname; | |
// We need to check if the subdomain contains "www" and remove it before using the "pure" subdomain. | |
if (hostnameClone.indexOf('www.') > -1) { hostnameClone.replace('www.', ''); } | |
window.location.href = `https://scribe.rip/${hostnameClone.split('.')[0]}${window.location.pathname}`; | |
} | |
// const debuggingArticles = [ | |
// "http://medium.com/finding-insight/cancel-culture-just-cancelled-my-favorite-furniture-b652b2afb088", | |
// "http://medium.com/good-service/introducing-dynamic-route-maps-a8e56dd8a33", | |
// "https://medium.com/hackernoon/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2", | |
// "https://michaellong.medium.com/swiftui-vs-jetpack-compose-why-android-wins-hands-down-b5f849b730db"] | |
/* | |
## Digging Deeper | |
So I ran into an article on https://blog.gds-gov.tech/ which is hosted by Medium. None of the logic up until this point has checked if a site is Medium but it's not in the URL. So I need to figure out how to check if a particular page is Medium by hunting through the <head>. I'm not sure how to do that without tanking performance. | |
I'm trying to find a meta tag or something that is immutable. In other words, a tag where the domain owner (the GDS in this case) cannot change it. I've found this: | |
<meta data-rh="true" property="og:site_name" content="Medium"> | |
but I need to find more examples to see what other sites use this. | |
Another consideration: doing the check client-side, if the site is Medium but was not in the big array, asking the user if they'd like to share that addition to the database. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment