斗鱼批量取消关注

斗鱼关注中新增取消关注按钮

目前为 2019-08-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 斗鱼批量取消关注
  3. // @namespace http://github.com/qianjiachun
  4. // @version 0.1
  5. // @description 斗鱼关注中新增取消关注按钮
  6. // @author 小淳
  7. // @match https://www.douyu.com/directory/myFollow
  8. // @grant none
  9. // @require https://code.jquery.com/jquery-2.2.4.min.js
  10. // ==/UserScript==
  11. let isClick = false; //判断是否处于批量操作
  12. function addInfrastructure() {
  13. let style = document.createElement("style");
  14. style.appendChild(document.createTextNode(`
  15. .bubbly-button {
  16. font-family: 'Helvetica', 'Arial', sans-serif;
  17. display: inline-block;
  18. font-size: 1em;
  19. padding: 1em 2em;
  20. margin-bottom: 20px;
  21. -webkit-appearance: none;
  22. appearance: none;
  23. background-color: hotpink;
  24. color: #fff;
  25. border-radius: 4px;
  26. border: none;
  27. cursor: pointer;
  28. position: relative;
  29. transition: transform ease-in 0.1s, box-shadow ease-in 0.25s;
  30. box-shadow: 0 2px 25px rgba(255, 0, 130, 0.5);
  31. }
  32. .bubbly-button:focus {
  33. outline: 0;
  34. }
  35. .bubbly-button:hover {
  36. color: royalblue;
  37. }
  38. .bubbly-button:before, .bubbly-button:after {
  39. position: absolute;
  40. content: '';
  41. display: block;
  42. width: 140%;
  43. height: 100%;
  44. left: -20%;
  45. z-index: -1000;
  46. transition: all ease-in-out 0.5s;
  47. background-repeat: no-repeat;
  48. }
  49. .bubbly-button:before {
  50. display: none;
  51. top: -75%;
  52. background-image: radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, transparent 20%, #ff0081 20%, transparent 30%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, transparent 10%, #ff0081 15%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%);
  53. background-size: 10% 10%, 20% 20%, 15% 15%, 20% 20%, 18% 18%, 10% 10%, 15% 15%, 10% 10%, 18% 18%;
  54. }
  55. .bubbly-button:after {
  56. display: none;
  57. bottom: -75%;
  58. background-image: radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, transparent 10%, #ff0081 15%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%), radial-gradient(circle, #ff0081 20%, transparent 20%);
  59. background-size: 15% 15%, 20% 20%, 18% 18%, 20% 20%, 15% 15%, 10% 10%, 20% 20%;
  60. }
  61. .bubbly-button:active {
  62. transform: scale(0.9);
  63. background-color: #e60074;
  64. box-shadow: 0 2px 25px rgba(255, 0, 130, 0.2);
  65. }
  66. .bubbly-button.animate:before {
  67. display: block;
  68. animation: topBubbles ease-in-out 0.75s forwards;
  69. }
  70. .bubbly-button.animate:after {
  71. display: block;
  72. animation: bottomBubbles ease-in-out 0.75s forwards;
  73. }
  74. @keyframes topBubbles {
  75. 0% {
  76. background-position: 5% 90%, 10% 90%, 10% 90%, 15% 90%, 25% 90%, 25% 90%, 40% 90%, 55% 90%, 70% 90%;
  77. }
  78. 50% {
  79. background-position: 0% 80%, 0% 20%, 10% 40%, 20% 0%, 30% 30%, 22% 50%, 50% 50%, 65% 20%, 90% 30%;
  80. }
  81. 100% {
  82. background-position: 0% 70%, 0% 10%, 10% 30%, 20% -10%, 30% 20%, 22% 40%, 50% 40%, 65% 10%, 90% 20%;
  83. background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
  84. }
  85. }
  86. @keyframes bottomBubbles {
  87. 0% {
  88. background-position: 10% -10%, 30% 10%, 55% -10%, 70% -10%, 85% -10%, 70% -10%, 70% 0%;
  89. }
  90. 50% {
  91. background-position: 0% 80%, 20% 80%, 45% 60%, 60% 100%, 75% 70%, 95% 60%, 105% 0%;
  92. }
  93. 100% {
  94. background-position: 0% 90%, 20% 90%, 45% 70%, 60% 110%, 75% 80%, 95% 70%, 110% 10%;
  95. background-size: 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%, 0% 0%;
  96. }
  97. }
  98.  
  99. `));
  100.  
  101. document.head.appendChild(style);
  102. }
  103.  
  104.  
  105.  
  106.  
  107. function unFollowRoom(room_id,fElement) {
  108. $.ajax("https://www.douyu.com/room/follow/cancel_confuse/" + room_id, {
  109. type: 'post',
  110. success: function(data1){
  111. let data2 = eval("(" + data1 + ")");
  112. if (data2.error == "0") {
  113. console.log(room_id + "取关完毕");
  114. fElement.remove();
  115. } else{
  116. console.log(room_id + "取关失败");
  117. }
  118. }
  119. });
  120. }
  121.  
  122.  
  123. function unFollowRooms(e){
  124. var classname = document.getElementsByClassName("bubbly-button");
  125. for (var i = 0; i < classname.length; i++) {
  126. classname[i].addEventListener('click', animateButton, false);
  127. }
  128. let allRooms = document.getElementsByClassName("DyLiveCover-selectArea is-active");
  129. let room_id = "";
  130. if (allRooms.length >= 1) {
  131. let ret = confirm("是否确定取关?");
  132. if (ret == false) {
  133. return;
  134. }
  135. } else{
  136. return;
  137. }
  138. for (let i = 0; i < allRooms.length; i++) {
  139. if (allRooms[i].parentElement.getAttribute("href") == null) {
  140. room_id = allRooms[i].parentElement.querySelector("a").getAttribute("href");
  141. } else{
  142. room_id = allRooms[i].parentElement.getAttribute("href");
  143. }
  144. room_id = room_id.substring(1);//得到房间号
  145. unFollowRoom(room_id,allRooms[i].parentElement.parentElement);
  146. }
  147. }
  148. var animateButton = function(e) {
  149. e.preventDefault;
  150. //reset animation
  151. e.target.classList.remove('animate');
  152. e.target.classList.add('animate');
  153. setTimeout(function(){
  154. e.target.classList.remove('animate');
  155. },700);
  156. };
  157.  
  158. (function(){
  159. window.unFollowRooms = unFollowRooms;
  160. addInfrastructure();
  161.  
  162. let intID = setInterval(() => {
  163. if (typeof(document.getElementsByClassName("BranchTool")[0]) != "undefined") {
  164. document.getElementsByClassName("BranchTool")[0].onclick = function() {
  165. let fdiv = document.getElementsByClassName("FollowList-tabs")[0];
  166. if (typeof(document.getElementsByClassName("BranchTool-all")[0]) == "undefined") {
  167. isClick = true;
  168. let div = document.createElement("div");
  169. div.innerHTML = "<a href='javascript:void(0);' onclick='unFollowRooms()' id='unFollow' class='bubbly-button'>取消关注</a>";
  170. fdiv.insertBefore(div,fdiv.childNodes[0]);
  171. } else{
  172. isClick = false;
  173. document.getElementById("unFollow").remove();
  174. }
  175. console.log(isClick);
  176. }
  177. clearInterval(intID);
  178. }
  179. },1000);
  180. })()
  181.  
  182.  
  183.  
  184.  

QingJ © 2025

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