Multi Forum Read Marker (Soutong + TT1069)

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

Ajankohdalta 8.6.2025. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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