Acfun评论标签

文章区评论楼层标签添加

目前为 2018-09-20 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Acfun评论标签
  3. // @version 1.0
  4. // @description 文章区评论楼层标签添加
  5. // @match http*://www.acfun.cn/a/ac*
  6. // @author 冲锋
  7. // @require http://code.jquery.com/jquery-1.6.1.min.js
  8. // @namespace https://gf.qytechs.cn/users/63731
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. var labelCss=$(`
  15. <style type="text/css">
  16. .labelBg {width:340px;
  17. height:95px;
  18. background-color:#fff;
  19. position:relative;
  20. padding:8px 20px ;
  21. border: 1px solid #d4d4d4;
  22. margin:auto auto;
  23. }
  24. .win-hint-ensure {
  25.  
  26. margin: 0;
  27. font-size: large;
  28. }
  29. .btn-close {
  30. position: absolute;
  31. right: 20px;
  32. top: 8px;
  33. cursor: pointer;
  34. }
  35. .labelP1 {
  36. width: 60px;
  37. height: 24px;
  38. line-height: 24px;
  39. text-align: center;
  40. background: #eee;
  41. border-radius: 3px;
  42. display:inline-block;
  43. }
  44. .labelInput{
  45. display:inline-block;
  46. }
  47. .btn-addlabel{
  48. background: #95ba12;
  49. border: 1px solid #95ba12;
  50. border-radius: 3px;
  51. height: 28px;
  52. color: #fff;
  53. padding: 0 8px;
  54. cursor: pointer;
  55. display:inline-block;
  56. margin-left:0px;
  57. }
  58. .btn-addlabel:hover{
  59. background-color:#77950e;
  60. }
  61. .labelMain{
  62.  
  63. margin:auto auto;
  64. }
  65. .nameLabel{
  66. /* color:rgb(240,20,20);*/
  67. /* margin-left:10px;*/
  68. padding-left:5px;
  69. padding-right:5px;
  70.  
  71. height: 22px;
  72. font-size: 12px;
  73. line-height: 22px;
  74. background-color: #4a8eff;
  75. text-align: center;
  76. border-radius: 4px;
  77. color: #fff;
  78. margin-left:10px;
  79. display:inline-block;
  80.  
  81. }
  82. .btn-addlabel2 {
  83. font-family: PingFangSC-Regular;
  84. font-size: 13px !important;
  85. color: #999 !important;
  86. }
  87. .tips{
  88. margin: 5px 0px;
  89. color: #999;
  90. }
  91. </style>
  92. `)
  93. $("head").append(labelCss)
  94. var labelWindow=$(`
  95. <div class="labelBg" >
  96. <span class="btn-close">
  97. <i class="icon icon-close"></i>
  98. </span>
  99. <div class="labelMain">
  100. <span class="win-hint-ensure labelUserId">人物ID</span>
  101. <div>
  102. <p class="labelP1">输入标签</p>
  103. <input class="labelInput"></input>
  104. <button class="btn-addlabel">添加标签</button>
  105. </div>
  106. <p class="tips">当输入框内容为空时,点击添加标签,则可以去除标签</p>
  107. </div>
  108.  
  109. </div>
  110. `)
  111. labelWindow.userId="0"
  112. //关闭按钮点击
  113. labelWindow.find(".btn-close").click(function(){
  114. labelWindow.hide();
  115. })
  116. var userData={};
  117.  
  118. if(localStorage.getItem("userLabelData")!=null){
  119. userData=JSON.parse(localStorage.getItem("userLabelData"));
  120. }
  121.  
  122. //添加按钮点击
  123. labelWindow.find(".btn-addlabel").click(function(e){
  124. if(labelWindow.userId!="0")
  125. {
  126. userData[labelWindow.userId]=labelWindow.find(".labelInput").val().replace(/\s+/g,"");
  127. if( userData[labelWindow.userId]==""){
  128. delete userData[labelWindow.userId];
  129. }
  130. localStorage.setItem("userLabelData",JSON.stringify(userData));
  131. upDataLabel();
  132. labelWindow.hide();
  133. }
  134. })
  135.  
  136.  
  137.  
  138.  
  139. //判断楼层加载成功
  140. var flag=setInterval(function(){
  141. if($(".item-comment-quote").length!=0){
  142. clearInterval(flag)
  143. labelButtonAdd();
  144. upDataLabel();
  145. }
  146.  
  147. },
  148. 500 )
  149.  
  150. //更新所有人物标签
  151. function upDataLabel(){
  152. //回复遍历
  153. $("[class='author-comment top'],[class='area-comment-right']").each(function(index,e){
  154. //判断回复者是否有标签
  155. if(userData[$(e).find(".name").attr("data-uid")]!=null){
  156. //判断是否已添加标签
  157. if($(e).find(".nameLabel").length!=0){
  158. $(e).find(".nameLabel").text(userData[$(e).find(".name").attr("data-uid")]);
  159. }else{
  160. var nameLabel=$("<a class='nameLabel'></a>")
  161. nameLabel.text(userData[$(e).find(".name").attr("data-uid")]);
  162. $(e).find(".name").after(nameLabel)
  163. }
  164. }
  165. else{
  166. $(e).find(".nameLabel").remove()
  167. }
  168. //按钮文字修改
  169. if($(e).find(".nameLabel").text()!=""){
  170. $(e).next().next().find(".btn-addlabel2").text("修改标签");
  171. }
  172. else{
  173. $(e).next().next().find(".btn-addlabel2").text("添加标签");
  174. }
  175. })
  176. }
  177. //为所有回复添加标签
  178. function labelButtonAdd(){
  179. //回复遍历
  180. $("[class='author-comment top'],[class='area-comment-right']").each(function(index,e){
  181.  
  182.  
  183. //添加标签按钮添加
  184. var label=$(`
  185. <a>添加标签</a>
  186. `)
  187. label.addClass("btn-addlabel2")
  188. $(e).next().next().find(".btn-quote").before(label)
  189.  
  190. //标签按钮点击
  191. label.click(function(){
  192. $(e).next().next().after(labelWindow)
  193. labelWindow.show();
  194. labelWindow.find(".labelInput").val("");
  195. labelWindow.find(".labelUserId").text($(e).find(".name").text());
  196. labelWindow.userId=$(e).find(".name").attr("data-uid")
  197. })
  198.  
  199.  
  200. })
  201.  
  202.  
  203. }
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址