jQuery脚本来监视disqus评论添加?

| 我想编写一个小脚本来监视页面上添加的disqus注释,并在添加新注释时触发一些通知回调。 对我而言,最简单的方法是定期监视#dsq-comments div的内容,并在其html内容更改时触发回调。 虽然这行得通,但我想知道是否有更清洁的方法? 编辑:正如@Pekka所建议的那样,我在页面上实现了onNewComment回调,它工作得很漂亮。这是我关于将Disqus集成到我的站点的主要问题之一,现在我有了一个可行的解决方案。
function disqus_config() {
  this.callbacks.onNewComment = [function() {
       $.get(\"/notifications/newcomment?...\", function(data) {
       });
  }];
}
    
已邀请:
似乎有一个
onNewComment
回调。请参阅如何在自己的分析工具中捕获Disqus评论活动? 这篇博客文章在记录方面做得很好。     
可以使用以下方法通过回调捕获Disqus评论活动:
function disqus_config() {
  this.callbacks.onNewComment = [function() { trackComment(); }];
}
您将在哪里替换trackComment();根据您自己的功能。 这是一个使用JavaScript动态加载Disqus评论的示例,您可以在其中找到添加新评论时将触发的discus_config函数。
var loadDisqus = function() {
  window.disqus_identifier = \'your thread id\';
  window.disqus_shortname = \'disqus_shortname\';
  window.disqus_url = \'http://your_domain.com/path\';
  window.disqus_title =\'page title\';
  window.disqus_config = function() {
    this.callbacks.onNewComment = [function() { myFunction() }];
  };

  (function() {
    var dsq = document.createElement(\'script\');
    dsq.type = \'text/javascript\';
    dsq.async = true;
    dsq.src = \'//\' + disqus_shortname + \'.disqus.com/embed.js\';
    (document.getElementsByTagName(\'head\')[0] ||
      document.getElementsByTagName(\'body\')[0]).appendChild(dsq);
  })();

};
    

要回复问题请先登录注册