Open Medium premium links with Freedium.cfd

Adds a button to open the current Medium article with freedium.cfd

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Open Medium premium links with Freedium.cfd
// @namespace    
// @version      1.0
// @description  Adds a button to open the current Medium article with freedium.cfd
// @match        *://medium.com/*
// @match        *://*.medium.com/*
// @grant        none
 // @license MIT
// ==/UserScript==

(function() {
    'use strict';

    function addButton() {
        let paragraphs = document.querySelectorAll("p");
        let found = false;

        paragraphs.forEach(p => {
            if (p.textContent.includes("Member-only") && !found) {
                found = true;

                let btn = document.createElement('button');
                btn.textContent = "Open with freedium";
                btn.style.marginLeft = "10px";
                btn.style.padding = "5px";
                btn.style.backgroundColor = "#ff6600";
                btn.style.color = "#fff";
                btn.style.border = "none";
                btn.style.borderRadius = "5px";
                btn.style.cursor = "pointer";

                // Define the button action
                btn.addEventListener('click', () => {
                    let currentURL=encodeURIComponent(window.location.href);
                    window.open(`https://freedium.cfd/${currentURL}`, '_blank');
                });

                p.appendChild(btn);
            }
        });

        if (!found) {
            console.log("Target div not found.");
        }
    }

    // Run the function when the page loads
    window.addEventListener('load', addButton);
})();