您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
记录上次查看时间。
当前为
// ==UserScript== // @name 记录上次查看时间 // @version 0.1.1 // @include https://www.mcbbs.net/* // @author xmdhs // @description 记录上次查看时间。 // @namespace https://xmdhs.top // ==/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 now = new Date().getTime() for (let i in date) { if ((now - date[i]) > 432000000) { 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-[0-9]{1,10}.html/) let atime if (tid != null && tid.length >= 2) { tid = tid[1] atime = date[tid] } else { let b = new URLSearchParams(link) let tidtemp = b.get("tid") if (tidtemp != "") { atime = date[tidtemp] } } if (atime > 0) { jq(this).prepend('<font color="#000000"><b>[' + diffTime(new Date(atime), new Date()) + '] </b></font>') } }) } })(); // https://www.jianshu.com/p/bdda96a1dcd8 function diffTime(startDate, endDate) { var diff = endDate.getTime() - startDate;//.getTime();//时间差的毫秒数 //计算出相差天数 var days = Math.floor(diff / (24 * 3600 * 1000)); //计算出小时数 var leave1 = diff % (24 * 3600 * 1000); //计算天数后剩余的毫秒数 var hours = Math.floor(leave1 / (3600 * 1000)); //计算相差分钟数 var leave2 = leave1 % (3600 * 1000); //计算小时数后剩余的毫秒数 var minutes = Math.floor(leave2 / (60 * 1000)); //计算相差秒数 var leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数 var seconds = Math.round(leave3 / 1000); var returnStr = seconds + "秒前"; if (minutes > 0) { returnStr = minutes + "分钟前";//+ returnStr; } if (hours > 0) { returnStr = hours + "小时前";// + returnStr; } if (days > 0) { returnStr = days + "天前";//+ returnStr; } return returnStr; }