Skip to content

Instantly share code, notes, and snippets.

@rainux
Created April 23, 2024 00:10
Show Gist options
  • Save rainux/a2c53450d005a8e1ab78e2c52fc22fe6 to your computer and use it in GitHub Desktop.
Save rainux/a2c53450d005a8e1ab78e2c52fc22fe6 to your computer and use it in GitHub Desktop.
Redirect Medium posts to ReadMedium.com
// ==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