bilibili_live_modify

目前只能车

  1. // ==UserScript==
  2. // @name bilibili_live_modify
  3. // @namespace http://tampermonkey.net/
  4. // @match *://live.bilibili.com/*
  5. // @version 0.2
  6. // @description 目前只能车
  7. // @author Yi MIT
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js
  10. // @require https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js
  11. // @grant GM_xmlhttpRequest
  12. // @license MIT
  13. // ==/UserScript==
  14. (function () {
  15. let website;//站点:0(斗鱼),1(虎牙),2(bilibili),3(抖音)
  16. let url = window.location.host;//当前网址
  17. let cookie = document.cookie;//获取所有cookie
  18. let csrf = '';//csrf码
  19. let room_info = '';//房间信息
  20. let room_id = '';//房间号
  21. let data = '';//表单数据
  22. let sessdata = '';//B站登录(不可用)状态
  23. let sleepTime = -1;
  24. let start = 0;//按钮状态:0启动 1停止
  25. let periodic = ''//周期状态
  26. let strI = 0;
  27. let strMax = 20;
  28. setTimeout(() => {
  29. initDLC();
  30. }, 7000);
  31. //初始化
  32. async function initDLC() {
  33. if (url === 'www.douyu.com') {
  34. website = 0;
  35. } else if (url === 'www.huya.com') {
  36. website = 1;
  37. } else if (url === 'live.bilibili.com') {
  38. website = 2;
  39. let temp = window.location.href.split("/")[3].split("?")[0];
  40. if (isNaN(parseFloat(temp))) {
  41. return;
  42. }
  43. room_info = await (await fetch("https://api.live.bilibili.com/room/v1/Room/get_info?room_id=" + temp)).json();
  44. room_id = room_info.data.room_id;
  45. let cookie_list = cookie.split(";");
  46. let flag = false;
  47. for (let i = 0; i < cookie_list.length; i++) {
  48. let temp = cookie_list[i].trim().split("=");
  49. if (temp[0] === 'bili_jct') {
  50. csrf = temp[1];
  51. } else if (temp[0] === 'yimit_live_sessdata') {
  52. flag = true;
  53. cookie = cookie + ";SESSDATA=" + temp[1];
  54. }
  55. }
  56. if (flag === false) {
  57. let returnGenerate = await run_unicycle_request_GET("https://passport.bilibili.com/x/passport-login/web/qrcode/generate");
  58. let login_live = document.createElement("div");
  59. login_live.setAttribute("style", "z-index: 999;position: fixed; top: 35%; left: 40%;background: #ffffff;padding: 0.3%;height: 16%; width: 7%;border-radius: 12px;display: block;");
  60. let main_live = document.querySelectorAll(".app-content.p-relative.z-app-content");
  61. main_live[0].appendChild(login_live);
  62. let login_live_text = document.createElement("div");
  63. login_live_text.innerHTML = "使用脚本前,请先用bilibili手机客户端扫码登陆";
  64. login_live_text.setAttribute("style", "color: #f69; text-align: center;");
  65. login_live.appendChild(login_live_text);
  66. let qrcode = document.createElement("div");
  67. qrcode.setAttribute("id", "qrcode");
  68. let img = new QRCode(qrcode, {
  69. text: returnGenerate[0].data.url,
  70. width: 180,
  71. height: 180,
  72. colorDark : "#000000",
  73. colorLight : "#ffffff"
  74. });
  75. login_live.appendChild(qrcode);
  76. let code = 1;
  77. while (code !== 0) {
  78. let login_in = await run_unicycle_request_GET("https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=" + returnGenerate[0].data.qrcode_key);
  79. code = login_in[0].data.code;
  80. if (code === 86090) {
  81. alert("二维码已扫未确认");
  82. } else if (code === 86038) {
  83. alert("二维码已失效");
  84. } else if (code === 0) {
  85. alert("账号已登录(不可用)");
  86. let sessdata = login_in[1].split('\n');
  87. for (let i = 0; i < sessdata.length; i++) {
  88. let set_cookie = sessdata[i].split(';');
  89. if (set_cookie.length > 1) {
  90. for (let j = 0, k = 0; j < set_cookie.length; j++) {
  91. let set_temp = set_cookie[j].split("=");
  92. if (set_temp[0].indexOf("SESSDATA") !== -1) {
  93. sessdata = set_temp[1];
  94. } else if (set_temp[0].trim() === 'Expires' && k === 0) {
  95. document.cookie = "yimit_live_sessdata=" + sessdata + "; expires=" + set_temp[1];
  96. cookie = cookie + ";SESSDATA=" + sessdata;
  97. k++;
  98. }
  99. }
  100. }
  101. }
  102. login_live.setAttribute("style", "z-index: 999;position: fixed; top: 35%; left: 40%;background: #ffffff;padding: 0.3%;height: 16%; width: 7%;border-radius: 12px;display: none;");
  103. }
  104. sleep(10);
  105. }
  106. }
  107. }
  108. let ul_tab_list = document.querySelectorAll(".tab-list.dp-flex");
  109. let tab_content = document.querySelectorAll(".tab-content.ts-dot-2.tab-content-pilot");
  110. let unicycle_test1_height = document.querySelectorAll(".tabs");
  111. if (document.getElementsByTagName("iframe").length > 2) {
  112. ul_tab_list = document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".tab-list.dp-flex");
  113. tab_content = document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".tab-content.ts-dot-2.tab-content-pilot");
  114. unicycle_test1_height = document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".tabs");
  115. }
  116. // let ul_tab_list = document.querySelectorAll(".tab-list.dp-flex");
  117. // alert(document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".tab-list.dp-flex").length);
  118. let li_tab_list = document.createElement("li");
  119. li_tab_list.setAttribute("id", "li-tab-list");
  120. li_tab_list.setAttribute('data-v-9a8f688c', '');
  121. li_tab_list.setAttribute('data-v-9d1b85a4', '');
  122. li_tab_list.setAttribute('class', 'item live-skin-normal-text dp-i-block live-skin-separate-border border-box t-center pointer opacity6');
  123. li_tab_list.setAttribute('height', '14px');
  124. li_tab_list.setAttribute('line-height', '14px');
  125. li_tab_list.setAttribute('border-right', '1px solid #e3e5e7;');
  126. li_tab_list.setAttribute('flex', '1');
  127. li_tab_list.innerHTML = "独轮车";
  128. ul_tab_list[0].appendChild(li_tab_list);
  129. let ul_tab_children = ul_tab_list[0].querySelectorAll('li');
  130. let unicycle_test1 = document.createElement("div");
  131. unicycle_test1.className = "unicycle-test1";
  132. unicycle_test1.setAttribute('data-v-018ef60e', '');
  133. unicycle_test1.setAttribute('data-v-30dc9297', '');
  134. unicycle_test1.setAttribute('style', 'z-index: 999;position: absolute;background: rgba(255, 255, 255, 0);');
  135. unicycle_test1.setAttribute('class', 'gift-rank-cntr live-skin-coloration-area rank-list-content a-move-in-top');
  136. unicycle_test1.style.width = tab_content[0].offsetWidth + 'px';
  137. unicycle_test1.style.top = unicycle_test1_height[0].offsetHeight + 'px';
  138. // unicycle_test1.style.height = 400 + 'px';
  139. unicycle_test1.style.height = "80%";
  140. unicycle_test1.style.display = 'none';
  141. tab_content[0].appendChild(unicycle_test1);
  142. let mode = document.createElement("div");
  143. mode.style.padding = "1%";
  144. mode.style.height = "100%";
  145. unicycle_test1.appendChild(mode);
  146. let mode_top = document.createElement("div");
  147. mode_top.style.width = "98%";
  148. mode_top.style.height = "7%";
  149. mode_top.style.padding = "0% 1% 2% 1%";
  150. mode.appendChild(mode_top);
  151. let mode_top_select = document.createElement("div");
  152. mode_top_select.style.height = "100%";
  153. mode_top_select.style.width = "50%";
  154. mode_top_select.style.display = "inline-flex";
  155. mode_top_select.innerHTML = "模式选择:"
  156. mode_top_select.style.alignItems = "center";
  157. let mode_top_select_1 = document.createElement("select");
  158. mode_top_select_1.style.height = "100%";
  159. mode_top_select_1.style.borderRadius = "4px";
  160. mode_top_select_1.style.border = "1px solid rgba(255,102,153,0.8)";
  161. mode_top.appendChild(mode_top_select);
  162. mode_top_select.appendChild(mode_top_select_1);
  163. let mode_top_select_option_0 = document.createElement("option");
  164. mode_top_select_option_0.value = "0";
  165. mode_top_select_option_0.innerHTML = "单句模式";
  166. mode_top_select_option_0.style.border = "0";
  167. mode_top_select_option_0.style.padding = "0";
  168. mode_top_select_option_0.style.borderRadius = "4px";
  169. mode_top_select_1.appendChild(mode_top_select_option_0);
  170. let mode_top_select_option_1 = document.createElement("option");
  171. mode_top_select_option_1.value = "1";
  172. mode_top_select_option_1.innerHTML = "说书模式";
  173. mode_top_select_option_1.style.border = "0";
  174. mode_top_select_option_1.style.padding = "0";
  175. mode_top_select_option_1.style.borderRadius = "4px";
  176. mode_top_select_1.appendChild(mode_top_select_option_1);
  177. let mode_top_select_option_2 = document.createElement("option");
  178. mode_top_select_option_2.value = "2";
  179. mode_top_select_option_2.innerHTML = "编程模式";
  180. mode_top_select_option_2.style.border = "0";
  181. mode_top_select_option_2.style.padding = "0";
  182. mode_top_select_option_2.style.borderRadius = "4px";
  183. mode_top_select_1.appendChild(mode_top_select_option_2);
  184. let mode_top_select_option_3 = document.createElement("option");
  185. mode_top_select_option_3.value = "3";
  186. mode_top_select_option_3.innerHTML = "随机模式";
  187. mode_top_select_option_3.style.border = "0";
  188. mode_top_select_option_3.style.padding = "0";
  189. mode_top_select_option_3.style.borderRadius = "4px";
  190. mode_top_select_1.appendChild(mode_top_select_option_3);
  191. let mode_top_select_right = document.createElement("div");
  192. mode_top_select_right.style.height = "100%";
  193. mode_top_select_right.style.width = "50%";
  194. mode_top_select_right.style.display = "inline-flex";
  195. mode_top.appendChild(mode_top_select_right);
  196. let mode_top_select_right_text = document.createElement("input");
  197. mode_top_select_right_text.setAttribute("id", "input_time");
  198. mode_top_select_right_text.type = "text";
  199. mode_top_select_right_text.style.width = "80%";
  200. mode_top_select_right_text.style.float = "right";
  201. mode_top_select_right_text.placeholder = "间隔时间(ms)";
  202. mode_top_select_right_text.style.borderRadius = "4px 0 0 4px";
  203. mode_top_select_right_text.style.padding = "0% 2%";
  204. mode_top_select_right_text.style.border = "1px solid rgba(255,102,153,0.8)";
  205. mode_top_select_right.appendChild(mode_top_select_right_text);
  206. let text_time = mode_top_select_right_text.value;
  207. let mode_top_select_right_span = document.createElement("span");
  208. mode_top_select_right_span.innerHTML = "ms";
  209. mode_top_select_right_span.style.display = "block";
  210. mode_top_select_right_span.style.justifyContent = "center";
  211. mode_top_select_right_span.style.alignContent = "center";
  212. mode_top_select_right_span.style.textAlign = "center";
  213. mode_top_select_right_span.style.width = "20%";
  214. mode_top_select_right_span.style.borderRadius = "0 4px 4px 0";
  215. mode_top_select_right_span.style.border = "1px solid rgba(255,102,153,0.8)";
  216. mode_top_select_right.appendChild(mode_top_select_right_span);
  217. let mode_text = document.createElement("textarea");
  218. mode_text.rows = "10";
  219. mode_text.cols = "20";
  220. mode_text.placeholder = "有活的整活,没活的复制,直播间不养闲人!";
  221. mode_text.style.width = "96%";
  222. mode_text.style.height = "75%";
  223. mode_text.style.padding = "2%";
  224. mode_text.style.borderRadius = "4px";
  225. mode_text.style.border = "1px solid rgba(255,102,153,0.8)";
  226. mode_text.setAttribute("id", "mode-text");
  227. mode.appendChild(mode_text);
  228. let text_str = mode_text.value;
  229. let mode_button = document.createElement("div");
  230. mode_button.style.padding = "2% 0%";
  231. mode_button.style.width = "100%";
  232. mode_button.style.height = "8%";
  233. mode_button.style.display = "inline-flex";
  234. mode.appendChild(mode_button);
  235. let mode_button_left = document.createElement("div");
  236. mode_button_left.style.height = "100%";
  237. mode_button_left.style.width = "50%";
  238. mode_button_left.style.display = "inline-flex";
  239. mode_button.appendChild(mode_button_left);
  240. let mode_button_right = document.createElement("div");
  241. mode_button_right.style.height = "100%";
  242. mode_button_right.style.width = "50%";
  243. mode_button_right.style.display = "inline-flex";
  244. mode_button.appendChild(mode_button_right);
  245. let mode_button_button = document.createElement("button");
  246. mode_button_button.setAttribute("id", "mode_button_button");
  247. mode_button_button.innerHTML = "独轮车,启动!";
  248. mode_button_button.style.padding = "0% 3%";
  249. mode_button_button.style.width = "94%";
  250. mode_button_button.style.background = "rgba(255,102,153,0.8)";
  251. mode_button_button.style.color = "#ffffff";
  252. mode_button_button.style.border = "0";
  253. mode_button_button.style.borderRadius = "4px";
  254. mode_button_right.appendChild(mode_button_button);
  255. for (let j = 0; j < ul_tab_children.length; j++) {
  256. ul_tab_children[j].addEventListener('click', (function(children, num, unicycle_test1_1) {
  257. return function(e) {
  258. for (let i = 0; i < children.length; i++) {
  259. children[i].setAttribute('class', 'item live-skin-normal-text dp-i-block live-skin-separate-border border-box t-center pointer opacity6');
  260. }
  261. // let tab_content = document.querySelectorAll(".tab-content.ts-dot-2.tab-content-pilot");
  262. let tab_content = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".tab-content.ts-dot-2.tab-content-pilot") : document.querySelectorAll(".tab-content.ts-dot-2.tab-content-pilot");
  263. if (children[num].id === 'li-tab-list') {
  264. unicycle_test1_1.style.display = 'block';
  265. tab_content[0].querySelectorAll("div")[0].style.display = "none";
  266. // let switch_btn = document.querySelectorAll(".switch-btn-bg.live-skin-highlight-bg");
  267. let switch_btn = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".switch-btn-bg.live-skin-highlight-bg") : document.querySelectorAll(".switch-btn-bg.live-skin-highlight-bg");
  268. switch_btn[0].click();
  269. } else {
  270. unicycle_test1_1.style.display = 'none';
  271. tab_content[0].querySelectorAll("div")[0].style.display = "block";
  272. }
  273. children[num].setAttribute('class', 'item live-skin-normal-text dp-i-block live-skin-separate-border border-box t-center pointer active');
  274. }
  275. })(ul_tab_children, j, unicycle_test1));
  276. }
  277. mode_top_select_1.addEventListener("change", (function(mode_top_select_1_1, text) {
  278. return function(e) {
  279. let change_num = mode_top_select_1_1.value;
  280. // let temp = document.getElementById("input_time");
  281. let temp = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.getElementById("input_time") : document.getElementById("input_time");
  282. if (change_num === '0') {
  283. temp.removeAttribute("disabled");
  284. text.placeholder = "按照指定时间间隔逐行发送弹幕" + '\n' + "1.使用回车换行。" + '\n' + "2.每行字符数建议不超过弹幕字符上限(超过部分会裁掉)。" + '\n' + "3.间隔时间建议不小于网站规定。";
  285. } else if (change_num === '1') {
  286. temp.removeAttribute("disabled");
  287. text.placeholder = "按照指定时间间隔逐行发送弹幕" + '\n' + "1.以符号为分段依据,过长会拆分发送。" + "\n" + "2.间隔时间建议不小于网站规定。";
  288. } else if (change_num === '2') {
  289. temp.setAttribute("disabled", "");
  290. text.placeholder = "待发送弹幕间可自定义发送间隔" + "\n" + "1.请以一行待发送弹幕一行间隔时间的格式来编写。" + "\n" + "2.每行字符数建议不超过弹幕字符上限(超过部分会裁掉)。" + '\n' + "3.间隔时间建议不小于网站规定。" + "\n\n例如:\n" + "谁不在改变呀!\n6000\n我也在改变呀!\n7000\n改变就应该改变!\n8000\n而不是不改变!\n9000";
  291. } else if (change_num === '3') {
  292. temp.setAttribute("disabled", "");
  293. text.placeholder = "随机时间间隔逐行发送弹幕" + '\n' + "1.使用回车换行。" + '\n' + "2.每行字符数建议不超过弹幕字符上限(超过部分会裁掉)。" + '\n' + "3.间隔时间建议不小于网站规定。";
  294. }
  295. }
  296. })(mode_top_select_1, mode_text));
  297. mode_button_button.addEventListener("click", (function(mode_top_select_1_1, room_id_1, csrf_1, cookie_1, data_1) {
  298. return function(e) {
  299. let change_num = mode_top_select_1_1.value;
  300. // let str = document.getElementById("mode-text").value;
  301. let str = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.getElementById("mode-text").value : document.getElementById("mode-text").value;
  302. // let time = document.getElementById("input_time").value;
  303. let time = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.getElementById("input_time").value : document.getElementById("input_time").value;
  304. let text = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.querySelectorAll(".chat-input.border-box") : document.querySelectorAll(".chat-input.border-box");
  305. // let button = document.getElementById("mode_button_button");
  306. let button = document.getElementsByTagName("iframe").length > 2 ? document.getElementsByTagName("iframe")[1].contentWindow.document.getElementById("mode_button_button") : document.getElementById("mode_button_button");
  307. if (start === 0) {
  308. if (str.trim() === "") {
  309. alert("独轮车不写内容好比上厕所不带纸");
  310. } else if (change_num === '0') {
  311. if (time.trim() === '') {
  312. alert("为什么不写时间!");
  313. } else {
  314. start = 1;
  315. button.innerHTML = "我说婷婷";
  316. let str_split = str.split("\n");
  317. let str_num = str_split.length;
  318. periodic = setInterval(() => {
  319. let str_temp = str_split[strI].length > 20 ? str_split[strI].substr(0, 20) : str_split[strI];
  320. text[text.length - 1].value = str_temp;
  321. let form_data = formData(str_temp, room_id_1, csrf_1);
  322. run_unicycle_request_1("https://api.live.bilibili.com/msg/send", cookie_1, form_data);
  323. strI = ++strI % str_split.length;
  324. sleep(100);
  325. text[text.length - 1].value = '';
  326. }, time);
  327. }
  328. } else if (change_num === '1') {
  329. if (time.trim() === '') {
  330. alert("为什么不写时间!");
  331. } else {
  332. start = 1;
  333. button.innerHTML = "我说婷婷";
  334. let str_split = new Array();
  335. let temp_str = '';
  336. for (let i = 0, j = 1; i < str.length; i++) {
  337. if (j < strMax && ([i] !== '\n' || str[i] !== '\t' || str[i] !== ',' || str[i] !== '.' || str[i] !== '?' || str[i] !== '!' || str[i] !== ',' || str[i] !== '。' || str[i] !== '?' || str[i] !== '!')) {
  338. temp_str += str[i];
  339. j++;
  340. } else {
  341. temp_str += str[i];
  342. str_split.push(temp_str);
  343. temp_str = '';
  344. j = 1;
  345. }
  346. }
  347. periodic = setInterval(() => {
  348. text[text.length - 1].value = str_split[strI];
  349. let form_data = formData(str_split[strI], room_id_1, csrf_1);
  350. run_unicycle_request_1("https://api.live.bilibili.com/msg/send", cookie_1, form_data);
  351. strI = ++strI % str_split.length;
  352. sleep(100);
  353. text[text.length - 1].value = '';
  354. }, time);
  355. }
  356. } else if (change_num === '2') {
  357. alert("编程模式");
  358. } else if (change_num === '3') {
  359. alert("随机模式");
  360. }
  361. } else {
  362. start = 0;
  363. button.innerHTML = "独轮车,启动!";
  364. clearInterval(periodic);
  365. }
  366. }
  367. })(mode_top_select_1, room_id, csrf, cookie, data));
  368. }
  369. })();
  370.  
  371. async function run_unicycle_request_1(url, cookie, data) {
  372. GM_xmlhttpRequest({
  373. method: 'POST',
  374. url: url,
  375. anonymous: true,
  376. cookie: cookie,
  377. data: data,
  378. onload: function(response) {
  379. },
  380. onerror: function (){
  381. alert(`操作失败`);
  382. }
  383. });
  384. }
  385.  
  386. async function run_unicycle_request_GET(url) {
  387. return new Promise((resolve, reject) => {
  388. GM_xmlhttpRequest({
  389. method: 'GET',
  390. url: url,
  391. headers: {
  392. "Content-Type": "application/json; charset=utf-8",
  393. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
  394. },
  395. onload: function(response) {
  396. let array = new Array();
  397. array[0] = JSON.parse(response.responseText);
  398. array[1] = response.responseHeaders;
  399. resolve(array);
  400. },
  401. onerror: function (){
  402. alert(`操作失败!`);
  403. }
  404. });
  405. })
  406. }
  407.  
  408. function sleep(time){
  409. return new Promise((resolve) => setTimeout(resolve, time));
  410. }
  411.  
  412. function formData(msg, room_id, csrf) {
  413. let form = new FormData();
  414. form.append("bubble","0");
  415. form.append("msg",msg);
  416. form.append("color","16777215");
  417. form.append("mode","1");
  418. form.append("fontsize","25");
  419. form.append("rnd",Date.now());
  420. form.append("roomid",room_id);
  421. form.append("csrf",csrf);
  422. form.append("csrf_token",csrf);
  423. return form;
  424. }

QingJ © 2025

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