Greasy Fork

Greasy Fork is available in English.

Medium免费阅读 Medium Unlock

Adds a button to read full Medium articles via freedium.cfd

当前为 2024-11-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Medium免费阅读 Medium Unlock
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a button to read full Medium articles via freedium.cfd
// @author       Your name
// @match        https://*.medium.com/*/*
// @match        https://medium.com/*
// @match        https://*.towardsdatascience.com/*
// @match        https://*.plainenglish.io/*
// @match        https://*.gitconnected.com/*
// @match        https://*.betterprogramming.pub/*
// @match        https://*.levelup.gitconnected.com/*
// @match        https://freedium.cfd/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=medium.com
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Handle freedium.cfd site
    if (window.location.hostname === 'freedium.cfd') {
        // Function to remove notification element and click confirm button if exists
        const handleNotification = () => {
            const notification = document.querySelector("body > div.notification-container.fixed.top-5.p-2.max-h-\\[95vh\\].overflow-y-auto.hidden > div");
            if (notification) {
                const confirmButton = notification.querySelector('button');
                if (confirmButton) {
                    confirmButton.click();
                }
                notification.remove();
            }
        };

        // Try to handle notification immediately
        handleNotification();

        // Also observe DOM changes to handle notification if it appears later
        const observer = new MutationObserver(handleNotification);
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });

        return;
    }

    // Wait for page to load completely
    function init() {
        // Skip if we're on the Medium homepage
        if (window.location.hostname === 'medium.com' && 
            (window.location.pathname === '/' || window.location.pathname === '')) {
            return;
        }
        // Create the button
        const button = document.createElement('button');
        button.innerHTML = 'Read Full Article 阅读全文 ';
        button.style.cssText = `
            position: fixed;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            z-index: 999999;
            padding: 14px 24px;
            background-color: white;
            color: rgb(41, 41, 41);
            border: 1px solid rgb(41, 41, 41);
            border-radius: 99em;
            cursor: pointer;
            font-family: sohne, "Helvetica Neue", Helvetica, Arial, sans-serif;
            font-size: 14px;
            font-weight: 400;
            line-height: 20px;
            text-align: center;
            text-decoration: none;
            transition: all 0.2s ease-in-out;
            box-shadow: none;
        `;

        // Add hover effect
        button.onmouseover = function() {
            this.style.backgroundColor = 'rgb(41, 41, 41)';
            this.style.color = 'white';
        };
        button.onmouseout = function() {
            this.style.backgroundColor = 'white';
            this.style.color = 'rgb(41, 41, 41)';
        };

        // Add click event
        button.onclick = function() {
            const currentUrl = window.location.href;
            const freediumUrl = 'https://freedium.cfd/' + currentUrl;
            window.open(freediumUrl, '_blank');
        };

        // Add button to page
        document.body.appendChild(button);
    }

    // Add button to article list items
    function addReadFullButtons() {
        const articleItems = document.querySelectorAll('article');
        articleItems.forEach(article => {
            const actionsDiv = article.querySelector('div.x.de.kc');
            if (actionsDiv && !actionsDiv.querySelector('.read-full-zh')) {
                const button = document.createElement('button');
                button.className = 'read-full-zh';
                button.textContent = '阅读全文';
                button.style.cssText = 'margin-left: 12px; color: rgb(26, 137, 23); cursor: pointer; font-size: 14px; border: none; background: none; padding: 0;';
                
                button.addEventListener('click', (e) => {
                    e.preventDefault();
                    const articleLink = article.querySelector('a[aria-label]');
                    if (articleLink) {
                        window.location.href = articleLink.href;
                    }
                });
                
                actionsDiv.appendChild(button);
            }
        });
    }

    // Observe DOM changes to handle dynamically loaded content
    const observeDOM = () => {
        const observer = new MutationObserver(() => {
            addReadFullButtons();
        });
        
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    };

    // Initialize the feature
    function initializeReadFullFeature() {
        addReadFullButtons();
        observeDOM();
    }

    // Run init when page is loaded
    if (document.readyState === 'complete') {
        init();
        initializeReadFullFeature();
    } else {
        window.addEventListener('load', () => {
            init();
            initializeReadFullFeature();
        });
    }

    // Also run init when URL changes (for single page applications)
    let lastUrl = location.href;
    new MutationObserver(() => {
        const url = location.href;
        if (url !== lastUrl) {
            lastUrl = url;
            init();
            initializeReadFullFeature();
        }
    }).observe(document, { subtree: true, childList: true });
})();