Greasy Fork

Customize Zeit Online

Entferne unerwünschte Artikel/Abschnitte aus Zeit Online

目前为 2021-02-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         Customize Zeit Online
// @namespace    https://greasyfork.org/en/users/689160-georg-vogt
// @version      2.4.3
// @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
    "*[class='zg-wiegehtsesihnen-appwrapper']": 1,//  Stimmungsumfrage
    "*[class='zg-wiegehtsesihnen-survey']": 1,//  Stimmungsumfrage mobile
    "*[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
};

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 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});