Closed W4J1e closed 8 months ago
最近不会搞,欢迎提交pull request
可以考虑下这个过渡方案:在评论加载完成时,替换所有外链到知乎的中转页:
twikoo.init({
......,
onCommentLoaded: function () {
console.log('评论加载完成');
document.querySelectorAll('a').forEach(function(aEl){
if(!aEl.href.startsWith(window.location.origin)){
aEl.href='https://link.zhihu.com/?target='+encodeURI(aEl.href);
}
});
}
});
可以考虑下这个过渡方案:在评论加载完成时,替换所有外链到知乎的中转页:
twikoo.init({ ......, onCommentLoaded: function () { console.log('评论加载完成'); document.querySelectorAll('a').forEach(function(aEl){ if(!aEl.href.startsWith(window.location.origin)){ aEl.href='https://link.zhihu.com/?target='+encodeURI(aEl.href); } }); } });
您好,请问这段代码应该添加到什么位置呀?
@willow-god twikoo 初始化的地方。 在主题源码里搜 twikoo.init 一般能找到相应的位置。
@willow-god twikoo 初始化的地方。 在主题源码里搜 twikoo.init 一般能找到相应的位置。
好的,谢谢您的代码,我已经找到位置并实现了
@imaegoo 谢谢开发者的代码,我也用上了。
今天在龙笑天下的博客看到这回事:
考虑到有少数博主做博客缺乏恒心,做不久就关站,域名被其他人注册后做违规网站,导致该博主之前在其他博客留下的评论变相成为了违规站点的外链。
2024.04.21 更新
使用下面开发者提供的代码时,建议把
document.querySelectorAll('a').forEach(function(aEl){
修改为
document.querySelectorAll('.tk-comments-container a').forEach(function(aEl){
原因:1.知乎跳转页会过滤掉链接
&
后面的参数,对于某些需要携带参数的场景不友好,比如某些cps
链接;2. 如果你在博客的footer
或者sidebar
之类的地方填写了备案信息并做了跳转,在引入了 Twikoo 的页面会导致这些链接没有直接指向需要指向的地方,通常情况下首页不受影响;