Multi Forum Read Marker (Soutong + TT1069)

标记已访问的帖子标题,支持搜同网和 TT1069 论坛,在任何排序方式下生效,标记放文字标题左边。

Versione datata 08/06/2025. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Multi Forum Read Marker (Soutong + TT1069)
// @namespace    https://felixchristian.dev/userscripts/multi-forum-read-marker
// @version      1.2.0
// @description  标记已访问的帖子标题,支持搜同网和 TT1069 论坛,在任何排序方式下生效,标记放文字标题左边。
// @author       FelixChristian
// @license      MIT
// @match        https://soutong.men/forum.php?mod=forumdisplay&fid=*
// @match        https://soutong.men/forum.php?mod=viewthread&tid=*
// @match        https://www.tt1069.com/bbs/thread-*-*-*.html
// @match        https://www.tt1069.com/bbs/forum-*-*.html
// @match        https://www.tt1069.com/bbs/forum.php?mod=forumdisplay&fid=*
// @match        https://www.tt1069.com/bbs/forum.php?mod=forumdisplay&fid=*&*
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function () {
    'use strict';

    const HOST = location.hostname;
    const isSoutong = HOST.includes('soutong.men');
    const isTT1069 = HOST.includes('tt1069.com');
    const STORAGE_KEY = 'visitedTids';

    let visitedTids = GM_getValue(STORAGE_KEY, {});

    // 获取当前帖子 TID
    function getCurrentTid() {
        if (isSoutong) {
            const url = new URL(location.href);
            return url.searchParams.get('tid');
        }
        if (isTT1069) {
            const match = location.pathname.match(/thread-(\d+)-/);
            return match ? match[1] : null;
        }
        return null;
    }

    // 记录访问
    function recordTidVisit(tid) {
        if (tid) {
            visitedTids[tid] = Date.now();
            GM_setValue(STORAGE_KEY, visitedTids);
        }
    }

    // 标记已读帖子标题
    function markReadThreads() {
        let threadLinks = [];

        if (isSoutong) {
            threadLinks = document.querySelectorAll('a.xst');
        } else if (isTT1069) {
            threadLinks = Array.from(document.querySelectorAll('a.xst')).filter(link =>
                link.href.includes('thread-') || link.href.includes('viewthread')
            );
        }

        threadLinks.forEach(link => {
            let tid;

            if (isSoutong) {
                try {
                    const fullUrl = new URL(link.href, location.origin);
                    tid = fullUrl.searchParams.get('tid');
                } catch (e) { return; }
            } else if (isTT1069) {
                const match = link.href.match(/thread-(\d+)-/);
                tid = match ? match[1] : null;
            }

            if (tid && visitedTids[tid] && !link.dataset.markedVisited) {
                const tag = document.createElement('span');
                tag.textContent = '[已读] ';
                tag.style.color = 'red';
                tag.style.fontWeight = 'bold';
                tag.style.marginRight = '4px';
                link.insertBefore(tag, link.firstChild);
                link.dataset.markedVisited = 'true';
            }
        });
    }

    // 判断页面类型
    const isViewThread =
        (isSoutong && location.href.includes('mod=viewthread')) ||
        (isTT1069 && /thread-\d+-\d+-\d+\.html/.test(location.pathname));

    const isForumDisplay =
        (isSoutong && location.href.includes('mod=forumdisplay')) ||
        (isTT1069 &&
            ((location.pathname.endsWith('forum.php') && location.search.includes('mod=forumdisplay')) ||
            /forum-\d+-\d+\.html/.test(location.pathname)));

    // 当前是帖子详情页 => 记录访问
    if (isViewThread) {
        const tid = getCurrentTid();
        recordTidVisit(tid);
    }

    // 当前是论坛列表页 => 执行标记
    if (isForumDisplay) {
        window.addEventListener('load', markReadThreads);
        const observer = new MutationObserver(markReadThreads);
        observer.observe(document.body, { childList: true, subtree: true });
    }
})();