Customize Zeit Online

Entferne unerwünschte Artikel/Abschnitte aus Zeit Online

当前为 2021-02-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Customize Zeit Online
// @namespace    https://greasyfork.org/en/users/689160-georg-vogt
// @version      2.5.2
// @description  Entferne unerwünschte Artikel/Abschnitte aus Zeit Online
// @author       Georg Vogt
// @match        https://www.zeit.de/*
// @run-at       document-body
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

'use strict';

var customBadSections = {};
var customBadHeadings = {};
var customBadQueries = {};
customBadSections = GM_getValue("customBadSections", {});
customBadHeadings = GM_getValue("customBadHeadings", {});
customBadQueries = GM_getValue("customBadQueries", {});

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
//                   Customize

// customBadSections["newsticker"] = true;
// customBadHeadings["Video"] = true;
// customBadQueries["*[href='https://www.zeit.de/kaenguru-comics-marc-uwe-kling-bernd-kissel ']"] = 3;

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////

GM_setValue("customBadSections", customBadSections);
GM_setValue("customBadHeadings", customBadHeadings);
GM_setValue("customBadQueries", customBadQueries);

console.log("TM: Custom settings:", customBadSections, customBadHeadings, customBadQueries);

function hideNode(node) {
    try {
        node.style.display = 'none';
        //  node.style.background = 'red'; //  debug
    } catch {}
}

function hideParent(node, num) {
    if (i < 0) return;
    for (var i=0; i<num; i++) {
        node = node?.parentElement;
    }
    hideNode(node);
}

const defaultBadSections = {
    "wochenmarkt": true,// Wochenmarkt
    "headed-zplus": true,// zplus
    "headed-zett": true,//  zett
    "headed-wirtschaftswoche": false,// Wirtschaftswoche
    "headed-zar": false,// Zeit Arbeit
    "headed-zmo": false,//  Zeit Magazin
    "shop": true,//  Shop
    "headed-zco": false,//  Zeit Campus
    };

const defaultBadHeadings = {
    "DAS BESTE AUS Z+": true,
    "DAS BESTE AUS Z+\n:\nUnsere Leseempfehlungen": true,
    "Diese Woche in der ZEIT": true,
    "Beliebte Artikel": true,
    "Politik": false,
    "Gesellschaft": false,
    "Podcasts": true,
    "Wirtschaft": false,
    "Kultur": false,
    "Video": true,
    "Wissen": false,
    "Digital": false,
    "Entdecken": false,
    "Mobilität": false,
    "Hamburg": false,
    "Sport": false,
    "Spiele": true,
    };

const badSections = {...defaultBadSections, ...customBadSections};
const badHeadings = {...defaultBadHeadings, ...customBadHeadings};

const zplusKeywords = [
    "zplus",//  pay to read
    "zplus-register",// register to read
    //  "zplus-dynamic",// unknown zplus article type, can still be accessed
    ];

const defaultBadQueries = {
    "aside.joblisting": 2,//  Stellenangebot
    "*[class='frame frame--quiz']": 2,//  Quiz
    "div.zg-wiegehtesihnen": 0, // Stimmungsumfrage
    "*[href='https://www.zeit.de/kaenguru-comics-marc-uwe-kling-bernd-kissel']": 3,//  Känguru comic
    "*[href='https://www.zeit.de/kaenguru-comics-marc-uwe-kling-bernd-kissel ']": 3,//  Känguru comic
    "aside#newsletter-signup-zplus-daily": 0,// Z+ Newsletter
    "aside#newsletter-signup-wochenmarkt": 2,// Wochenmarkt Newsletter
};

const badQueries = {...defaultBadQueries, ...customBadQueries};

document.addEventListener('DOMContentLoaded', () => {
    const sections = document.querySelectorAll("section");
    const articles = document.querySelectorAll("main article");
    const podcasts = document.querySelectorAll(["article.zon-teaser-standard.zon-teaser-standard--podcast","article.zon-teaser-wide.zon-teaser-wide--podcast"]);

    // remove sections
    for (const section of sections) {
        if (badSections[section.getAttribute("data-ct-context")]??false) {
            hideNode(section.parentElement);
        } else if (badHeadings[section.querySelector("h2")?.innerText]??false) {
           hideNode(section.parentElement);
        }
    }

    // remove articles
    for (const article of articles) {
        // remove zplus article
        if (zplusKeywords.includes(article.getAttribute("data-zplus"))) {
            hideNode(article);
        }

        // remove zett article
        if (article.getAttribute("data-unique-id")?.includes("zett")) {
            hideNode(article);
        }

        // remove Verlagsangebot
        if (article.querySelector("h3")?.innerText.includes("VERLAGSANGEBOT")) {
            hideNode(article);
        }
    }

    // remove podcasts
    podcasts.forEach(node => hideNode(node));

    // remove bad Queries
    Object.entries(badQueries).forEach(([query, num]) => hideParent(document.querySelector(query), num));

    // remove ad regions
    document.querySelectorAll("div.cp-region.cp-region--ad").forEach(node => hideNode(node));

    // remove sidebar Zeit+
    const sideBoxes = document.querySelectorAll("aside.topicbox");
    for (const sideBox of sideBoxes) {
        const text = sideBox?.childNodes[1]?.childNodes[1]?.innerText;
        if (/DAS BESTE|Z+/.test(text)) {
            hideNode(sideBox);
        }
    }
});

// remove paywall footer
const callback = function(mutationsList, observer) {
    for(const mutation of mutationsList) {
        for (const node of mutation.addedNodes) {
            try {
                if (node.className.includes("paywall-footer")) {
                    hideNode(node);
                }
            } catch {}
        }
    }
};

const observer = new MutationObserver(callback);
observer.observe(document.body, {childList: true});