Greasy Fork

Customize Zeit Online

Entferne unerwünschte Artikel/Abschnitte aus Zeit Online

目前为 2020-12-29 提交的版本。查看 最新版本

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

'use strict';

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

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

// customBadSections["newsticker"] = true;
// customBadHeadings["Video"] = true;

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

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

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

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

// remove sections
const defaultBadSections = {
    "wochenmarkt": true,// Wochenmarkt
    "headed-zplus": true,// zplus
    "headed-zett": true,//  zett
    "headed-brandeins": false,// brand eins
    "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 sections = document.querySelectorAll("section");

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 other articles
const articles = document.querySelectorAll("main article");

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

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

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

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

// remove Stellenangebot
hideNode(document.querySelector("aside.joblisting")?.parentElement?.parentElement);

// remove Quiz
hideNode(document.querySelector("*[class='frame frame--quiz']")?.parentElement?.parentElement);

// remove Stimmung Umfrage
hideNode(document.querySelector("*[class='zg-wiegehtsesihnen-appwrapper']")?.parentElement);

// remove Stimmung Umfrage
hideNode(document.querySelector("*[class='zg-wiegehtsesihnen-appwrapper']")?.parentElement);

// remove sidebar Zeit+
const sideBox = document.querySelector("aside.topicbox");
if (sideBox?.childNodes[1]?.childNodes[1]?.innerText == "DAS BESTE AUS Z+") {
    hideNode(sideBox);
}

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

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