User Highlighting

Highlight users in tickers.

目前为 2024-08-27 提交的版本。查看 最新版本

// ==UserScript==
// @name         User Highlighting
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Highlight users in tickers.
// @author       Winston Smith
// @license      MIT
// @match        https://www.derstandard.at/jetzt/livebericht/*
// @icon         https://www.google.com/s2/favicons?domain=derstandard.at
// @grant        none
// ==/UserScript==

// Background color for highlighted users.
const COLOR = "lightblue";

(function() {
    'use strict';

    let isDelayed = false;

    // Executed on DOM changes and limit the update rate.
    function onDomChange() {
        if (!isDelayed) {
            highlightYourself();

            isDelayed = true;
            setTimeout(() => {
                isDelayed = false;
            }, 2500);

        }
    }

    const observer = new MutationObserver(onDomChange);
    const targetNode = document.body;
    const config = { childList: true, subtree: true };
    observer.observe(targetNode, config);

    function highlightYourself() {
        let legacyID = JSON.parse(localStorage.userdata).value.communityIdentityId;
        let xpath = `//a[contains(@href, '/legacy/${legacyID}') and contains(@class, 'upost-usercontainer')]/..`;
        let nodes = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

        for (let i = 0; i < nodes.snapshotLength; i++) {
            const element = nodes.snapshotItem(i);
            element.style.backgroundColor = COLOR;
        }
    }
})();