Greasy Fork

Greasy Fork is available in English.

蘋果新聞免登入

移植自GitHub

当前为 2019-05-17 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         蘋果新聞免登入
// @namespace    https://github.com/it9gamelog/gcx-appledaily-esc-paywall
// @version      0.2
// @description  移植自GitHub
// @author       You
// @match        *.appledaily.com/*
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    var article = document.querySelector('.Article');
    var blocker = document.querySelector('.contentblock-block');

    if (article && blocker) {
        // 香港/北美版
        //
        // The completed article is presented to the client then hide later with JS,
        // hence the script could achive the goal by just manipulating the DOM.
        //
        // After page load, the DOM of every paragraphs, excepted the first one,
        // in an article is removed.
        // Then a paywall is shown.

        // Backup the article DOM
        var preservedArticle = article.cloneNode(true);

        // function to restore the article
        var restoreArticle = function() {
            // Remove the paywall
            var block = document.querySelector('.contentblock-block');
            if (block) block.remove();

            // Remove the gradient background and height limitation
            var style = document.createElement('style');
            style.innerHTML = `
            .LHSContent:before { background: none !important; }
            #articleContent { height: initial !important; }
        `;
            document.head.appendChild(style);

            // Restore the article
            article.replaceWith(preservedArticle);
            console.log("Esc Paywall: Completed");
        };

        // Monitor when the article children is removed, then queue the restore function
        var observer = new MutationObserver(function(mutations) {
            mutations.some(function(mutation) {
                if (!mutation.removedNodes) return false;
                observer.disconnect();
                // Queue the function to make sure the paywall script is done before restoring
                setTimeout(restoreArticle, 10);
                return true;
            })
        })
        observer.observe(article, {
            childList: true
        });
    }
})();