Shit Journal Title (Fixed)

Replace document title by actual article title.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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

})();