North-Plus MarkRead

Mark read thread.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         North-Plus MarkRead
// @namespace    https://github.com/sssssssl
// @version      0.1
// @description  Mark read thread.
// @author       sl
// @match        https://*.white-plus.net/thread.php?fid-*
// @match        https://*.south-plus.net/thread.php?fid-*
// @match        https://*.imoutolove.me/thread.php?fid-*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    const CLS_THREAD = '.tr3.t_one';
    const TD_ID_PAT = /td_(\d+)/;
    const KEY_VISITED_TD = 'visited_id';
    const CLS_UNREAD = 'np-unread';

    const NP_UNREAD_STYLE = `
    <style>
    .np-unread {
        font-weight : bold;
    }
    </style>`;

    let threads = document.querySelectorAll(CLS_THREAD);

    let visitedThreads = GM_getValue(KEY_VISITED_TD);
    if(!visitedThreads) {
        visitedThreads = [];
    }

    document.head.insertAdjacentHTML('beforeend', NP_UNREAD_STYLE);

    threads.forEach((elem) => {
        let _td = elem.querySelector('td[id]');
        if(_td) {
            let m = TD_ID_PAT.exec(_td.id);
            if(m) {
                let id = parseInt(m[1]);
                if(visitedThreads.indexOf(id) == -1) {
                    let title = _td.querySelector('h3 a');
                    title.classList.add(CLS_UNREAD);

                    _td.onclick = () => {
                        let idx = visitedThreads.indexOf(id);
                        if(idx == -1) {
                            visitedThreads.push(id);
                            GM_setValue(KEY_VISITED_TD, visitedThreads);
                            console.log(`${id} clicked.`);
                        }
                    };
                }
            }
        }
    });

    // Your code here...
})();