chrome浏览器,有时候收藏了一个帖子,后面会发现重复收藏的情况。
原来是收藏了子帖(点击子帖会更新url)
怎么避免重复收藏呢?
大家用的是什么办法?
这个问题,我记得
解决方案是 Edge 的这个:

你这个只是浏览记录啊,楼主要的是收藏夹防重复
别使用浏览器的收藏夹,用论坛自带的收藏功能
1 个赞
Firefox没这个功能
而且我觉得这属于论坛的bug呀,有啥必要每个楼层都产生一个历史记录嘞? ![]()
居然看差了…
不好意思,弄错了。
你可以试试论坛自带的收藏功能啊,还能提醒
有这个功能吗?怎操作呢
点击帖子下面的书签按钮就可以啦,手机版要先点三个点,让按钮显示出来。
1 个赞
这里
2 个赞
还有个办法,上脚本:
history.replaceStateRaw ||= history.replaceState;
history.replaceState = function(state, title, url) {
//console.log("Intercepted replaceState. New URL: " + url);
var idx = url.indexOf("topic/");
if(idx>0) {
var idx1 = url.indexOf("/", idx+6);
if(idx1>0) {
var idx2 = url.indexOf("?", idx+1);
if(idx2<0) idx2 = url.length;
console.log(url.slice(idx+6, idx2), url.slice(idx1+1, idx2))
var num2 = url.slice(idx1+1, idx2);// 这里只检查第二个数字。
if(num2.length && !isNaN(0-num2)) {
console.log("已拦截: " + url);
return;
}
}
}
history.replaceStateRaw.apply(this, arguments);
};
原理:禁止更新url为 topic/数字/数字
使用方法:下载油猴或其他脚本扩展,应用此脚本到所有网页。
然而这样会带来一个问题:如果跟帖数量很多,那么刷新时,无法恢复上次阅读的位置。
可用 sessionStorage 存储楼层数。然后将logo的链接改成 topic/数字/数字。
右击logo恢复。
大型脚本制作:
// ==UserScript==
// @run-at document-start
// ==/UserScript==
var num2;
var logo;
function gtp(c, d, max) {
var p = d||document;
if(!max) max=99999;
while(p) {
if(p.tagName==c) return p;
p = p.parentNode;
if(--max<=0) return null;
}
}
function testTNN(url) {
var idx = url.indexOf("topic/");
if(idx>0) {
var idx1 = url.indexOf("/", idx+6);
if(idx1>0) {
var idx2 = url.indexOf("?", idx+1);
if(idx2<0) idx2 = url.length;
//console.log(url.slice(idx+6, idx2), url.slice(idx1+1, idx2))
num2 = url.slice(idx1+1, idx2);// 这里只检查第二个数字。
if(num2.length && !isNaN(0-num2)) {
return 2;
}
}
return 1; // 只有一个数字
}
return 0;
}
var flag = testTNN(location.href);
if(flag===1) {
history.replaceStateRaw ||= history.replaceState;
history.replaceState = function(state, title, url) {
// console.log("Intercepted replaceState. New URL: " + url);
if(testTNN(url)===2) {
console.log("已拦截: " + url);
setForumLoca(num2);
if(parseInt(num2)>=9) {
sessionStorage.setItem('lastPost', location.pathname)
sessionStorage.setItem('lastPos', num2)
console.log("已保存楼层数: " + num2);
}
return;
}
history.replaceStateRaw.apply(this, arguments);
};
num2 = parseInt(sessionStorage.getItem('lastPos'))
if(!isNaN(num2) && location.pathname==sessionStorage.getItem('lastPost')) {
// 启动时检查一次
let itv = setInterval(_=>{
if(setForumLoca(num2, itv)) {
if(typeof toast=='function') toast(num2);
gtp("A", logo, 9).oncontextmenu = e=>{
if(!e.altKey) {
history.replaceState = history.replaceStateRaw;
if(typeof toast=='function') toast("不装了");
history.replaceState(0,0,location.pathname+"/"+num2)
e.preventDefault()
}
}
// history.replaceStateRaw(0,0,location.pathname+"/"+num2)
}
}, 1000)
}
function setForumLoca(num2, itv) { // 修改logo地址
var tgt = "//"+location.host+location.pathname+"/"+num2;
logo = unsafeWindow['site-logo'];
console.log("保存的楼层: https:"+tgt, logo);
if(logo) {
if(itv) clearInterval(itv);
gtp("A", logo, 9).href = tgt;
return 1;
}
// return tgt;
}
}
1 个赞
这么硬核么
感谢老哥帮助解决小众论坛的问题
@Qingwa 得谢谢人家 ![]()
HI 大佬要不要把脚本发布到 Greasy Fork?