Acfun评论标签

文章区评论楼层标签添加

  1. // ==UserScript==
  2. // @name Acfun评论标签
  3. // @version 2.2
  4. // @description 文章区评论楼层标签添加
  5. // @match http*://www.acfun.cn/a/ac*
  6.  
  7. // @author 冲锋
  8. // @require http://code.jquery.com/jquery-1.7.1.min.js
  9. // @namespace https://gf.qytechs.cn/users/63731
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. console.log("ACFUN评论标签 启动");
  15. var labelCss=$(`
  16. <style type="text/css">
  17. .labelBg {width:373px;
  18.  
  19. background-color:#fff;
  20. position:relative;
  21. padding:8px 20px !important;
  22. border: 1px solid #d4d4d4;
  23. margin:auto auto !important;
  24. margin-top:10px !important;
  25. }
  26. .win-hint-ensure {
  27.  
  28.  
  29. margin: 0 !important;
  30. font-size: large;
  31. }
  32. .btn-close {
  33. position: absolute;
  34. right: 15px;
  35. top: 8px;
  36. cursor: pointer;
  37. }
  38. .labelP1 {
  39. padding:0 8px !important;
  40. height: 28px;
  41. line-height: 28px;
  42. text-align: center;
  43. background: #eee;
  44. border-radius: 3px;
  45. display:inline-block;
  46. font-size:14px;
  47. font-color:#999;
  48. }
  49. .labelInput{
  50. width:180px;
  51. height:24px;
  52. display:inline-block;
  53. border: 1px solid rgb(212,212,212);
  54. border-radius: 3px;
  55. }
  56. .btn-addlabel{
  57. background: #fd4c5c;
  58. border: 1px solid #fd4c5c;
  59. border-radius: 3px;
  60. height: 28px;
  61. color: #fff;
  62. padding: 0 8px !important;
  63. cursor: pointer;
  64. display:inline-block;
  65. margin-left:0px !important;
  66. }
  67. .btn-addlabel:hover{
  68. background-color:rgb(255,53,7);
  69. }
  70. .labelMain{
  71. margin:auto auto !important;
  72. }
  73. .nameLabel{
  74. /* color:rgb(240,20,20);*/
  75. /* margin-left:10px;*/
  76. padding-left:5px !important;
  77. padding-right:5px !important;
  78. color:#fff !important;
  79.  
  80. height: 22px;
  81. font-size: 12px;
  82. line-height: 22px;
  83. background-color: #4a8eff;
  84. text-align: center;
  85. border-radius: 4px;
  86. color: #fff;
  87. margin-left:10px !important;
  88. display:inline-block;
  89.  
  90. }
  91. .btn-addlabel2 {
  92.  
  93. font-size: 12px !important;
  94. color: #999 !important;
  95. }
  96. .btn-addlabel3 {
  97.  
  98. font-size: 12px !important;
  99. color: #999 !important;
  100. }
  101. .tips{
  102. margin: 10px 0px !important;
  103. color: #999;
  104. }
  105. .labelUserId{
  106. color:#333;
  107. margin-bottom:10px !important;
  108. }
  109.  
  110.  
  111. </style>
  112. `)
  113. $("head").append(labelCss)
  114. var labelWindow=$(`
  115. <div class="labelBg" >
  116. <span class="btn-close">
  117. <i class="icon icon-close"></i>
  118. </span>
  119. <div class="labelMain">
  120. <span class="win-hint-ensure labelUserId">人物ID</span>
  121. <div>
  122. <p class="labelP1">输入标签</p>
  123. <input class="labelInput"></input>
  124. <button class="btn-addlabel">添加标签</button>
  125. </div>
  126. <p class="tips">当输入框内容为空时,点击添加标签,则可以去除标签</p>
  127. </div>
  128.  
  129. </div>
  130. `)
  131. labelWindow.userId="0"
  132. labelWindow.userName="0"
  133. //关闭按钮点击
  134. labelWindow.find(".btn-close").click(function(){
  135. labelWindow.hide();
  136. })
  137. var userData={};
  138.  
  139. if(localStorage.getItem("userLabelData")!=null){
  140. userData=JSON.parse(localStorage.getItem("userLabelData"));
  141. }
  142.  
  143. //添加按钮点击
  144. labelWindow.find(".btn-addlabel").click(function(e){
  145. //旧的
  146. /*
  147. if(labelWindow.userId!="0")
  148. {
  149. userData[labelWindow.userId]=labelWindow.find(".labelInput").val().replace(/\s+/g,"");
  150. if( userData[labelWindow.userId]==""){
  151. delete userData[labelWindow.userId];
  152. }
  153. localStorage.setItem("userLabelData",JSON.stringify(userData));
  154. upDataLabel();
  155. labelWindow.hide();
  156. }*/
  157. if(labelWindow.userName!="0")
  158. {
  159. userData[labelWindow.userName]=labelWindow.find(".labelInput").val().replace(/\s+/g,"");
  160. if( userData[labelWindow.userName]==""){
  161. delete userData[labelWindow.userName];
  162. }
  163. localStorage.setItem("userLabelData",JSON.stringify(userData));
  164. if($(".comment-list").length!=0){
  165. upDataLabel(1);
  166. }
  167. else{ upDataLabel(2);}
  168.  
  169. labelWindow.hide();
  170. }
  171.  
  172. })
  173.  
  174. //切换评论后刷新
  175. $(".area-comm-title-right").live("click",function(){
  176.  
  177. refreashComm();
  178. });
  179. $(".comment-banner").find(".button").live("click",function(){
  180.  
  181. refreashComm();
  182. });
  183. //切换页面后刷新
  184. $(".pager__btn").live("click",function(){
  185.  
  186. refreashComm();
  187.  
  188.  
  189.  
  190. });
  191.  
  192.  
  193. //刷新评论区
  194. refreashComm();
  195. var flag=setInterval(function(){
  196.  
  197.  
  198. //console.log("评论区刷新检测")
  199. labelButtonAdd(1);
  200. upDataLabel(1);
  201. //if($("[class='comment-list'],[class='area-comment-top clearfix']").length!=0){
  202.  
  203. if($("[class='switch fc-button']").text()=="返回盖楼模式"){
  204. // console.log("评论区标签刷新!")
  205.  
  206.  
  207. labelButtonAdd(2);
  208. upDataLabel(2);
  209. // clearInterval(flag)
  210.  
  211.  
  212. }
  213. if($("[class='switch fc-button']").text()=="试用新版评论"){
  214. // console.log("评论区标签刷新!")
  215.  
  216. labelButtonAdd(1);
  217. upDataLabel(1);
  218. // clearInterval(flag)
  219. }
  220. // }
  221. },
  222. 500 )
  223. function refreashComm(){
  224. var flag=setInterval(function(){
  225.  
  226. if($("[class='comment-list'],[class='area-comment-top clearfix']").length!=0){
  227. if($(".area-comm-title-right").find("a").next().text()=="返回盖楼模式"){
  228. console.log("评论区标签刷新!")
  229.  
  230.  
  231. labelButtonAdd(2);
  232. upDataLabel(2);
  233. clearInterval(flag)
  234.  
  235.  
  236. }
  237. if($(".comment-banner").find(".button.switch").text()=="试用新版评论"){
  238. console.log("评论区标签刷新!")
  239.  
  240. labelButtonAdd(1);
  241. upDataLabel(1);
  242. clearInterval(flag)
  243. }
  244. }
  245. },
  246. 200 )
  247. }
  248.  
  249. //更新所有人物标签
  250. function upDataLabel(type){
  251. //回复遍历
  252. /*
  253. $("[class='author-comment top'],[class='area-comment-right']").each(function(index,e){
  254. //判断回复者是否有标签
  255. if(userData[$(e).find(".name").attr("data-uid")]!=null){
  256. //判断是否已添加标签
  257. if($(e).find(".nameLabel").length!=0){
  258. $(e).find(".nameLabel").text(userData[$(e).find(".name").attr("data-uid")]);
  259. }else{
  260. var nameLabel=$("<a class='nameLabel'></a>")
  261. nameLabel.text(userData[$(e).find(".name").attr("data-uid")]);
  262. $(e).find(".name").after(nameLabel)
  263. }
  264. }
  265. else{
  266. $(e).find(".nameLabel").remove()
  267. }
  268. //按钮文字修改
  269. if($(e).find(".nameLabel").text()!=""){
  270. $(e).next().next().find(".btn-addlabel2").text("修改标签");
  271. }
  272. else{
  273. $(e).next().next().find(".btn-addlabel2").text("添加标签");
  274. }
  275. })*/
  276. //旧的
  277.  
  278. if(type==1){
  279. $(".fc-comment-item ").each(function(index,e){
  280. if(userData[$(e).find(".name").text()]!=null){
  281. //判断是否已添加标签
  282. if($(e).find(".nameLabel").length!=0){
  283. $(e).find(".nameLabel").text(userData[$(e).find(".name").text()]);
  284. }else{
  285. var nameLabel=$("<a class='nameLabel'></a>")
  286. nameLabel.text(userData[$(e).find(".name").text()]);
  287. $(e).find(".name").after(nameLabel)
  288. }
  289. }
  290. else{
  291. $(e).find(".nameLabel").remove()
  292. }
  293. //按钮文字修改
  294. if($(e).find(".nameLabel").text()!=""){
  295. $(e).next().next().find(".btn-addlabel2").text("修改标签");
  296. }
  297. else{
  298. $(e).next().next().find(".btn-addlabel2").text("添加标签");
  299. }
  300. })
  301. }
  302. else{
  303. $(".area-comment-title ").each(function(index,e){
  304. if(userData[$(e).find("a").text()]!=null){
  305. //判断是否已添加标签
  306. if($(e).find(".nameLabel").length!=0){
  307. $(e).find(".nameLabel").text(userData[$(e).find("a").text()]);
  308. }else{
  309. var nameLabel=$("<span class='nameLabel'></span>")
  310. nameLabel.text(userData[$(e).find("a").text()]);
  311. $(e).find("a").after(nameLabel)
  312. }
  313. }
  314. else{
  315. $(e).find(".nameLabel").remove()
  316. }
  317. //按钮文字修改
  318. if($(e).find(".nameLabel").text()!=""){
  319. $(e).next().next().find(".btn-addlabel3").text("修改标签");
  320. }
  321. else{
  322. $(e).next().next().find(".btn-addlabel3").text("添加标签");
  323. }
  324. })
  325.  
  326.  
  327. }
  328. }
  329.  
  330.  
  331.  
  332. //为所有回复添加标签按钮
  333. function labelButtonAdd(type){
  334. /*
  335. //回复遍历
  336. $("[class='author-comment top'],[class='area-comment-right']").each(function(index,e){
  337. if($(e).find(".btn-addlabel2").length==0){
  338. //添加标签按钮添加
  339. var label=$(`
  340. <a>添加标签</a>
  341. `)
  342. label.addClass("btn-addlabel2")
  343. $(e).next().next().find(".btn-quote").before(label)
  344.  
  345. //标签按钮点击
  346. label.click(function(){
  347. $(e).next().next().after(labelWindow)
  348. labelWindow.show();
  349. labelWindow.find(".labelInput").val("");
  350. labelWindow.find(".labelUserId").text($(e).find(".name").text());
  351. labelWindow.userId=$(e).find(".name").attr("data-uid")
  352. })
  353. }
  354. })
  355. */
  356. //以上为旧版
  357. if(type==1){
  358.  
  359.  
  360. //添加标签按钮添加
  361.  
  362. $(".fc-comment-item").each(function(index,e){
  363. if($(e).find(".comment-item-footer").find(".btn-addlabel2").length==0){
  364.  
  365. var label=$(`
  366. <a>添加标签</a>
  367. `)
  368. label.addClass("btn-addlabel2")
  369. $(e).find(".comment-item-footer").find(".comment-toolbar").prepend(label)
  370.  
  371. //标签按钮点击
  372. /* label.click(function(){
  373. // $(e).after(labelWindow)
  374. // console.log(labelWindow)
  375.  
  376.  
  377. })*/
  378. }
  379.  
  380.  
  381. })
  382. //标签按钮点击
  383. $(".btn-addlabel2").on("click",function(){
  384. var buttonBar= $(this).parents(".comment-item-footer");
  385. $(this).parents(".comment-toolbar").after(labelWindow)
  386. // console.log($(this).parents(".comment-item"))
  387. labelWindow.show();
  388. labelWindow.find(".labelInput").val("");
  389. labelWindow.find(".labelUserId").text(buttonBar.prev().prev().find(".name").text());
  390. labelWindow.userId=buttonBar.prev().prev().find(".name").attr("data-uid")
  391. labelWindow.userName=buttonBar.prev().prev().find(".name").text();
  392. // console.log( labelWindow.userName)
  393. // labelWindow.find(".labelUserId").text($(e).find(".name").text());
  394. // labelWindow.userId=$(e).find(".name").attr("data-uid")
  395. });
  396. }
  397. else{
  398. //添加标签按钮添加
  399.  
  400. $(".area-comment-tool").each(function(index,e){
  401. if($(e).find(".btn-addlabel3").length==0){
  402.  
  403. var label=$(`
  404. <svg class="svgIcon"
  405. xmlns="http://www.w3.org/2000/svg"
  406. xmlns:xlink="http://www.w3.org/1999/xlink"
  407. width="13px" height="13px">
  408. <image x="0px" y="0px" width="13px" height="13px" xlink:href="data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAQAAADY4iz3AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfjAQoPIR3qHDRfAAAAwElEQVQY023LMUoDURQF0DMTkIggCDGIugWxEAvjEsZUoriCryCCS3AXZn6WIVPZWCkiQmxS2ImkMZYWgkVSOBkV51bvcu5L8gvnmj594dlReFUmdWjkzLuWlo4irv/QopvQd1f2DUVc+z6T/MWygS1zs7UnWRiRapq38wvYVMRVkvzDgv8ZyBrdJZ0aWrHbuLp+bNuuw5RwqldDt8kExEsnf+BetyRiLlTwIAvjdNbCsX4Fe2FM9QWx58DQfniDKbpFL3LrqJVWAAAAAElFTkSuQmCC" />
  409. </svg>
  410. <a class="btn-addlabel3">添加标签</a>
  411. `)
  412. // label.addClass("btn-addlabel3")
  413. $(e).find(".area-comment-reply").after(label)
  414.  
  415. }
  416.  
  417.  
  418. })
  419. //标签按钮点击
  420. $(".btn-addlabel3").on("click",function(){
  421. var buttonBar= $(this).parents(".area-comment-tool");
  422. $(this).parents(".area-comment-tool").after(labelWindow)
  423. // console.log($(this).parents(".comment-item"))
  424. labelWindow.show();
  425. labelWindow.find(".labelInput").val("");
  426. labelWindow.find(".labelUserId").text(buttonBar.prev().prev().find(".name").text());
  427. labelWindow.userName=buttonBar.prev().prev().find(".name").text();
  428. // labelWindow.find(".labelUserId").text($(e).find(".name").text());
  429. // labelWindow.userId=$(e).find(".name").attr("data-uid")
  430. });
  431.  
  432.  
  433.  
  434. }
  435.  
  436.  
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443.  
  444.  
  445.  
  446. }
  447.  
  448.  
  449.  
  450.  
  451.  
  452. })();

QingJ © 2025

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