Medium to Freedium Redirect

Redirects Medium membership articles to freedium.cfd

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @license MIT
// @name         Medium to Freedium Redirect
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Redirects Medium membership articles to freedium.cfd
// @author       You
// @match        *://*.medium.com/*
// @match        *://*.towardsdatascience.com/*
// @match        *://*.betterprogramming.pub/*
// @match        *://*.blog.blockmagnates.com/*
// @match        *://*.levelup.gitconnected.com/*
// @match        *://*.uxdesign.cc/*
// @match        *://*.betterhumans.pub/*
// @match        *://*.baos.pub/*
// @match        *://*.blog.devgenius.io/*
// @match        *://*.bootcamp.uxdesign.cc/*
// @match        *://*.entrepreneurshandbook.co/*
// @match        *://*.blog.usejournal.com/*
// @match        *://*.writingcooperative.com/*
// @match        *://*.blog.prototypr.io/*
// @match        *://*.blog.bitsrc.io/*
// @match        *://*.thebolditalic.com/*
// @match        *://*.aninjusticemag.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // Function to check if the page is showing a membership wall
    function isMembershipRequired() {
        // Check for membership wall element or if article is truncated
        if (document.querySelector('.meteredContent')) return true;
        if (document.querySelector('.overlay-message')) return true;
        if (document.querySelector('#paywall-upsell-button-upgrade')) return true;

        // Wait for content to load and check if article is truncated
        setTimeout(function() {
            if (document.querySelector('.meteredContent')) {
                redirectToFreedium();
            }
            if (document.querySelector('.overlay-message')) {
                redirectToFreedium();
            }
        }, 1500);

        return false;
    }

    // Function to redirect to freedium
    function redirectToFreedium() {
        const currentUrl = window.location.href;
        // Check if the URL is already a freedium URL
        if (!currentUrl.includes('freedium.cfd')) {
            const freediumUrl = 'https://freedium.cfd/' + currentUrl;
            window.location.href = freediumUrl;
        }
    }

    // Initial check on page load
    window.addEventListener('load', function() {
        if (isMembershipRequired()) {
            redirectToFreedium();
        }
    });

    // Track DOM changes to detect when a paywall might appear
    const observer = new MutationObserver(function(mutations) {
        for (const mutation of mutations) {
            if (mutation.addedNodes.length) {
                if (isMembershipRequired()) {
                    redirectToFreedium();
                    break;
                }
            }
        }
    });

    // Start observing the document after it's fully loaded
    window.addEventListener('DOMContentLoaded', function() {
        observer.observe(document.body, { childList: true, subtree: true });
    });
})();