GELocal Full Text Articles

Fetch the full text of GEDI local newspapers

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            GELocal Full Text Articles
// @name:it         GELocal - Articoli con testo completo
// @namespace       https://andrealazzarotto.com/
// @version         1.0.2
// @description     Fetch the full text of GEDI local newspapers
// @description:it  Mostra il testo completo degli articoli dei quotidiani locali GEDI
// @author          Andrea Lazzarotto
// @match           https://*.gelocal.it/*
// @require         https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @grant           GM_xmlhttpRequest
// @grant           GM.xmlHttpRequest
// @license         GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
// ==/UserScript==

/* Greasemonkey 4 wrapper */
if (typeof GM !== "undefined" && !!GM.xmlHttpRequest) {
    GM_xmlhttpRequest = GM.xmlHttpRequest;
}

function fetch(params) {
    return new Promise(function(resolve, reject) {
        params.onload = resolve;
        params.onerror = reject;
        GM_xmlhttpRequest(params);
    });
}

(function() {
    'use strict';

    if (location.href.endsWith('amp/')) {
        location.href = location.href.slice(0, -4);
    }

    $(document).ready(function() {
        var paywalled = $("#article-body").prop('hidden');

        if (paywalled) {
            fetch({
                method: 'GET',
                url: location.pathname,
            }).then(function(responseDetails) {
                var r = responseDetails.responseText;
                r = r.replace(/<script/gi, '<div hidden ').replace(/script>/gi, 'div>');
                var data = $(r);
                setTimeout(function() {
                    $('#article-body').replaceWith(data.find('#article-body'));
                    $('#article-body').attr('style', '').removeAttr('hidden');
                    $("#paywall-banner").parent().remove();
                    $(".paywall-adagio").remove();
                }, 1000);
            });
        }
    });
})();