dongzhuo5425 2013-06-30 18:18
浏览 81
已采纳

Disqus评论计数多个页面

The following code is to get Disqus counts of comments for multiple pages.

var DISQUSWIDGETS;

if (typeof DISQUSWIDGETS != 'undefined') {
    DISQUSWIDGETS.displayCount({
        "showReactions":true,
        "text":{
            "and":"and",
            "reactions":{
                "zero":"0 Reactions",
                "multiple":"{num} Reactions",
                "one":"1 Reaction"},
            "comments":{
                "zero":"0 Comments",
                "multiple":"{num} Comments",
                "one":"1 Comment"
            }
        },
        "counts":[
            {"reactions":0,"uid":1,"comments":2},
            {"reactions":0,"uid":2,"comments":5},
            {"reactions":0,"uid":3,"comments":9}
        ]
    });
}

I want to get just the number of comments example from here:

{"reactions":0,"uid":1,"comments":2} the number of comments should be 2.

Is there any javascript code which will get just the comments?

  • 写回答

1条回答 默认 最新

  • dongzhou5344 2013-06-30 18:29
    关注

    If you are able to rewrite this as such:

    var DISQUSWIDGETS;
    
    if (typeof DISQUSWIDGETS != 'undefined') {
        var disqus_options = {
            "showReactions":true,
            "text":{
                "and":"and",
                "reactions":{
                    "zero":"0 Reactions",
                    "multiple":"{num} Reactions",
                    "one":"1 Reaction"},
                "comments":{
                    "zero":"0 Comments",
                    "multiple":"{num} Comments",
                    "one":"1 Comment"
                }
            },
            "counts":[
                {"reactions":0,"uid":1,"comments":2},
                {"reactions":0,"uid":2,"comments":5},
                {"reactions":0,"uid":3,"comments":9}
            ]
        };
        DISQUSWIDGETS.displayCount(disqus_options);
    }
    

    Then you will be able to access the count like this:

    disqus_options.counts[0].comments
    

    which has the value 2 in this case.


    edit

    To filter by id, in this case id == 3.

    var counts_with_id = $.grep(disqus_options.counts, function(count) {
        return (count.uid == 3);
    });
    if (counts_with_id.length) // the id exists
        counts_with_id[0].comments // has value 9
    else
        the id does not exist in the disqus_options.
    

    edit

    You can "hack" the displayCount method:

    // Load the disqus plugin which contains the DISQUSWIDGETS.displayCount method.
    
    // Change what DISQUSWIDGETS.displayCount does.
    var actualDisplayCount = DISQUSWIDGETS.displayCount;
    DISQUSWIDGETS.displayCount = function(options) {
        // do things with options
        return actualDisplayCount(options);
    };
    
    // Now load the source from http://forum.disqus.com/count-data.js?q=1&1=2,http://www.website.com&2=2
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改