Bilibili Black Deque

Make blacklist of bilibili a deque

当前为 2023-12-05 提交的版本,查看 最新版本

// ==UserScript==
// @name Bilibili Black Deque
// @version 0.0.4
// @namespace http://tampermonkey.net/
// @description Make blacklist of bilibili a deque
// @author Zxilly
// @source https://github.com/Zxilly/bili-black-deque
// @license https://opensource.org/licenses/MIT
// @match *://www.bilibili.com/*
// @require https://cdn.jsdelivr.net/npm/[email protected]
// ==/UserScript==
/******/(()=>{/******/"use strict";/******/var t={/***/397:/***/function(t,e,n){var o=this&&this.__awaiter||function(t,e,n,o){function i(t){return t instanceof n?t:new n(function(e){e(t)})}return new(n||(n=Promise))(function(n,r){function a(t){try{s(o.next(t))}catch(t){r(t)}}function c(t){try{s(o["throw"](t))}catch(t){r(t)}}function s(t){t.done?n(t.value):i(t.value).then(a,c)}s((o=o.apply(t,e||[])).next())})};var i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{"default":t}};Object.defineProperty(e,"__esModule",{value:true});e.getBlackListCnt=void 0;const r=i(n(467));function a(){return o(this,void 0,void 0,function*(){const t=(yield r.default.get("https://api.bilibili.com/x/relation/blacks",{withCredentials:true})).data;return t.data.total})}e.getBlackListCnt=a;/***/},/***/213:/***/function(t,e,n){var o=this&&this.__awaiter||function(t,e,n,o){function i(t){return t instanceof n?t:new n(function(e){e(t)})}return new(n||(n=Promise))(function(n,r){function a(t){try{s(o.next(t))}catch(t){r(t)}}function c(t){try{s(o["throw"](t))}catch(t){r(t)}}function s(t){t.done?n(t.value):i(t.value).then(a,c)}s((o=o.apply(t,e||[])).next())})};Object.defineProperty(e,"__esModule",{value:true});const i=n(285);const r=n(397);function a(){return o(this,void 0,void 0,function*(){let t=yield(0,r.getBlackListCnt)();const e=window.prompt(`现在黑名单有 ${t} 人,想移除:`);if(e===null){alert("必须输入一个整数");return}const n=Number.parseInt(e);if(Number.isNaN(n)){alert(`${e} 不能被解释为合法整数`);return}if(n<=0){alert("数字必须大于 0")}if(t<n){alert(`当前黑名单中的人数 ${t} 少于 ${n}`);return}yield(0,i.popBlack)(n,t);const o=yield(0,r.getBlackListCnt)();alert(`处理完成,当前黑名单有 ${o} 人`)})}document.addEventListener("keydown",t=>o(void 0,void 0,void 0,function*(){if(t.ctrlKey&&t.key==="b"){yield a()}}));const c="keep-target";const s="last-task-date";(()=>o(void 0,void 0,void 0,function*(){const t=localStorage.getItem(c);if(t===null){return}const e=Number.parseInt(t);if(Number.isNaN(e)){console.error(`target ${t} is not a number`);return}const n=localStorage.getItem(s);const o=new Date().toDateString();if(n===o){return}yield(0,i.popBlack)(e,(yield(0,r.getBlackListCnt)()));localStorage.setItem(s,o)}))();/***/},/***/285:/***/function(t,e,n){var o=this&&this.__awaiter||function(t,e,n,o){function i(t){return t instanceof n?t:new n(function(e){e(t)})}return new(n||(n=Promise))(function(n,r){function a(t){try{s(o.next(t))}catch(t){r(t)}}function c(t){try{s(o["throw"](t))}catch(t){r(t)}}function s(t){t.done?n(t.value):i(t.value).then(a,c)}s((o=o.apply(t,e||[])).next())})};var i=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{"default":t}};Object.defineProperty(e,"__esModule",{value:true});e.popBlack=void 0;const r=i(n(467));const a=document.cookie.split("; ").find(t=>t.startsWith("bili_jct")).split("=")[1];function c(t,e){return o(this,void 0,void 0,function*(){const n=Math.ceil(e/50);const o=[];for(let e=n;e>0;e--){const n=(yield r.default.get("https://api.bilibili.com/x/relation/blacks",{params:{ps:20,pn:e},withCredentials:true})).data;const i=n.data.list;i.reverse();for(const e of i){const n=e["mid"];o.push(n);if(o.length>=t){break}}if(o.length>=t){break}}console.log(JSON.stringify(o));console.log("收集完成,准备解除");console.groupCollapsed("解除请求细节");for(let t of o){const e=new URLSearchParams;e.append("fid",t);e.append("csrf",a);e.append("act","6");e.append("re_src","116");let n=3;while(n>0){const t=(yield r.default.post("https://api.bilibili.com/x/relation/modify",e,{withCredentials:true})).data;console.debug(JSON.stringify(t));if(t.code===0){break}n--}}console.groupEnd()})}e.popBlack=c;/***/},/***/467:/***/t=>{t.exports=axios;/***/}};/************************************************************************//******/// The module cache
/******/var e={};/******//******/// The require function
/******/function n(o){/******/// Check if module is in cache
/******/var i=e[o];/******/if(i!==undefined){/******/return i.exports;/******/}/******/// Create a new module (and put it into the cache)
/******/var r=e[o]={/******/// no module.id needed
/******/// no module.loaded needed
/******/exports:{}};/******//******/// Execute the module function
/******/t[o].call(r.exports,r,r.exports,n);/******//******/// Return the exports of the module
/******/return r.exports;/******/}/******//************************************************************************//******//******/// startup
/******/// Load entry module and return exports
/******/// This entry module is referenced by other modules so it can't be inlined
/******/var o=n(213);/******//******/})();