原地址
BiliBili_Auto_Like/autoLike.js at main · howxcheng/BiliBili_Auto_Like (github.com)
原作者
howxcheng (程昊) (github.com)
代码解析
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
(function () { "use strict"; var WIDE_MODE_SWITCH = false; var LIKE_TIME_OUT = 0;
var originUrl = document.location.toString(); var like_lock = false; var like_timer = null; var like_count = 0; var wide_lock = false; var wide_timer = null; var wide_count = 0; var main_timer = null; var main_lock = true; main_timer = setInterval(changeEvent, 1000); document.addEventListener("click", (_e) => { setTimeout(() => { var currentUrl = document.location.toString(); if (currentUrl !== originUrl) { if (!main_lock) { main_lock = true; main_timer = setInterval(changeEvent, 500); } } }, 500); }); function changeEvent() { if (document.readyState === "complete") { if (!like_lock) { like_lock = true; like_count = 0; like_timer = setInterval(clickLike, 500); } if (WIDE_MODE_SWITCH && !wide_lock) { wide_lock = true; wide_count = 0; wide_timer = setInterval(setWideMode, 500); } clearInterval(main_timer); originUrl = document.location.toString(); main_lock = false; } } function setWideMode() { wide_count++; var _set_wide_mode_button = document.querySelector('div[class="bpx-player-ctrl-btn bpx-player-ctrl-wide"]'); if (_set_wide_mode_button !== null) { try { _set_wide_mode_button.click(); } catch (error) { } wide_count = 64; } if (document.querySelector('div[class="bpx-player-ctrl-btn bpx-player-ctrl-wide bpx-state-entered"]') !== null) { wide_count = 64; } if (wide_count <= 60) return; clearInterval(wide_timer); goToSuitable(); wide_lock = false; } function goToSuitable() { setTimeout(function () { window.scrollTo({ top: 92, behavior: "smooth", }); }, 1000); } function clickLike() { like_count++; var _like_button = document.querySelector("div[class='video-like video-toolbar-left-item']"); if (_like_button !== null) { try { new Promise((resolve) => setTimeout(() => { _like_button.click(); Toast("已自动点赞", 3000); }, LIKE_TIME_OUT) ); } catch (error) { } like_count = 64; } if (document.querySelector("div[class='video-like video-toolbar-left-item on']") !== null) { like_count = 64; } if (like_count <= 60) return; clearInterval(like_timer); like_lock = false; } function Toast(msg, duration) { duration = isNaN(duration) ? 3000 : duration; var m = document.createElement("div"); m.innerHTML = msg; m.style.cssText = "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;"; document.body.appendChild(m); setTimeout(function () { var d = 0.5; m.style.webkitTransition = "-webkit-transform " + d + "s ease-in, opacity " + d + "s ease-in"; m.style.opacity = "0"; setTimeout(function () { document.body.removeChild(m); }, d * 1000); }, duration); } })();
|