Acfun评论标签

文章区评论楼层标签添加

目前為 2018-09-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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")
                            })


                        })


                    }






})();