Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

建议增加功能:多长时间以前的评论不再显示链接 #647

Closed
W4J1e opened this issue Jan 7, 2024 · 6 comments
Closed

建议增加功能:多长时间以前的评论不再显示链接 #647

W4J1e opened this issue Jan 7, 2024 · 6 comments

Comments

@W4J1e
Copy link
Contributor

W4J1e commented Jan 7, 2024

今天在龙笑天下的博客看到这回事

image

考虑到有少数博主做博客缺乏恒心,做不久就关站,域名被其他人注册后做违规网站,导致该博主之前在其他博客留下的评论变相成为了违规站点的外链。

2024.04.21 更新

使用下面开发者提供的代码时,建议把

document.querySelectorAll('a').forEach(function(aEl){

修改为

document.querySelectorAll('.tk-comments-container a').forEach(function(aEl){

原因:1.知乎跳转页会过滤掉链接 & 后面的参数,对于某些需要携带参数的场景不友好,比如某些 cps 链接;2. 如果你在博客的 footer 或者 sidebar之类的地方填写了备案信息并做了跳转,在引入了 Twikoo 的页面会导致这些链接没有直接指向需要指向的地方,通常情况下首页不受影响;

@imaegoo
Copy link
Member

imaegoo commented Jan 8, 2024

最近不会搞,欢迎提交pull request

@imaegoo
Copy link
Member

imaegoo commented Jan 8, 2024

可以考虑下这个过渡方案:在评论加载完成时,替换所有外链到知乎的中转页:

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);
      }
    });
  }
});

@W4J1e W4J1e closed this as completed Jan 21, 2024
@willow-god
Copy link

可以考虑下这个过渡方案:在评论加载完成时,替换所有外链到知乎的中转页:

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);
      }
    });
  }
});

您好,请问这段代码应该添加到什么位置呀?

@imaegoo
Copy link
Member

imaegoo commented Mar 22, 2024

@willow-god
twikoo 初始化的地方。
在主题源码里搜 twikoo.init 一般能找到相应的位置。

@willow-god
Copy link

@willow-god twikoo 初始化的地方。 在主题源码里搜 twikoo.init 一般能找到相应的位置。

好的,谢谢您的代码,我已经找到位置并实现了

@W4J1e
Copy link
Contributor Author

W4J1e commented Mar 22, 2024

@imaegoo 谢谢开发者的代码,我也用上了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants