Freedium Redirect for Medium

Automatically open Medium articles on freedium.cfd.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Freedium Redirect for Medium
// @namespace    https://medium.com/
// @version      1.1
// @description  Automatically open Medium articles on freedium.cfd.
// @author       Nick Bakaka
// @match        https://*.medium.com/*
// @grant        none
// @license      CC
// ==/UserScript==

(function () {
    'use strict';

    /* ------------------------------------------------------------------
       1️⃣ List every domain you want the banner on (case‑insensitive).
          e.g. "medium.com", "uxdesign.cc", "example.org"
    ------------------------------------------------------------------ */
    const SHOW_ON_HOSTS = [
        "medium.com",
        "uxdesign.cc"
        // add more here...
    ];

    /* 2️⃣ The host that will receive the redirected URL (unchanged) */
    const FREEDIUM_HOST   = "freedium.cfd";
    const REDIRECT_PREFIX = `https://${FREEDIUM_HOST}/`;

    /* Helper: does the current page belong to one of our target hosts? */
    function isTargetPage() {
        return SHOW_ON_HOSTS.some(h => window.location.hostname.includes(h));
    }

    // If we're NOT on a target host, nothing to do.
    if (!isTargetPage()) return;

    /** Build the URL that will open the article on freedium.cfd */
    function buildRedirectUrl() {
        return REDIRECT_PREFIX + encodeURIComponent(window.location.href);
    }

    /* Create and inject the banner element. */
    function createBanner() {
        const banner = document.createElement('div');
        banner.textContent = 'Open in Freedium.cfd';

        Object.assign(banner.style, {
            position:      'fixed',
            top:           '72px',
            right:         '20px',
            padding:       '.7em 1em',
            background:    'rgb(31,41,55)',
            color:         'rgb(34,197,94)',
            border:        '2px solid rgb(34,197,94)',
            cursor:        'pointer',
            zIndex:        '9999',
            fontFamily:    'sans-serif',
            fontSize:      '.75rem'
        });

        banner.addEventListener('mouseover', () => {
            banner.style.background = 'rgb(45,55,72)';
        });
        banner.addEventListener('mouseout', () => {
            banner.style.background = 'rgb(31,41,55)';
        });

        banner.onclick = () => window.location.replace(buildRedirectUrl());

        document.body.appendChild(banner);
    }

    /* Run after the page has finished rendering. */
    if (document.readyState === 'complete' || document.readyState === 'interactive')
        createBanner();
    else
        window.addEventListener('DOMContentLoaded', createBanner);
})();