拒绝跟风,理性思考

点击 ooxx 前隐藏当前 post 的 ooxx,目前只支持主楼,不支持吐槽

当前为 2020-06-26 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         拒绝跟风,理性思考
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  点击 ooxx 前隐藏当前 post 的 ooxx,目前只支持主楼,不支持吐槽
// @author       native
// @match        http://jandan.net/*
// @match        https://jandan.net/*
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    $(document).ready(function(){
        var allPost = $(".commentlist")[0];
        for(cur = allPost.firstElementChild; cur != null; cur = cur.nextElementSibling){
            if(cur.id.startsWith("comment-")){
                var likeSpan = cur.querySelector("div > div > div.jandan-vote > span.tucao-like-container > span");
                var unLikeSpan = cur.querySelector("div > div > div.jandan-vote > span.tucao-unlike-container > span");

                if(likeSpan == null){
                    likeSpan = cur.querySelector("div > div > div.jandan-vote > span:nth-child(2)");
                }
                if(unLikeSpan == null){
                    unLikeSpan = cur.querySelector("div > div > div.jandan-vote > span:nth-child(4)");
                }

                var commentOoxxEle = {
                    'id': cur.id, 'oo': parseInt(likeSpan.innerText), 'xx': parseInt(unLikeSpan.innerText)
                };
                GM_setValue(cur.id, commentOoxxEle);
                likeSpan.innerText = "...";
                unLikeSpan.innerText = "...";
            }
        }
        console.log(GM_getValue("comment-4617141"));

        ooxx_action = function xxx(c, e){
            var d = c.data("id");
            var b = c.data("type");
            var a = c.data("is_loading");
            var isClickOo = c[0].className == "comment-like like";
            var commentId = c[0].parentElement.parentElement.parentElement.parentElement.parentElement.id;
            if (a === true) {
                jandan_show_msg("数据加载中...请不要重复操作");
                return
            }
            c.data("is_loading", true);
            $.ajax({
                headers: {
                    "Request-Uri": window.location.href
                },
                type: "POST",
                dataType: "json",
                url: "/api/comment/vote",
                data: {
                    comment_id: d,
                    like_type: b,
                    data_type: e
                },
                success: function(i) {
                    c.data("is_loading", false);
                    if (i.error != 0) {
                        jandan_show_msg(i.msg);

                        // add code to show current ooxx
                        showOoxx(c, commentId, isClickOo, false);
                        return
                    }
                    var f = {
                        obj: c,
                        str: "+ 1",
                        startSize: "12px",
                        endSize: "30px",
                        interval: 800,
                        color: "#cd4450",
                        weight: "bold"
                    };
                    f.color = "#00f";
                    if (b === "pos") {
                        f.color = "#f00"
                    }
                    $("body").append('<span class="plus-num" id="plus-' + d + '">' + f.str + "</span>");
                    var h = $("#plus-" + d);
                    var k = f.obj.offset().left;
                    var j = f.obj.offset().top - f.obj.height() + 5;
                    h.css({
                        position: "absolute",
                        left: k + "px",
                        top: j + "px",
                        "z-index": 9999,
                        "font-size": f.startSize,
                        "line-height": f.endSize,
                        color: f.color,
                        "font-weight": f.weight
                    });
                    var g = c.next("span");
                    // add code to show current ooxx
                    showOoxx(c, commentId, isClickOo, true);
                    h.velocity({
                        opacity: "0",
                        top: (j - 20) + "px"
                    }, f.interval, function() {
                        h.remove()
                    })
                },
                error: function() {
                    c.data("is_loading", false)

                    // add code to show current ooxx
                    showOoxx(c, commentId, isClickOo, false);
                }
            })
        };

        function showOoxx(c, commentId, isClickOo, success){
            var ooxx = GM_getValue(commentId);
            var addend = success ? 1 : 0;

            isClickOo ? ooxx["oo"] += addend: ooxx["xx"] + addend;
            GM_setValue(commentId, ooxx);

            c[0].parentElement.parentElement.querySelector("span.tucao-like-container > span").innerText = ooxx["oo"];
            c[0].parentElement.parentElement.querySelector("span.tucao-unlike-container > span").innerText = ooxx["xx"];
        }
    });
})();