Created
April 23, 2024 00:10
-
-
Save rainux/a2c53450d005a8e1ab78e2c52fc22fe6 to your computer and use it in GitHub Desktop.
Redirect Medium posts to ReadMedium.com
This file contains hidden or 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 Redirect Medium posts to ReadMedium.com | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Redirect Medium posts to ReadMedium.com | |
// @author Llama 3 | |
// @match *://*/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var mediumMetaTag = document.querySelector('meta[property="al:android:app_name"][content="Medium"]'); | |
if (mediumMetaTag) { | |
var ogUrlMetaTag = document.querySelector('meta[property="og:url"]'); | |
if (ogUrlMetaTag) { | |
var postId = getPostIdFromOgUrl(ogUrlMetaTag.content); | |
if (postId) { | |
var redirectUrl = 'https://readmedium.com/' + postId; | |
window.location.href = redirectUrl; | |
} | |
} | |
} | |
})(); | |
function getPostIdFromOgUrl(ogUrl) { | |
var urlParts = ogUrl.split('/'); | |
return urlParts[urlParts.length - 1]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment