S1论坛已读已阅提示

S1论坛已阅提示,ignore old thread on saraba1st

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         S1论坛已读已阅提示
// @namespace    http://www.saraba1st.com/
// @version      0.8
// @description  S1论坛已阅提示,ignore old thread on saraba1st
// @author       不能放过孩子
// @match        *.saraba1st.com/*
// @grant        none
// ==/UserScript==


(function () {
    'use strict';
    var prevUrl =localStorage.getItem("prevUrl");
    var prevUrlTime =localStorage.getItem("prevUrlTime"); ;
    var curUrl =  window.location.href;
    localStorage.setItem("prevUrl",curUrl);;
    localStorage.setItem("prevUrlTime",new Date().getTime());;
    
        var ignoreIdList = localStorage.getItem("ignoreIdList");
        ignoreIdList = ignoreIdList ? ignoreIdList : '';
        if (ignoreIdList && ignoreIdList.length / 1024 > 20) {//限制最大20kb后重置
            ignoreIdList = '';
        }
        ignoreIdList = ignoreIdList.replace(/\"/g, '');
        ignoreIdList = ignoreIdList.replace(/\\/g, '');
        if (ignoreIdList) {
            var ignore = ignoreIdList.split(',');
            if (typeof (ignore) !== 'object' || ignore.length <= 0) {
                ignore = [];
            }
        } else {
            var ignore = [];
        }
        var pushList = [];
        var threadlist = document.getElementsByClassName('xst');
        for (var index in threadlist) {
            var href = threadlist[index].href;
            if (href) {
                var threadMatch = href.match(/thread\-[0-9]+\-/g);
                var threadStr = threadMatch && threadMatch.length > 0 ? threadMatch[0] : '';
                var treadIdMatch = threadStr.match(/[0-9]+/g);
                var idStr = threadStr && threadStr.length > 0 ? treadIdMatch[0] : '';
                if (idStr) {
                    var patt = null;
                    var exist = false;
                    for (var i in ignore) {
                        if (typeof (ignore[i]) === 'string') {
                            var ignoreId = ignore[i];
                            patt = new RegExp(ignoreId, "g");
                            if (patt.test(idStr)) {
                                exist = true;
                            }
                        }
                    }
                    if (exist) {
                        threadlist[index].style.color = 'gray';
                    } else {
                        pushList.push(idStr);
                    }
                }
            }
        }
        var newIgnore = ignore.concat(pushList);
        var ignoreIdList = newIgnore.join(',');
    debugger;
    if( (prevUrl === undefined || prevUrl === null) || prevUrl === curUrl || new Date().getTime() - prevUrlTime > 24 * 60 * 60 * 100){
        //refresh 刷新、第一次加载的时候不启用
        return
    }else{
        localStorage.setItem("ignoreIdList", JSON.stringify(ignoreIdList));
    }
    
})();