Acfun评论标签

文章区评论楼层标签添加

当前为 2018-09-20 提交的版本,查看 最新版本

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Acfun评论标签
// @version     1.0
// @description 文章区评论楼层标签添加
// @match       http*://www.acfun.cn/a/ac*
// @author      冲锋
// @require        http://code.jquery.com/jquery-1.6.1.min.js
// @namespace https://greasyfork.org/users/63731
// ==/UserScript==

(function() {
    'use strict';

    var labelCss=$(`
<style type="text/css">
.labelBg {width:340px;
height:95px;
background-color:#fff;
position:relative;
padding:8px 20px ;
 border: 1px solid #d4d4d4;
margin:auto auto;
}
.win-hint-ensure {

    margin: 0;
    font-size: large;
}
 .btn-close {
    position: absolute;
    right: 20px;
    top: 8px;
    cursor: pointer;
}
.labelP1 {
    width: 60px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    background: #eee;
    border-radius: 3px;
 display:inline-block;
}
.labelInput{
   display:inline-block;
}
.btn-addlabel{
    background: #95ba12;
    border: 1px solid #95ba12;
    border-radius: 3px;
    height: 28px;
    color: #fff;
    padding: 0 8px;
    cursor: pointer;
 display:inline-block;
margin-left:0px;
}
.btn-addlabel:hover{
background-color:#77950e;
}
.labelMain{

margin:auto auto;
}
.nameLabel{
  /*  color:rgb(240,20,20);*/
  /*  margin-left:10px;*/
  padding-left:5px;
    padding-right:5px;

    height: 22px;
    font-size: 12px;
    line-height: 22px;
    background-color: #4a8eff;
    text-align: center;
    border-radius: 4px;
    color: #fff;
   margin-left:10px;
 display:inline-block;

}
.btn-addlabel2 {
    font-family: PingFangSC-Regular;
    font-size: 13px !important;
    color: #999 !important;
}
.tips{
    margin: 5px 0px;
    color: #999;
}
</style>
`)
    $("head").append(labelCss)
    var labelWindow=$(`
                       <div class="labelBg" >
<span class="btn-close">
<i class="icon icon-close"></i>
</span>
<div class="labelMain">
<span class="win-hint-ensure labelUserId">人物ID</span>
<div>
<p class="labelP1">输入标签</p>
<input class="labelInput"></input>
<button class="btn-addlabel">添加标签</button>
</div>
<p class="tips">当输入框内容为空时,点击添加标签,则可以去除标签</p>
</div>

</div>
                      `)
    labelWindow.userId="0"
    //关闭按钮点击
    labelWindow.find(".btn-close").click(function(){
        labelWindow.hide();
       })
    var userData={};

    if(localStorage.getItem("userLabelData")!=null){
         userData=JSON.parse(localStorage.getItem("userLabelData"));
    }

                            //添加按钮点击
                                labelWindow.find(".btn-addlabel").click(function(e){
                                    if(labelWindow.userId!="0")
                                    {
                                            userData[labelWindow.userId]=labelWindow.find(".labelInput").val().replace(/\s+/g,"");
                                            if( userData[labelWindow.userId]==""){
                                                delete userData[labelWindow.userId];
                                            }
                                            localStorage.setItem("userLabelData",JSON.stringify(userData));
                                            upDataLabel();
                                             labelWindow.hide();
                                    }
                                })




         //判断楼层加载成功
    var flag=setInterval(function(){
                    if($(".item-comment-quote").length!=0){
                        clearInterval(flag)
                        labelButtonAdd();
                        upDataLabel();
                    }

    },
             500 )

    //更新所有人物标签
function upDataLabel(){
     //回复遍历
                    $("[class='author-comment top'],[class='area-comment-right']").each(function(index,e){
                        //判断回复者是否有标签
                            if(userData[$(e).find(".name").attr("data-uid")]!=null){
                                //判断是否已添加标签
                                   if($(e).find(".nameLabel").length!=0){
                                                    $(e).find(".nameLabel").text(userData[$(e).find(".name").attr("data-uid")]);
                                            }else{
                                               var nameLabel=$("<a class='nameLabel'></a>")
                                               nameLabel.text(userData[$(e).find(".name").attr("data-uid")]);
                                                $(e).find(".name").after(nameLabel)
                                            }
                            }
                        else{
                             $(e).find(".nameLabel").remove()
                        }
                        //按钮文字修改
                                if($(e).find(".nameLabel").text()!=""){
                                     $(e).next().next().find(".btn-addlabel2").text("修改标签");
                                }
                                else{
                                     $(e).next().next().find(".btn-addlabel2").text("添加标签");
                                }
                            })
}
 //为所有回复添加标签
function labelButtonAdd(){
                              //回复遍历
                        $("[class='author-comment top'],[class='area-comment-right']").each(function(index,e){


                            //添加标签按钮添加
                             var label=$(`
            <a>添加标签</a>
                            `)
                             label.addClass("btn-addlabel2")
                            $(e).next().next().find(".btn-quote").before(label)

                            //标签按钮点击
                            label.click(function(){
                                $(e).next().next().after(labelWindow)
                                labelWindow.show();
                                labelWindow.find(".labelInput").val("");
                                labelWindow.find(".labelUserId").text($(e).find(".name").text());
                                labelWindow.userId=$(e).find(".name").attr("data-uid")
                            })


                        })


                    }






})();