Shit Journal Title (Fixed)

Replace document title by actual article title.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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

})();