Freedium Redirect for Medium

Automatically open Medium articles on freedium.cfd.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
})();