// ==UserScript== // @name 记录上次查看时间 // @version 0.0.1 // @include https://www.mcbbs.net/* // @author xmdhs // @description 记录上次查看时间。 // @namespace https://xmdhs.top // @downloadURL none // ==/UserScript== (function () { let tid; try { tid = document.querySelector("#pt > div > a:nth-child(9)").href.match(/thread-([0-9]{1,10})-1-1.html/)[1] } catch { } if (tid > 0) { let date = localStorage.getItem("lastview") if (date == null) { date = {} } else { date = JSON.parse(date) } date[tid] = new Date().getTime() let tempdate = {} if (date.length > 1000){ let a = 0; for (let i in date) { a = a + 1 if (a < 3) { continue; } tempdate[i] = date[i] } date = tempdate } localStorage.setItem("lastview", JSON.stringify(date)) } else { let date = localStorage.getItem("lastview") date = JSON.parse(date) jq(".s.xst").each(function () { let link = jq(this).attr("href") let tid = link.match(/thread-([0-9]{1,10})-1-1.html/)[1] let atime = date[tid] if (atime > 0) { jq(this).append(' [' + time(atime) + ']') } }) } })(); // https://segmentfault.com/a/1190000015992232 function time(time = +new Date()) { var date = new Date(time + 8 * 3600 * 1000); // 增加8小时 return date.toJSON().substr(0, 19).replace('T', ' '); }