Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Forked from mathix420/medium.user.js
Created February 19, 2024 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iqiancheng/b985da58ac5f333a045efaafb1be29b1 to your computer and use it in GitHub Desktop.
Save iqiancheng/b985da58ac5f333a045efaafb1be29b1 to your computer and use it in GitHub Desktop.
Bypass Medium Paywall - Working late 2023 - Greasy Fork, Violentmonkey, Tampermonkey
// ==UserScript==
// @name Medium Paywall Bypass
// @namespace Violentmonkey Scripts
// @run-at document-start
// @match *://*.medium.com/*
// @match *://medium.com/*
// @match *://*/*
// @grant none
// @version 2.1
// @inject-into content
// @updateURL https://gist.githubusercontent.com/mathix420/e0604ab0e916622972372711d2829555/raw/medium.user.js
// @downloadURL https://gist.githubusercontent.com/mathix420/e0604ab0e916622972372711d2829555/raw/medium.user.js
// @website https://freedium.cfd
// @author Mathix420, ZhymabekRoman
// @description Don't forget to remove `@match` filters you don't want.
// ==/UserScript==
// initCall is telling us if we need to inject the title observer
function mediumRedirecter(initCall = false) {
const mediumPostUrlProperty = document.head.querySelector('meta[property="al:android:url"]') || {}
if (
// Allow seeing original articles that were already redirected to freedium.
!window.location.href.endsWith('#bypass') &&
// Do not redirect when editing on medium.
!window.location.href.includes("/edit?source=") &&
// Detect if we are on a medium website (regardless of the domain)
(mediumPostUrlProperty.content && mediumPostUrlProperty.content.includes('medium://p/'))
) {
window.location.href = 'https://freedium.cfd/' + window.location.href;
} else if (initCall && /(.*\.|^)medium\.com$/.test(window.location.host)) {
new MutationObserver(function(mutations) {
if (mutations[0].target.textContent) mediumRedirecter();
}).observe(
document.querySelector('title'),
{ subtree: true, characterData: true, childList: true }
);
}
}
mediumRedirecter(true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment