Shit Journal Title (Fixed)

Replace document title by actual article title.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

Advertisement:

// ==UserScript==
// @name         Shit Journal Title (Fixed)
// @description  Replace document title by actual article title.
// @match        *://shitjournal.org/*
// @icon         https://shitjournal.org/LOGO2.png
// @license      Unlicense
// @version      0.1.0
// @run-at       document-idle
// @namespace https://greasyfork.org/users/789884
// ==/UserScript==

(function () {
    'use strict';

    const originalTitle = document.title;

    function updateTitle() {
        // 更通用的选择器
        let node = document.querySelector("h1");

        if (!node) {
            node = document.querySelector("main h2, article h2");
        }

        if (node && node.innerText.trim()) {
            document.title = node.innerText.trim();
        } else {
            document.title = originalTitle;
        }
    }

    // 初次执行
    updateTitle();

    // 监听 DOM 变化(适配 React / Vue)
    const observer = new MutationObserver(() => {
        updateTitle();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();