Bilibili自动点赞

哔哩哔哩视频、番剧自动点赞

  1. // ==UserScript==
  2. // @name Bilibili自动点赞
  3. // @name-en Bilibili_Auto_Like
  4. // @namespace http://tampermonkey.net/
  5. // @version 2.1
  6. // @description 哔哩哔哩视频、番剧自动点赞
  7. // @author Howxcheng
  8. // @match *://*.bilibili.com/video/*
  9. // @match *://*.bilibili.com/bangumi/*
  10. // @homepageURL https://github.com/howxcheng/BiliBili_Auto_Like
  11. // @supportURL https://github.com/howxcheng/BiliBili_Auto_Like/issues
  12. // @icon https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://bilibili.com&size=16
  13. // @license MIT
  14. // @run-at document-start
  15. // @grant unsafeWindow
  16. // @grant GM_xmlhttpRequest
  17. // @grant GM_getResourceText
  18. // @grant GM_notification
  19. // @grant GM_openInTab
  20. // @grant GM_getValue
  21. // @grant GM_setValue
  22. // @grant GM_addStyle
  23. // ==/UserScript==
  24.  
  25. (function () {
  26. "use strict";
  27. var WIDE_MODE_SWITCH = false; // 是否启用<自动宽屏模式>,true:开启,false:关闭
  28. var LIKE_TIME_OUT = 0; // 延迟点赞时间,单位:毫秒
  29.  
  30. var originUrl = document.location.toString();
  31. var like_lock = false; // 点赞计时器锁
  32. var like_timer = null; // 点赞计时
  33. var like_count = 0; // 点赞失败计数器
  34. var wide_lock = false; // 宽屏计时器锁
  35. var wide_timer = null; // 宽屏计时器锁
  36. var wide_count = 0; // 宽屏失败计数器
  37. var main_timer = null;
  38. var main_lock = true;
  39. main_timer = setInterval(changeEvent, 1000);
  40. document.addEventListener("click", (_e) => {
  41. // console.log("监控到点击事件");
  42. setTimeout(() => {
  43. var currentUrl = document.location.toString();
  44. if (currentUrl !== originUrl) {
  45. // console.log("url不同,执行操作");
  46. if (!main_lock) {
  47. main_lock = true;
  48. main_timer = setInterval(changeEvent, 500);
  49. }
  50. }
  51. }, 500);
  52. });
  53. function changeEvent() {
  54. if (document.readyState === "complete") {
  55. // console.log("执行");
  56. if (!like_lock) {
  57. like_lock = true;
  58. // console.log("like锁定");
  59. like_count = 0;
  60. like_timer = setInterval(clickLike, 500);
  61. }
  62. if (WIDE_MODE_SWITCH && !wide_lock) {
  63. wide_lock = true;
  64. // console.log("wide锁定");
  65. wide_count = 0;
  66. wide_timer = setInterval(setWideMode, 500);
  67. }
  68. clearInterval(main_timer);
  69. originUrl = document.location.toString();
  70. // console.log("timer解锁");
  71. main_lock = false;
  72. }
  73. }
  74. // 自动宽屏模式
  75. function setWideMode() {
  76. wide_count++;
  77. var _set_wide_mode_button = document.querySelector('div[class="bpx-player-ctrl-btn bpx-player-ctrl-wide"]');
  78. if (_set_wide_mode_button !== null) {
  79. try {
  80. _set_wide_mode_button.click();
  81. } catch (error) {
  82. // console.log(error);
  83. }
  84. // console.log("非宽屏,切换宽屏,次数:" + wide_count);
  85. wide_count = 64;
  86. }
  87. if (document.querySelector('div[class="bpx-player-ctrl-btn bpx-player-ctrl-wide bpx-state-entered"]') !== null) {
  88. // console.log("宽屏,跳过,次数:" + wide_count);
  89. wide_count = 64;
  90. }
  91. if (wide_count <= 60) return;
  92. // console.log("wide解锁");
  93. clearInterval(wide_timer);
  94. goToSuitable();
  95. wide_lock = false;
  96. }
  97. // 滚动至合适位置
  98. function goToSuitable() {
  99. setTimeout(function () {
  100. window.scrollTo({
  101. top: 92,
  102. behavior: "smooth",
  103. });
  104. }, 1000);
  105. }
  106. // 点赞
  107. function clickLike() {
  108. like_count++;
  109. var _like_button = document.querySelector("div[class='video-like video-toolbar-left-item']");
  110. if (_like_button !== null) {
  111. try {
  112. // // console.log("正在点赞");
  113. new Promise((resolve) =>
  114. setTimeout(() => {
  115. _like_button.click();
  116. Toast("已自动点赞", 3000);
  117. }, LIKE_TIME_OUT)
  118. );
  119. } catch (error) {
  120. // console.log(error);
  121. }
  122. // console.log("未点赞,正在点赞,次数:" + like_count);
  123. like_count = 64;
  124. }
  125. if (document.querySelector("div[class='video-like video-toolbar-left-item on']") !== null) {
  126. // console.log("已点赞,次数:" + like_count);
  127. like_count = 64;
  128. }
  129. if (like_count <= 60) return;
  130. // console.log("like解锁");
  131. clearInterval(like_timer);
  132. like_lock = false;
  133. }
  134. //界面toast提示
  135. function Toast(msg, duration) {
  136. duration = isNaN(duration) ? 3000 : duration;
  137. var m = document.createElement("div");
  138. m.innerHTML = msg;
  139. m.style.cssText =
  140. "font-family:siyuan;max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 10%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0,.7);font-size: 16px;";
  141. document.body.appendChild(m);
  142. setTimeout(function () {
  143. var d = 0.5;
  144. m.style.webkitTransition = "-webkit-transform " + d + "s ease-in, opacity " + d + "s ease-in";
  145. m.style.opacity = "0";
  146. setTimeout(function () {
  147. document.body.removeChild(m);
  148. }, d * 1000);
  149. }, duration);
  150. }
  151. })();

QingJ © 2025

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