// ==UserScript== // @name B站-批量拉黑直播间机器人 // @description 批量拉黑直播间机器人 // @namespace https://scriptcat.org/zh-CN/script-show-page/2785/ // @version 1.1.2 // @license MIT // @author LadonQ // @icon https://www.bilibili.com/favicon.ico // @include http://space.bilibili.com/* // @include https://space.bilibili.com/* // @connect api.bilibili.com // @grant unsafeWindow // ==/UserScript== (function() { 'use strict'; const log = (...m) => console.warn('[QInfo]', ...m); const wait = t => new Promise(r => setTimeout(r, t)); const batchDelay = async () => await wait(0.2 * 1000); // 从cookie中获取csrf_token const getCookie = (name) => { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } const getCSRFToken = () => getCookie("bili_jct"); log("Cookie:" + getCSRFToken()) const getFollowURL = () => `https://api.bilibili.com/x/relation/modify`; const optHeaders = () => { return { "user-agent": unsafeWindow.navigator.userAgent, "cookie": unsafeWindow.document.cookie.split('; ').map(it => it.split("=")).map(it => it.map(i => i.match(/[^\x00-\x7F]/gm) ? encodeURIComponent(i) : i)).map(it => it.join("=")).join(", "), "origin": "space.bilibili.com", "referer": "https://www.bilibili.com/" } }; const optGetRequest = path => new Request(path, { method: 'GET', headers: optHeaders(), credentials: "include" }); const optPostRequest = (path, body = null) => new Request(path, { method: 'POST', headers: optHeaders(), credentials: "include", body }); const RELE_ACTION = { // 加入黑名单 BLOCK: 5, // 移除黑名单 UNBLOCK: 6 } const get_RELE_ACTION_Text = (id, fallback = '?') => { //let actText = ""; switch (id) { case 5: return "加入黑名单"; case 6: return "移除黑名单"; default: return fallback; } } // 需要加入黑名单的UID列表 const uid_list = [ 3546776046930594, 3546739774589238, 3546776317463299, 3546741041269015, 3546740993034384, 3546751638178164, 3493260519540812, 3546794472508038, 3546652910553267, 3546677594032573, 3546794403301573, 3546656152750753, 3546766708312646, 3494361998297713, 3546654636509299, 3546654644898246, 3546608931178814, 3546656127584796, 3546607012284656, 3546656630901576, 3546655817206124, 3546778760644964, 3546656469420368, 3546760412661892, 3546764527274008, 3546586867043021, 1938464087, 3546760582531597, 3546755194947608, 3546789057661401, 3546779928759179, 3546787132475837, 472738658, 3546643123145231, 1047441781, 3546760899201197, 3546776214702772, 3546784137743274, 247830407, 3546760892909983, 3546740747668080, 3546726229085029, 3546653829106509, 3546719539169670, 3546801051273762, 3546727638371079, 3546800180955840, 3546761314437560, 392427789, 3546799820245917, 3546652392557205, 3546717068724629, 3546753796147450, 3546787363162777, 3546801032399259, 1920869180, 3546643234294080, 3546611160451732, 3546775468116645, 3546783410030893, 3546786138426143, 3546752472844964, 3546791603604305, 3546799553906720, 3546761213774310, 3546670105102441, 3546766007863749, 1738856490, 1332005285, 3546641321691585, 1355276337, 1830422345, 3546654596663481, 3546655892704220, 279502432, 279513013, 3546655332764461, 3546654600858402, 309933628, 3546655320180802, 3546604273404664, 160175853, 3546644503070732, 3546654569400348, 3546641378314251, 309831342, 3546656096127238, 279513321, 3546656458934573, 3546656320522794, 279480466, 3546591902305090, 3546655309695289, 1394122135, 3546655911578057, 1513289763, 3546615371532754, 3546646216444670, 303357826, 279479713, 279513114, 3546617988778048, 3546655794137734, 279515243, 3546794279570035, 3494357984348463, 3546656089836096, 3546654628121144, 3546655603296263, 3546654412114113, 3546659585788033, 279483805, 3546720430459349, 3546572845484288, 322261454, 3546652788918432, 310642212, 358678229, 3546654896556552, 302957418, 3546654651189340, 3546654728783954, 3546655120951761, 279514807, 3546653455812609, 3546655257266311, 247830048, 3546654433085698, 3546654814767278, 3546654649092931, 306251576, 3546609885383132, 3546655873829041, 3546655167089082, 3546656142264973, 3546654852516240, 3546656148555885, 3546564140206536, 303349303, 3546653405481122, 3546654609246389, 544909406, 3546654649092334, 3546763575167801, 343267831, 3546654571498062, 3546655018191018, 3546641355245904, 3546655565547800, 3546589427665485, 3546656567986768, 3546655274043577, 620695476, 279511078, 3546571429907104, 3546793912568080, 279513620, 3546654663772883, 3546655964006962, 420142987, 3546655167088643, 3546802829658925, 3546787835021331, 3546804419299347, 629407829, 3546799065271180, 3546789128964128, 3546636458396083, 3546736031173077, 1431353404, 454847393, 3546765447923892, 3546781052832172, 3546802728995574, 3546645121730966, 3546610822810053, 3546655282432733, 3546567319488807, 3546605261162544, 3546763262692165, 311883221, 3546655869635264, 326615073, 3493285295294615, 1170951322, 279513119, 3546645664893138, 332716059, 3493290452191616, 3546624064227336, 279513333, 3546653806037294, 3546391911598566, 3546652270921998, 3546606657865742, 1340558073, 3546654447766025, 3546607314274645, 3546654917527566, 3546820082928317, 3546820082928492, 3546820085025446, 485818552, 3546820093413823, 3546820093413733, 3546820087122390, 3546820095510592, 3546820093414212, 3546820103899226, 3546820101802924, 3546820103899959, 3546820105996345, 3546820103899877, 3546820105996889, 3546820105996977, 3546820108093833, 3546663922698662, 3546831304788020, 3546831480948786, 3546831613069947, 3546831615166879, 3546820108093958, 3546831615167133, 3546831619360910, 3546831619361205, 3546831659207095, 3546837417986589, 3546837415889671, 3546837394918346, 3546837392821147, 3546820246505771, 3546836235192861, 3546836239387209, 3546831619361239, 3546837466220980, 3546837468318166, 3546837474609463, 3546837476706684, 3546837482998529, 3546837487192490, 3546837493483805, 3546837495581477, 3546837495581183, 3546837506066638, 3546837506067117, 3546837508164171, 3546854954371220, 3546854952274873, 3546854954371744, 3546854954371348 ]; // 需要移出黑名单的已注销UID列表 const del_uid_list = [ 35467994385640, 354678115559314, 3546812805811012, 3546820087122298, 3546820103899320, 3546820103899769, 3546820105996749, 3546820105996592, 3546831661303844, 3546820105997142, 3546837485095862 ]; const OperateUser = async (uids = [], actCode) => { const act = actCode; let Count = 0; for (let uid of uids) { const jsonData = await ( await fetch( optPostRequest( getFollowURL(), new URLSearchParams(`fid=${uid}&act=${act}&re_src=11&gaia_source=web_main&spmid=333.999.0.0&jsonp=jsonp&csrf=${getCSRFToken()}`) ) ) ).json() Count++; if (jsonData && jsonData.code === 0) { log("操作成功(" + get_RELE_ACTION_Text(act) + "):", "[" + Count + "/" + uids.length + "]", "已" + get_RELE_ACTION_Text(act), ":https://space.bilibili.com/" + uid); sendMsg("操作成功(" + get_RELE_ACTION_Text(act) + "): [" + Count + "/" + uids.length + "] 已" + get_RELE_ACTION_Text(act) + " :https://space.bilibili.com/" + uid); } else { log("操作失败(" + get_RELE_ACTION_Text(act) + "):", "[" + Count + "/" + uids.length + "]", jsonData.message, ":https://space.bilibili.com/" + uid); sendMsg("操作失败(" + get_RELE_ACTION_Text(act) + "): [" + Count + "/" + uids.length + "] " + jsonData.message + " :https://space.bilibili.com/" + uid); } await batchDelay(); } } // 批量操作函数 const batchOperatew = async () => { await OperateUser(uid_list, RELE_ACTION.BLOCK); await OperateUser(del_uid_list, RELE_ACTION.UNBLOCK); log("批量操作,执行完毕"); sendMsg("批量操作,执行完毕"); //alert('批量操作,执行完毕'); return; } // 执行批量操作 const createButton = () => { // 创建一个按钮元素 const QButton = document.createElement('button'); // 设置按钮的文本 QButton.textContent = '开始批量拉黑'; QButton.className = 'QButton'; QButton.style.position = 'fixed'; QButton.style.bottom = '20px'; QButton.style.right = '20px'; QButton.style.zIndex = '9999'; QButton.style.backgroundColor = '#f25d8e'; QButton.style.color = 'white'; QButton.style.padding = '10px 20px'; QButton.style.border = 'none'; QButton.style.borderRadius = '5px'; QButton.style.cursor = 'pointer'; // 为按钮添加点击事件监听器 QButton.addEventListener('click', function() { // 当用户点击按钮时,执行批量操作 batchOperatew(); }); // 添加到页面 document.body.appendChild(QButton); } const sendMsg = (msg, duration = 10000) => { const QmsgsToast = document.createElement("div"); QmsgsToast.classList.add("Qmsgs-toast"); QmsgsToast.style.position = "absolute"; QmsgsToast.style.bottom = "4.5rem"; QmsgsToast.style.right = "0.5rem"; QmsgsToast.style.display = "flex"; QmsgsToast.style.flexDirection = "column"; QmsgsToast.style.alignItems = "end"; QmsgsToast.style.zIndex = "99999"; document.body.appendChild(QmsgsToast); const QmsgsDom = document.querySelector(".Qmsgs-toast"); const QnewMsgDom = document.createElement("div"); QnewMsgDom.innerText = msg; QnewMsgDom.classList.add("Qmsg-toast"); QnewMsgDom.style.margin = "0.8rem"; QnewMsgDom.style.padding = "1rem"; QnewMsgDom.style.backgroundColor = "white"; QnewMsgDom.style.borderRadius = "0.5rem"; QnewMsgDom.style.boxShadow = "rgba(0, 0, 0, 0.3) 0px 19px 38px,rgba(0, 0, 0, 0.22) 0px 15px 12px"; QmsgsDom.appendChild(QnewMsgDom); setTimeout(() => { QnewMsgDom.remove(); }, duration); } // 执行创建开始按钮的操作 createButton(); })();