-哔哩猫-(试用版)

注:练手作品,多多包涵,不接受恶意差评,有问题群内咨询(Q群1031014013):批量播放视频;批量拉黑;批量关注;动态艾特消息提醒(友情天选群746790091 )

当前为 2021-04-01 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/422731/917347/-%E5%93%94%E5%93%A9%E7%8C%AB-%EF%BC%88%E8%AF%95%E7%94%A8%E7%89%88%EF%BC%89.js

  1. // ==UserScript==
  2. // @name -哔哩猫-(试用版)
  3. // @description 注:练手作品,多多包涵,不接受恶意差评,有问题群内咨询(Q群1031014013):批量播放视频;批量拉黑;批量关注;动态艾特消息提醒(友情天选群746790091 )
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.4.0
  6. // @iconURL https://gitee.com/java_cn/BILIBLI_RES/raw/master/PIC/PC_1606377718.gif
  7. // @author 荒年(QQ:2019676120)
  8. // @match *://space.bilibili.com/*
  9. // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js
  10. // @require https://cdn.jsdelivr.net/gh/java-xiaoyi/HNGG-RES@ea375a9d65253039a2ef8cde53b6a3cf421a022c/javaex/pc/js/javaex.min.js
  11. // @require https://cdn.jsdelivr.net/gh/java-xiaoyi/HNGG-RES@ea375a9d65253039a2ef8cde53b6a3cf421a022c/javaex/pc/js/javaex-formVerify.js
  12. // @resource animate http://cdn.javaex.cn/javaex/pc/css/animate.css
  13. // @resource common http://cdn.javaex.cn/javaex/pc/css/common.css
  14. // @resource defaultCss http://cdn.javaex.cn/javaex/pc/css/skin/default.css
  15. // @grant unsafeWindow
  16. // @grant GM_getValue
  17. // @grant GM_setValue
  18. // @grant GM_xmlhttpRequest
  19. // @grant GM_getResourceText
  20. // @grant GM_openInTab
  21. // @grant GM_addStyle
  22. // @run-at document-idle
  23. // @license MIT License
  24. // @connect github.com
  25. // @connect gitee.com
  26. // @connect api.bilibili.com
  27. // @connect qmsg.zendee.cn
  28. // @connect passport.bilibili.com
  29. // @connect api.live.bilibili.com
  30. // @namespace http://tampermonkey.net/
  31. // ==/UserScript==
  32.  
  33.  
  34. GM_addStyle(`
  35.  
  36. #switch-qsmg:before {
  37. content: "开关";
  38. letter-spacing: 16px;
  39. top: 4px;
  40. left: 10px;
  41. }
  42. #left_navbar{
  43. z-index: 1000;
  44. position: absolute;
  45. top: 100px;
  46. left: 5px;
  47. }
  48. button[hnBtn="btn_open"] {
  49. z-index: 1001;
  50. z-index: 1000px;
  51. position: absolute;
  52. top: 58px;
  53. left: 220px;
  54. }
  55. .javaex-panel.javaex-panel-right.javaex-animated-zoom-in {
  56. top: 60px;
  57. }
  58. .javaex-menu-container {
  59. border: 1px solid #eee;
  60. }
  61. .javaex-panel-box p {
  62. text-align: center;
  63. background: #fb7299;
  64. }
  65. .fontbold{
  66. color: #00a1d6;
  67. font-weight: bold;
  68. cursor: pointer;
  69. }
  70. `);
  71.  
  72.  
  73. let HN_SETUP_CONFIG = {
  74.  
  75. qmsg_key: null, //后期改为kull 存储到本地
  76. qmsg_checked: false,
  77.  
  78.  
  79. }
  80.  
  81. let Live_info = {
  82. room_id: undefined,
  83. uid: undefined,
  84. blocked: undefined,
  85. csrf_token: undefined,
  86. visit_id: undefined,
  87. rnd: undefined,
  88. ruid: undefined,
  89. uname: undefined,
  90. user_level: undefined,
  91. ruid: undefined,
  92. };
  93.  
  94. let BILIBLI_PATH = {
  95.  
  96. "passport": "https://passport.bilibili.com",
  97. "api": "https://api.bilibili.com",
  98. "video": "https://www.bilibili.com/video/",
  99. "single_unread": "http://api.vc.bilibili.com/"
  100. }
  101.  
  102. let BILIBILI_URL = {
  103. // 导航栏用户信息
  104. "nav": BILIBLI_PATH.api + "/x/web-interface/nav",
  105. }
  106.  
  107. let BiliData = {
  108.  
  109. this_uid: window.location.href.split("/")[3], //当前页面uid
  110. author_uid: 99439379,
  111. login_code: null,
  112. login_message: "",
  113. LoginData: {},
  114. CoinLog: {},
  115. Unread: null,
  116. Video: {},
  117. replyAction: {},
  118. upCard: {},
  119. BVList: [],
  120. }
  121.  
  122. window.onload = function () {
  123.  
  124.  
  125. //界面显示
  126. init();
  127.  
  128.  
  129. }
  130.  
  131.  
  132. function init() {
  133.  
  134. Live_info.csrf_token = HNTOOL.getCookie("bili_jct");
  135. Live_info.uid = HNTOOL.getCookie("DedeUserID");
  136.  
  137. addStyle();
  138. addSetPage();
  139.  
  140. HNTOOL.chackAtMsg();
  141.  
  142. $("#getCoinLog").bind("click", async function () {
  143.  
  144.  
  145. if (HNAPI.getCoinLog()) {
  146.  
  147. await HNTOOL.Sleep(500);
  148. let html = '';
  149. html += '<div class="javaex-panel-box" style="width: 250px;">';
  150. html += ' <ul>';
  151. html += ` <p style="color: #FFF;">硬币使用记录</p>`;
  152.  
  153. BiliData.CoinLog.list.forEach(function (item) {
  154.  
  155. let BV = item.reason.replace(/[^a-z0-9]+/ig, "");
  156. if (BV.indexOf("BV") != -1) {
  157. html += `<li><a href="${BILIBLI_PATH.video}${BV}">${item.reason}${item.delta}币 ${item.time}</a> </li> `;
  158. }
  159. html += `<li>${item.reason}${item.delta}币 ${item.time}</li> `;
  160.  
  161.  
  162. });
  163. html += ' <hr class="javaex-divider"></hr>';
  164. html += ' </ul>';
  165. html += '</div>';
  166.  
  167. javaex.panel(this, {
  168. position: "right",
  169. //offsetTop: "104",
  170. content: html
  171. });
  172. javaex.tip({
  173. content: "获取用户成功!",
  174. type: "success"
  175. });
  176.  
  177. } else {
  178. javaex.tip({
  179. content: "获取硬币记录失败,请稍后重试!",
  180. type: "error"
  181. });
  182. }
  183.  
  184.  
  185. });
  186.  
  187. $("#getUnread").bind("click", async function () {
  188.  
  189. javaex.tip({
  190. content: "获取中,请稍候...",
  191. type: "submit"
  192. });
  193. HNAPI.getUnread();
  194.  
  195.  
  196. });
  197.  
  198.  
  199. $("#likeInDynamicComments").bind("click", async function () {
  200.  
  201. let prid = LocalData.get("likeInDynamic_PRID") == null ? "4015599048" : LocalData.get("likeInDynamic_PRID");
  202. let oid = LocalData.get("likeInDynamic_OID") == null ? "108928314" : LocalData.get("likeInDynamic_OID");
  203.  
  204. let html = '';
  205.  
  206. html += '<div style="padding: 10px 10px 10px 0px;">'
  207. html += '<form id="likeInDynamic_form">'
  208. html += ' <div class="javaex-unit clear">'
  209. html += ' <div class="javaex-unit-left"><p class="subtitle required">评论RPID</p></div>'
  210. html += ' <div class="javaex-unit-right">'
  211. html += ' <input type="text" class="javaex-text" data-type="positive_int" error-msg="评论RPID格式错误"'
  212. html += ` id="likeInDynamic_PRID" value=${prid} placeholder="请输入评论RPID"/>`
  213. html += ' </div>'
  214. html += ' </div>'
  215. html += ' <div class="javaex-unit clear">'
  216. html += ' <div class="javaex-unit-left"><p class="subtitle required">OID</p></div>'
  217. html += ' <div class="javaex-unit-right">'
  218. html += ' <input type="text" class="javaex-text" data-type="positive_int" error-msg="OID格式错误"'
  219. html += ` id="likeInDynamic_OID" value=${oid} placeholder="请输入OID"/>`
  220. html += ' </div>'
  221. html += ' </div>'
  222. html += ' <div class="javaex-unit clear tc">'
  223. html += ' <input type="button" id="likeInDynamic_no" class="javaex-hover-pulse javaex-btn no " value="取消赞"/>'
  224. html += ' <input type="button" id="likeInDynamic_yes" class="javaex-hover-pulse javaex-btn yes" value="点赞"/>'
  225. html += ' </div>'
  226. html += '</form>';
  227. html += '<hr class="javaex-divider"></hr>';
  228. html += '</div>';
  229.  
  230.  
  231. javaex.panel(this, {
  232. position: "right",
  233. content: html
  234. });
  235.  
  236.  
  237. // 监听点击保存按钮事件
  238. $("#likeInDynamic_yes").click(async function () {
  239. // 表单验证函数
  240. if (javaexVerify()) {
  241.  
  242. HNAPI.likeInDynamicComments(+javaex.getSelectVal("#likeInDynamic_OID"), +javaex.getSelectVal("#likeInDynamic_PRID"), 1);
  243. await HNTOOL.Sleep(1000);
  244.  
  245. if (BiliData.replyAction.code == 0) {
  246.  
  247. LocalData.set("likeInDynamic_PRID", javaex.getSelectVal("#likeInDynamic_PRID"));
  248. LocalData.set("likeInDynamic_OID", javaex.getSelectVal("#likeInDynamic_OID"));
  249.  
  250. javaex.tip({content: "评论区点赞成功!", type: "success"});
  251. } else {
  252. javaex.tip({content: "评论区点赞失败!", type: "error"});
  253. }
  254. if (BiliData.replyAction.code == 65006) {
  255. javaex.tip({content: "请勿重复点赞!", type: "error"});
  256. }
  257. }
  258. });
  259.  
  260. // 监听点击返回按钮事件
  261. $("#likeInDynamic_no").click(async function () {
  262.  
  263. if (javaexVerify()) {
  264.  
  265. HNAPI.likeInDynamicComments(+javaex.getLocalStorage("#likeInDynamic_OID"), +javaex.getLocalStorage("#likeInDynamic_PRID"), 0);
  266. await HNTOOL.Sleep(500);
  267.  
  268. if (BiliData.replyAction.code == 0) {
  269.  
  270. javaex.setLocalStorage("likeInDynamic_PRID", javaex.getSelectVal("#likeInDynamic_PRID"));
  271. javaex.setLocalStorage("likeInDynamic_OID", javaex.getSelectVal("#likeInDynamic_OID"));
  272.  
  273. javaex.tip({content: "评论区取消点赞成功!", type: "success"});
  274. } else {
  275. javaex.tip({content: "评论区取消点赞失败!", type: "error"});
  276. }
  277. if (BiliData.replyAction.code == 65006) {
  278. javaex.tip({content: "请勿重复取消点赞!", type: "error"});
  279. }
  280. }
  281. });
  282.  
  283. });
  284.  
  285. $("#biliUserMsg").bind("click", async function () {
  286.  
  287.  
  288. //刷新信息
  289. HNAPI.getUserNav();
  290. await HNTOOL.Sleep(500);
  291.  
  292. let isLogin = "未登录";
  293. let vipType = "无";
  294. //判断是否成功
  295. if (BiliData.login_code == 0) {
  296.  
  297.  
  298. if (BiliData.LoginData.isLogin) {
  299. isLogin = "已登录";
  300. }
  301.  
  302. if (BiliData.LoginData.vipType == 1) {
  303. vipType = "月度大会员";
  304. } else if (BiliData.LoginData.vipType == 2) {
  305. vipType = "年度大会员";
  306. }
  307.  
  308. let html = '';
  309. html += '<div class="javaex-panel-box" style="width: 250px;">';
  310. html += ' <ul>';
  311. html += ` <p style="color: #FFF;">用户信息</p>`;
  312. html += ` <li><a href="https://account.bilibili.com/account/home">当前用户:${BiliData.LoginData.uname}</a> </li> `;
  313. html += ` <li>用户状态:${isLogin} </li> `;
  314. html += ` <li>用户等级:${BiliData.LoginData.level_info.current_level}</li> `;
  315. html += ` <li>升级下一等级需:${BiliData.LoginData.level_info.next_exp - BiliData.LoginData.level_info.current_exp} 经验</li> `;
  316. html += ` <li>UID${BiliData.LoginData.mid} </li> `;
  317. html += ` <li><a href="https://account.bilibili.com/account/coin">硬币:${BiliData.LoginData.money}</a> </li> `;
  318. html += ` <li>节操值:${BiliData.LoginData.moral} </li> `;
  319. html += ` <li>会员:${vipType} </li> `;
  320. html += ' <hr class="javaex-divider"></hr>';
  321. html += ' </ul>';
  322. html += '</div>';
  323.  
  324.  
  325. javaex.panel(this, {
  326. position: "right",
  327. content: html
  328. });
  329.  
  330. javaex.tip({
  331. content: "获取用户成功!",
  332. type: "success"
  333. });
  334.  
  335. } else {
  336. javaex.tip({
  337. content: "获取用户信息失败!",
  338. type: "error"
  339. });
  340. }
  341.  
  342.  
  343. });
  344.  
  345. $("#getAtMsg").bind("click", async function () {
  346.  
  347. if (HNAPI.getMsgfeed("at") && typeof (HNAPI.getMsgfeed("at")) != "undefined") {
  348.  
  349. javaex.tip({
  350. content: "可能中奖了!!!",
  351. type: "success"
  352. });
  353. }
  354. });
  355.  
  356.  
  357. $("#disUser").bind("click", async function () {
  358.  
  359. let html = '';
  360. html += '<div class="javaex-panel-box" style="width: 500px;">';
  361. html += ' <div class="javaex-unit clear">';
  362. html += ' <div class="javaex-unit-left ml-10 mt-10">*拉黑列表</div>';
  363. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  364. html += ' <textarea id="disUser_uidList" class="javaex-desc" placeholder="请填写用户UID,多个用英文逗号,隔开"></textarea>';
  365. html += ' </div>';
  366. html += ' </div>';
  367. html += ' <div class="javaex-unit clear tc">';
  368. html += ' <input type="button" id="disUser_beg" class="javaex-btn yes" value="开始" />';
  369. html += ' </div>';
  370. html += '</div>';
  371.  
  372. javaex.panel(this, {
  373. position: "right",
  374. content: html
  375. });
  376.  
  377. $("#disUser_beg").bind("click", async function () {
  378.  
  379. let disUser_str = javaex.getSelectVal("#disUser_uidList");
  380. let disUser_uidList = disUser_str.split(",");
  381.  
  382. for (const vmid of disUser_uidList) {
  383.  
  384. HNAPI.disUserByUid(vmid);
  385.  
  386. await HNTOOL.Sleep(1500);
  387.  
  388. }
  389.  
  390. });
  391.  
  392. });
  393.  
  394. $("#batchFollow").bind("click", async function () {
  395.  
  396. var thisUPName = $("#h-name").text();
  397.  
  398.  
  399. let html = '';
  400. html += '<div class="javaex-panel-box" style="width: 500px;">';
  401. html += ' <div class="javaex-unit clear">';
  402. html += ' <div class="javaex-unit-left ml-10 mt-10">*关注列表</div>';
  403. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  404. html += ' <textarea id="batchFollow_uidList" class="javaex-desc" placeholder="请填写用户UID,多个用英文逗号,隔开,此功能会强制关注,解决账号异常不能关注问题!!!"></textarea>';
  405. html += ' </div>';
  406. html += ' </div>';
  407. html += ' <div class="javaex-unit clear tc">';
  408. html += ' <input type="button" id="batchFollow_beg" class="javaex-btn yes" value="开始" />';
  409. html += ` <input type="button" id="Follow_thisUp" class="javaex-btn yes" value="关注${thisUPName}" />`;
  410. html += ` <input type="button" id="disFollow_thisUp" class="javaex-btn yes" value="拉黑${thisUPName}" /> `;
  411. html += ' </div>';
  412. html += '</div>';
  413.  
  414. javaex.panel(this, {
  415. position: "right",
  416. content: html
  417. });
  418.  
  419. $("#disFollow_thisUp").bind("click", async function () {
  420.  
  421. HNAPI.batchModify(BiliData.this_uid, 5);
  422.  
  423. });
  424.  
  425. $("#Follow_thisUp").bind("click", async function () {
  426.  
  427. HNAPI.batchModify(BiliData.this_uid);
  428.  
  429. });
  430.  
  431. $("#batchFollow_beg").bind("click", async function () {
  432.  
  433. let mid_str = javaex.getSelectVal("#batchFollow_uidList");
  434. mid_list = mid_str.split(",");
  435.  
  436. let mid_Lists = HNTOOL.split_array(mid_list,10);
  437. for (const mids of mid_Lists) {
  438.  
  439. HNAPI.batchModify(mids.toString());
  440. await HNTOOL.Sleep(3000);
  441. }
  442.  
  443.  
  444. });
  445.  
  446. });
  447.  
  448.  
  449. $("#HNSetup").bind("click", async function () {
  450.  
  451. var CONFIG = HNTOOL.getConfig();
  452.  
  453.  
  454. let html = '';
  455.  
  456. html += '<div style="padding: 10px 10px 10px 0px;width:400px; ">'
  457. html += '<form id="HNGG_SETUP">'
  458. html += ' <div class="javaex-unit clear">'
  459. html += ' <div class="javaex-unit-left mr-10"><p class="subtitle required">Q酱key</p></div>'
  460. html += ' <div class="javaex-unit-left mr-10" style="width:200px">'
  461. html += ' <input type="text" class="javaex-text" data-type="english_number" error-msg="Q酱key不正确" ;'
  462. html += ` id="HNSetup_Qmsg_key" value="${CONFIG.qmsg_key}" placeholder="请输入Q酱key"/>`
  463. html += ' </div>'
  464. html += ' <div class="javaex-unit-left mr-10">'
  465. html += ` <input type="checkbox" class="javaex-switch" id="switch-qsmg" /> `
  466. html += ' </div>'
  467. html += ' </div>'
  468. html += '</form>';
  469. html += '<div class="javaex-unit clear tc">';
  470. html += ' <input type="button" id="HNSetup_save" class="javaex-btn yes" value="保存" />';
  471. html += '</div>';
  472. html += '<hr class="javaex-divider"></hr>';
  473. html += '</div>';
  474.  
  475. javaex.panel(this, {
  476. position: "right",
  477. content: html
  478. });
  479.  
  480.  
  481. HNTOOL.cssChecked("#switch-qsmg", CONFIG.qmsg_checked, HN_SETUP_CONFIG.qmsg_checked);
  482.  
  483. $("#switch-qsmg").bind("click", function () {
  484.  
  485. HN_SETUP_CONFIG.qmsg_checked = CONFIG.qmsg_checked == true ? false : true;
  486.  
  487. })
  488.  
  489.  
  490. $("#HNSetup_save").bind("click", async function () {
  491.  
  492.  
  493. HN_SETUP_CONFIG.qmsg_key = javaex.getSelectVal("#HNSetup_Qmsg_key");
  494.  
  495. localStorage.setItem(`HN_SETUP_CONFIG`, JSON.stringify(HN_SETUP_CONFIG));
  496.  
  497. javaex.tip({
  498. content: "设置成功!",
  499. type: "success"
  500. });
  501.  
  502. });
  503.  
  504. });
  505.  
  506. //
  507. $("#getUpMassage").bind("click", async function () {
  508.  
  509.  
  510. let html = '';
  511.  
  512. html += '<div style="padding: 10px 10px 10px 0px;">'
  513. html += '<form id="getUpMassage_form">'
  514. html += ' <div class="javaex-unit clear">'
  515. html += ' <div class="javaex-unit-left mr-10"><p class="subtitle required">用户uid</p></div>'
  516. html += ' <div class="javaex-unit-left mr-10">'
  517. html += ' <input type="text" class="javaex-text javaex-grid-4" data-type="positive_int" error-msg="用户uid"'
  518. html += ` id="up_uid" value="${BiliData.this_uid}" placeholder="请输入评论uid"/>`
  519. html += ' </div>'
  520. html += ' <div class="javaex-unit-right mr-10">'
  521. html += ' <input type="button" id="getUpMsg" class="javaex-btn blue" value="查询"/>'
  522. html += ' </div>'
  523. html += ' </div>'
  524. html += ' <div class="javaex-unit clear tc" style="width: 500px;">'
  525. html += ' <table id="upMsgTable" class="javaex-table td-c-1">'
  526. html += ' <thead>'
  527. html += ' <tr><th>内容</th><th>详情</th></tr>'
  528. html += ' </thead>'
  529. html += ' <tbody id="upMsgTbody">'
  530.  
  531. html += ' </tbody>'
  532. html += '</table> '
  533. html += '</div>'
  534. html += '</form>';
  535. html += '<hr class="javaex-divider"></hr>';
  536. html += '</div>';
  537.  
  538.  
  539. javaex.panel(this, {
  540. position: "right",
  541. content: html
  542. });
  543.  
  544. javaex.table({
  545. id: "upMsgTable",
  546. isDragColWidth: true, // 是否允许拖动改变列宽
  547. mode: "overflow", // overflow表示允许使用父容器溢出来调整列的大小
  548. leftFixedColNum: 2, // 左侧固定列数
  549. rightFixedColNum: 1, // 右侧固定列数
  550. sort: {
  551. "1": "create_time", // 4表示第几列(从1开始计)。create_time表示排序字段,回调函数会返回该值
  552. "2": "update_time"
  553. },
  554. sortCallback: function (rtn) {
  555. //console.log(rtn.sortArr);
  556. }
  557. });
  558.  
  559. //
  560. $("#getUpMsg").click(async function () {
  561.  
  562. let thismid = javaex.getSelectVal("#up_uid");
  563. await HNAPI.userInfo(thismid)
  564.  
  565. let temp = await HNAPI.getUpCard(thismid);
  566.  
  567.  
  568. await HNTOOL.Sleep(500);
  569.  
  570.  
  571. if (temp != false) {
  572. let data = BiliData.upCard.data;
  573.  
  574. let html = ``;
  575. html += `<tr><td>用户UID</td><td>${data.card.mid}</td></tr> `
  576. html += `<tr><td>用户等级</td><td>lv${data.card.level_info.current_level}</td></tr> `
  577. html += `<tr><td>用户昵称</td><td>${data.card.name}</td></tr> `
  578. html += `<tr><td>用户性别</td><td>${data.card.sex}</td></tr> `
  579. html += `<tr><td>用户头像</td><td><a href="javascript:;"><img src= ${data.card.face} width="50%"></a></td></tr> `
  580. html += `<tr><td>粉丝数</td><td>${data.follower}</td></tr> `
  581. html += `<tr><td>关注数</td><td>${data.card.friend}</td></tr> `
  582. html += `<tr><td>是否关注此用户</td><td>${data.following}</td></tr> `
  583. html += `<tr><td>用户稿件数</td><td>${data.archive_count}</td></tr> `
  584. html += `<tr><td>用户勋章</td><td>${data.card.nameplate.name}<a href="javascript:;"><img src= ${data.card.nameplate.image} width="50%"></a> </td></tr> `
  585. html += `<tr><td>用户勋章等级</td><td>${data.card.nameplate.level}</td></tr> `
  586. html += `<tr><td>认证信息</td><td>${data.card.Official.title}</td></tr> `
  587.  
  588.  
  589. $("#upMsgTbody").empty();
  590. $("#upMsgTbody").append(html);
  591. }
  592.  
  593.  
  594. });
  595. //点击放大
  596. /* $("img").click(function() {
  597. javaex.dialog({
  598. type : "image", // 弹出层类型
  599. url : $(this).attr("src") // 图片地址
  600. });
  601. });*/
  602.  
  603. });
  604.  
  605.  
  606. $("#plateActivity").bind("click", async function () {
  607.  
  608. //获取轮盘数据
  609.  
  610. let url = "https://gitee.com/java_cn/BILIBLI_RES/raw/master/HNPLATE/plateActivity.json";
  611. let myjson = await HNAPI.getMyJson(url);
  612.  
  613. for (const json of myjson) {
  614. let x = json.name;
  615.  
  616. }
  617.  
  618.  
  619. });
  620.  
  621. $("#addPlay").bind("click", async function () {
  622.  
  623.  
  624. let html = '';
  625.  
  626. html += '<div style="padding: 10px 10px 10px 0px;">'
  627. html += '<form id="getUpMassage_form">'
  628.  
  629. html += ' <div class="javaex-unit clear">'
  630. html += ' <div class="javaex-unit-left"><p class="subtitle required">UID</p></div>'
  631. html += ` <div class="javaex-unit-right" tooltip="请输入用户UID,默认自己" tooltip-pos="up"> `
  632. html += ' <input type="text" class="javaex-text" data-type="positive_int|required" error-msg="请正确输入uid"'
  633. html += ` id="addPlay_uid" value="${Live_info.uid}" placeholder="默认${BiliData.author_uid}"/>`
  634. html += ' </div>'
  635. html += ' </div>'
  636. html += ' <div class="javaex-unit clear">'
  637. html += ' <div class="javaex-unit-left"><p class="subtitle required">BV</p></div>'
  638. html += ' <div class="javaex-unit-right" tooltip="请输入视频BV号 例如BV14r4y1A7Q9 (0表示全部)" tooltip-pos="up">'
  639. html += ' <input type="text" class="javaex-text" data-type="required|english_number" error-msg=""'
  640. html += ` id="addPlay_bv" value="0" placeholder="请输入视频BV号 例如BV14r4y1A7Q9 (0表示全部)"/>`
  641. html += ' </div>'
  642. html += ' </div>'
  643. html += '</form>';
  644. html += ' <div class="javaex-unit clear tc">'
  645. html += ' <button id="addPlay_bgn" class="javaex-btn blue radius-3">开始</button> '
  646. html += ' </div>'
  647. html += '<hr class="javaex-divider"></hr>';
  648. html += '</div>';
  649.  
  650.  
  651. javaex.panel(this, {
  652. position: "right",
  653. content: html
  654. });
  655.  
  656. $("#addPlay_bgn").click(async function () {
  657.  
  658. let MID = javaex.getSelectVal("#addPlay_uid")
  659. let BV = javaex.getSelectVal("#addPlay_bv");
  660. let bvArr = [];
  661. let bvArr2 = [];
  662.  
  663. MID = javaex.ifnull(MID, BiliData.author_uid);
  664.  
  665.  
  666. if (BV == "0") {
  667.  
  668. //1.查询up所有视频BV号 2.发送心跳间隔2s
  669. HNAPI.getUpAllBV(BiliData.author_uid, 1, 2);
  670. await HNTOOL.Sleep(500);
  671. bvArr2 = BiliData.BVList;
  672.  
  673. for (let i = 1; i > 0; i++) {
  674.  
  675. HNAPI.getUpAllBV(MID, i);
  676.  
  677. await HNTOOL.Sleep(500);
  678.  
  679. if (BiliData.BVList.length == 0) {
  680. if (bvArr.length == 0) {
  681. javaex.tip({
  682. content: "该用户无投稿视频,请确认是否有误!",
  683. type: "success"
  684. });
  685. await HNTOOL.Sleep(2000);
  686. }
  687. //bvArr = bvArr.ifnull(bvArr2, bvArr.concat(bvArr2));
  688. bvArr = bvArr.concat(bvArr2);
  689. break;
  690. }
  691.  
  692. bvArr = bvArr.concat(BiliData.BVList);
  693. }
  694.  
  695.  
  696. if (bvArr.length != 0) {
  697.  
  698. for (const emt of bvArr) {
  699.  
  700. HNAPI.playOneVideo(emt.bvid, MID);
  701.  
  702. await HNTOOL.Sleep(2000);
  703.  
  704. }
  705.  
  706. alert("播放完成!!!");
  707.  
  708. }
  709.  
  710.  
  711. } else {
  712. //1.调用点击播放接口
  713. //2.发送心跳
  714.  
  715. await HNTOOL.Sleep(500);
  716.  
  717. HNAPI.playOneVideo(BV);
  718. }
  719.  
  720.  
  721. });
  722.  
  723.  
  724. });
  725.  
  726. }
  727.  
  728. let showUnreadMsg = function () {
  729.  
  730. var html = '';
  731. html += '<div class="javaex-panel-box" style="width: 250px;">';
  732. html += ' <ul>';
  733. html += ` <p style="color: #FFF;">用户消息</p>`;
  734. html += ` <li><a href="https://message.bilibili.com/#/at">未读艾特数:${BiliData.Unread.at}</a> </li> `;
  735. html += ` <li><a href="https://message.bilibili.com/#/love">未读点赞数:${BiliData.Unread.like}</a> </li> `;
  736. html += ` <li><a href="https://message.bilibili.com/#/reply">未读回复数:${BiliData.Unread.reply}</a> </li> `;
  737. html += ` <li><a href="https://message.bilibili.com/#/system">未读系统通知数:${BiliData.Unread.sys_msg}</a> </li> `;
  738. html += ` <li><a href="">UP主助手信息数:${BiliData.Unread.up}</a> </li> `;
  739. html += ' <hr class="javaex-divider"></hr>';
  740. html += ' </ul>';
  741. html += '</div>';
  742.  
  743.  
  744. javaex.panel(document.getElementById("getUnread"), {
  745. position: "right",
  746. content: html
  747. });
  748.  
  749. javaex.tip({
  750. content: "查询用户通知成功!",
  751. type: "success"
  752. });
  753.  
  754. }
  755.  
  756. /**
  757. * 检查 艾特信息
  758. * @returns {Promise<void>}
  759. */
  760. let chackAtMsg = async function (items) {
  761.  
  762. await HNTOOL.Sleep(500);
  763.  
  764. if (items != false && typeof (items) != "undefined") {
  765.  
  766.  
  767. var html = '';
  768. html += '<div class="javaex-panel-box" style="width: auto;">';
  769. html += ' <ul>';
  770. html += ` <p style="color: #FFF;">@信息</p>`;
  771. items.forEach(function (item) {
  772.  
  773. var atTime = javaex.dateFormat(item.at_time, 'yyyy-MM-dd HH:mm:ss');
  774. HNAPI.sendQmsg(HNTOOL.getConfig().qmsg_key, atTime + " 恭喜动态中奖了!" + `${item.user.nickname}在动态中艾特了你! 内容:${item.item.source_content}`);
  775.  
  776. html += ` <li>${atTime} <a class="fontbold" href="https://space.bilibili.com/${item.user.mid}">:${item.user.nickname}</a>在动态中艾特了你!</li> `
  777. html += ` <li class="fontbold">内容:${item.item.source_content}</li> `;
  778. html += ` <li><a href="${item.item.uri}">---点击查看详情---</a> </li> `;
  779. html += ' <hr class="javaex-divider"></hr>';
  780. });
  781. html += ' </ul>';
  782. html += '</div>';
  783.  
  784.  
  785. if (($("#chackList").attr("class")).indexOf("hover") > -1) {
  786. javaex.panel(document.getElementById("getAtMsg"), {
  787. position: "right",
  788. content: html
  789. });
  790. } else {
  791. javaex.panel(document.getElementById("chackList"), {
  792. position: "right",
  793. content: html
  794. });
  795. }
  796.  
  797.  
  798. }
  799.  
  800. }
  801.  
  802.  
  803. let addSetPage = async function () {
  804.  
  805. HNTOOL.Sleep(1000);
  806.  
  807. $('body').append('' +
  808. '<div id="left_navbar">' +
  809. '<div class="javaex-menu-container"> ' +
  810. ' <div id="menu" class="javaex-menu"> ' +
  811. ' <ul> ' +
  812. ' <li class="javaex-menu-item alone hover" > ' +
  813. ' <a href="javaScript:;" style="background: #fb7299;padding-left: 0px;text-align: center;color: #ffffff;font-weight: bold;border-bottom: 1px solid #eee;" ' +
  814. ` tooltip="我是来测试的" tooltip-pos="right">管理中心 v${GM_info.script.version}</a> ` +
  815. ' </li> ' +
  816. ' </ul> ' +
  817. ' <ul> ' +
  818. ' <li class="javaex-menu-item"> ' +
  819. ' <a href="javascript:;">个人中心<i class="icon-angle-down"></i></a> ' +
  820. ' <ul> ' +
  821. ' <li id="biliUserMsg" class="javaex-hover-pulse"><a href="javaScript:;">用户信息</a></li> ' +
  822. ' </ul> ' +
  823. ' </li> ' +
  824. ' <li id="chackList" class="javaex-menu-item"> ' +
  825. ' <a href="javaScript:;">查询<i class="icon-angle-down"></i></a> ' +
  826. ' <ul> ' +
  827. ' <li id="getUpMassage" ><a href="javaScript:;">查询用户详细信息</a></li> ' +
  828. ' <li><a href="javaScript:;">查询每日最热视频【禁用】</a></li> ' +
  829. ' <li id="getAtMsg"><a href="javaScript:;">查询动态艾特信息</a></li> ' +
  830. ' <li id="getCoinLog" class="javaex-hover-pulse"><a href="javaScript:;">查询硬币变化</a></li> ' +
  831. ' <li id="getUnread" class="javaex-hover-pulse"><a href="javaScript:;">查询消息</a></li> ' +
  832. ' </ul> ' +
  833. ' </li> ' +
  834. ' <li class="javaex-menu-item"> ' +
  835. ' <a href="javascript:;">工具<i class="icon-angle-down"></i></a> ' +
  836. ' <ul> ' +
  837. ' <li class="javaex-hover-pulse"><a href="javaScript:;" >移动粉丝勋章</a></li> ' +
  838. ' <li class="javaex-hover-pulse"><a href="javaScript:;" >评论区抽奖</a></li> ' +
  839. ' <li id="plateActivity" class="javaex-hover-pulse"><a href="javaScript:;" >轮盘抽奖</a></li> ' +
  840. ' <li class="javaex-hover-pulse"><a href="javaScript:;" >注册答题</a></li> ' +
  841. ' <li id="addPlay" class="javaex-hover-pulse"><a href="javaScript:;" >批量播放视频</a></li> ' +
  842. ' <li id="disUser" class="javaex-hover-pulse"><a href="javaScript:;" >批量拉黑</a></li> ' +
  843. ' <li id="batchFollow" class="javaex-hover-pulse"><a href="javaScript:;" >批量关注</a></li> ' +
  844. ' <li class="javaex-hover-pulse"><a href="javaScript:;" >批量发私信</a></li> ' +
  845. ' <li class="javaex-hover-pulse"><a href="javaScript:;" >批量发送视频弹幕</a></li> ' +
  846. ' <li id="" class="javaex-hover-pulse" ><a href="javaScript:;">动态评论区点赞</a></li> ' +//likeInDynamicComments
  847. ' <li id="HNSetup" class="javaex-hover-pulse" ><span class="icon-cogs" style="font-size:50px;color:#ff0000;"></span><a href="javaScript:;">设置</a></li> ' +
  848. ' </ul> ' +
  849. ' </li> ' +
  850.  
  851.  
  852. ' </ul> ' +
  853. ' </div> ' +
  854. '</div>' +
  855. '</div>');
  856. //$("#left_navbar").before('<button hnBtn="btn_open" class="javaex-btn green" onclick="openBar()">点我关闭</button>')
  857.  
  858. javaex.menu({
  859. id: "menu",
  860. isShowAll: false
  861. });
  862.  
  863. }
  864.  
  865.  
  866. let addStyle = function () {
  867. const animate = GM_getResourceText('animate');
  868. const common = GM_getResourceText('common');
  869. const defaultCss = GM_getResourceText('defaultCss');
  870. //const icomoonex = GM_getResourceText('icomoonex');
  871. //const AllCss = animate + common + defaultCss + icomoonex;
  872. const AllCss = animate + common + defaultCss;
  873. const style = document.createElement('style');
  874. style.innerHTML = AllCss;
  875. return document.getElementsByTagName('head')[0].appendChild(style);
  876. }
  877.  
  878. /*-----------------------------------------------点击事件绑定--------------------------------------------------*/
  879.  
  880.  
  881. /*-----------------------------------------------常用API--------------------------------------------------*/
  882.  
  883. let HNAPI = {
  884.  
  885. getMyJson: function (url) {
  886. return new Promise((resolve) => {
  887. GM_xmlhttpRequest({
  888. method: "GET",
  889. url: url,
  890. onload: function (response) {
  891. const res = HNTOOL.strToJson((response || {}).responseText)
  892. resolve(res);
  893. }
  894. });
  895. })
  896. },
  897.  
  898.  
  899. userInfo: function (mid) {
  900.  
  901. Ajax.get({
  902. url: BILIBLI_PATH.api + '/x/space/acc/info',
  903. queryStringsObj: {
  904. mid: mid
  905. },
  906. hasCookies: true,
  907. success: responseText => {
  908.  
  909. var json = JSON.parse(responseText);
  910.  
  911. if (json.code != 0) {
  912.  
  913.  
  914. }
  915. }
  916. });
  917.  
  918. },
  919.  
  920. sendQmsg: function (key, msg) {
  921.  
  922. GM_xmlhttpRequest({
  923. method: "GET",
  924. url: `https://qmsg.zendee.cn/send/${key}?msg=${msg}`,
  925. onload: function (response) {
  926.  
  927. let json = JSON.parse(response.response);
  928. if (json.code == 0) {
  929.  
  930. javaex.tip({
  931. content: "自动动态中奖提醒成功!" + json.reason,
  932. type: "success"
  933. });
  934. } else {
  935. console.log("自动动态中奖提醒失败!" + json.reason);
  936. javaex.tip({
  937. content: "自动动态中奖提醒失败!" + json.reason,
  938. type: "error"
  939. });
  940. }
  941.  
  942. }
  943. });
  944.  
  945. },
  946.  
  947. /**
  948. * 批量关注和拉黑 batchModify
  949. *
  950. * https://api.bilibili.com/x/relation/batch/modify
  951. * @param uid
  952. */
  953.  
  954. batchModify: function (uids, act) {
  955.  
  956.  
  957. Ajax.post({
  958. url: BILIBLI_PATH.api + "/x/relation/batch/modify",
  959. hasCookies: true,
  960. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  961. data: {
  962.  
  963. "fids": uids,
  964. "act": act == undefined ? 1 : act, //1 关注 5 拉黑
  965. "re_src": 151,
  966. csrf: Live_info.csrf_token,
  967. },
  968. success: responseText => {
  969.  
  970. let json = JSON.parse(responseText);
  971.  
  972. if (/^{"code":0/.test(responseText)) {
  973.  
  974. javaex.tip({
  975. content: "执行成功!" + "---关注失败:" + json.data.failed_fids,
  976. type: "success"
  977. });
  978.  
  979. } else {
  980. javaex.tip({
  981. content: "关注失败!" + json.message,
  982. type: "error"
  983. });
  984. }
  985. }
  986. })
  987. },
  988.  
  989.  
  990. /**
  991. * //https://api.bilibili.com/x/relation/modify
  992. *
  993. * @param UID
  994. */
  995. disUserByUid: function (vmid) {
  996.  
  997. Ajax.post({
  998. url: BILIBLI_PATH.api + '/x/relation/modify',
  999. data: {
  1000. fid: parseInt(vmid),
  1001. re_src: 11,
  1002. act: 5,
  1003. jsonp: "jsonp",
  1004. csrf: Live_info.csrf_token,
  1005. },
  1006. hasCookies: true,
  1007. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1008. success: responseText => {
  1009.  
  1010. var json = JSON.parse(responseText);
  1011.  
  1012. if (json.code != 0) {
  1013.  
  1014. console.log("拉黑用户失败uid:" + vmid + " 错误信息" + json.message);
  1015. javaex.tip({
  1016. content: "拉黑用户失败uid:" + vmid + " 错误信息" + json.message,
  1017. type: "error"
  1018. });
  1019.  
  1020. } else {
  1021. console.log("拉黑用户成功 uid:" + vmid);
  1022. javaex.tip({
  1023. content: "拉黑用户成功 uid:" + vmid,
  1024. type: "success"
  1025. });
  1026. }
  1027. }
  1028. });
  1029.  
  1030. },
  1031. /**
  1032. * http://api.bilibili.com/x/web-interface/view
  1033. * @param BV
  1034. * 心跳间隔15秒
  1035. */
  1036. playOneVideo: function (BV, MID) {
  1037.  
  1038. //1.调用点击播放接口 https://api.bilibili.com/x/click-interface/click/web/h5
  1039. Ajax.post({
  1040. url: BILIBLI_PATH.api + "/x/click-interface/click/web/h5",
  1041. hasCookies: true,
  1042. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1043. data: {
  1044.  
  1045. "bvid": BV,
  1046. "part": 1,
  1047. "mid": Live_info.uid,
  1048. "lv": 2,
  1049. "jsonp": "jsonp",
  1050. "type": 3,
  1051. "sub_type": 0
  1052. },
  1053. success: responseText => {
  1054.  
  1055. let json = JSON.parse(responseText);
  1056.  
  1057. if (/^{"code":0/.test(responseText)) {
  1058. //发送一次心跳
  1059. HNAPI.sendHeartbeat(BV, MID);
  1060.  
  1061. } else {
  1062. javaex.tip({
  1063. content: "视频" + data.bvid + "播放失败!" + json.message,
  1064. type: "error"
  1065. });
  1066. }
  1067. }
  1068. })
  1069.  
  1070.  
  1071. },
  1072.  
  1073. //上报视频播放心跳(web端)
  1074. /**
  1075. * http://api.bilibili.com/x/click-interface/web/heartbeat
  1076. * @param json
  1077. */
  1078. sendHeartbeat: function (bvid, MID) {
  1079.  
  1080. Ajax.post({
  1081. url: BILIBLI_PATH.api + "/x/click-interface/web/heartbeat",
  1082. hasCookies: true,
  1083. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1084. //aid=756988764&bvid=BV1wr4y1P782&cid=304166326&page=1
  1085. data: {
  1086. "bvid": bvid,
  1087. "type": 3,
  1088. "dt": 2,
  1089. "played_time": HNTOOL.random(12, 40),
  1090. "realtime": HNTOOL.random(12, 40),
  1091. "play_type": 0
  1092. },
  1093. success: responseText => {
  1094.  
  1095. if (/^{"code":0/.test(responseText) && MID != BiliData.author_uid) {
  1096.  
  1097. javaex.tip({
  1098. content: "视频BV" + bvid + "播放一次!",
  1099. type: "success"
  1100. });
  1101. }
  1102. }
  1103. })
  1104.  
  1105. },
  1106.  
  1107. //获取up所有投稿视频
  1108. /**
  1109. * https://api.bilibili.com/x/space/arc/search?mid=99439379&ps=30&tid=0&pn=1&keyword=&order=pubdate&jsonp=jsonp
  1110. * @param mid
  1111. */
  1112. getUpAllBV: function (mid, pn, ps) {
  1113. ps = (ps === undefined ? 30 : ps); // a默认值为1
  1114. Ajax.get({
  1115. url: BILIBLI_PATH.api + '/x/space/arc/search',
  1116. queryStringsObj: {
  1117. mid: mid,
  1118. tid: 0,
  1119. order: 'pubdate',
  1120. jsonp: 'jsonp',
  1121. pn: pn,
  1122. ps: ps
  1123. },
  1124. hasCookies: true,
  1125. success: responseText => {
  1126.  
  1127. var json = JSON.parse(responseText);
  1128.  
  1129. if (json.code != 0) {
  1130.  
  1131. javaex.tip({
  1132. content: "获取up所有投稿视频失败!" + json.message,
  1133. type: "success"
  1134. });
  1135.  
  1136. } else {
  1137. BiliData.BVList = json.data.list.vlist;
  1138.  
  1139. }
  1140. }
  1141. });
  1142.  
  1143. },
  1144.  
  1145.  
  1146. /**
  1147. *
  1148. * @param path
  1149. * @param data
  1150. * @param saveObj
  1151. * @param Func
  1152. */
  1153. publicGet: function (path, queryStringsObj) {
  1154.  
  1155. if (typeof (queryStringsObj) != "undefined") {
  1156. queryStringsObj = {};
  1157. }
  1158. Ajax.get({
  1159. url: BILIBLI_PATH.api + path,
  1160. queryStringsObj: queryStringsObj,
  1161. hasCookies: true,
  1162. success: responseText => {
  1163.  
  1164. let json = JSON.parse(responseText);
  1165. if (chackCode(json.code) && json.code == 0) {
  1166.  
  1167. return json.data;
  1168. }
  1169.  
  1170. return false;
  1171.  
  1172. }
  1173. })
  1174.  
  1175. },
  1176.  
  1177. /**
  1178. * 导航栏用户信息
  1179. */
  1180. getUserNav: async function () {
  1181.  
  1182. GM_xmlhttpRequest({
  1183. method: "GET",
  1184. url: BILIBLI_PATH.api + "/x/web-interface/nav",
  1185. //timeout:3000,
  1186. onload: function (response) {
  1187.  
  1188. let json = JSON.parse(response.response);
  1189. console.log(json);
  1190. BiliData.login_code = json.code;
  1191. BiliData.login_message = json.message;
  1192. BiliData.LoginData = json.data;
  1193.  
  1194. }
  1195. });
  1196.  
  1197. },
  1198.  
  1199. /**
  1200. * 获取某up详细信息
  1201. * http://api.bilibili.com/x/web-interface/card
  1202. */
  1203. getUpCard: function (mid) {
  1204.  
  1205. Ajax.get({
  1206. url: BILIBLI_PATH.api + '/x/web-interface/card',
  1207. queryStringsObj: {
  1208. mid: mid,
  1209. photo: false
  1210. },
  1211. hasCookies: true,
  1212. success: responseText => {
  1213.  
  1214. var json = JSON.parse(responseText);
  1215.  
  1216. if (json.code != 0) {
  1217.  
  1218. javaex.tip({
  1219. content: "查询失败!" + json.message,
  1220. type: "success"
  1221. });
  1222. return false;
  1223. } else {
  1224. BiliData.upCard = json;
  1225.  
  1226. }
  1227.  
  1228.  
  1229. }
  1230. })
  1231.  
  1232. },
  1233.  
  1234. /**
  1235. *
  1236. * @param uid 用户uid
  1237. * @param ps 每页视频个数 默认30个
  1238. * @param pn 第几页
  1239. */
  1240. getUpAllVideo: function (uid, ps, pn) {
  1241.  
  1242. },
  1243. getChallenge: async function () {
  1244.  
  1245.  
  1246. },
  1247. /**
  1248. * 硬币记录
  1249. * @returns {Promise<void>}
  1250. */
  1251. getCoinLog: async function () {
  1252.  
  1253. GM_xmlhttpRequest({
  1254. method: "GET",
  1255. url: BILIBLI_PATH.api + "/x/member/web/coin/log",
  1256. //url: "http://api.bilibili.com/x/member/web/coin/log",
  1257. onload: function (response) {
  1258.  
  1259. let json = JSON.parse(response.response);
  1260. if (json.code == 0) {
  1261.  
  1262. console.log("硬币记录" + json);
  1263. BiliData.CoinLog = json.data;
  1264.  
  1265. return true;
  1266. }
  1267.  
  1268. }
  1269. });
  1270. },
  1271. /**
  1272. * 未读消息数 http://api.bilibili.com/x/msgfeed/unread
  1273. * @returns {Promise<void>}
  1274. */
  1275. getUnread: async function () {
  1276.  
  1277. Ajax.get({
  1278. url: BILIBLI_PATH.api + "/x/msgfeed/unread",
  1279. hasCookies: true,
  1280. success: responseText => {
  1281.  
  1282. let json = JSON.parse(responseText);
  1283. if (chackCode(json.code) && json.code == 0) {
  1284.  
  1285. BiliData.Unread = json.data;
  1286. showUnreadMsg();
  1287. }
  1288.  
  1289. return false;
  1290.  
  1291. }
  1292. })
  1293.  
  1294. /* GM_xmlhttpRequest({
  1295. method: "GET",
  1296. url: BILIBLI_PATH.api + "/x/msgfeed/unread",
  1297. onload: function (response) {
  1298.  
  1299. let json = JSON.parse(response.response);
  1300.  
  1301. if (chackCode(json.code) && json.code == 0) {
  1302.  
  1303. BiliData.Unread = json.code;
  1304. showUnreadMsg();
  1305.  
  1306. }
  1307.  
  1308. }
  1309. });*/
  1310. },
  1311. /**
  1312. *
  1313. * @param type reply:回复我的 at @我的
  1314. */
  1315. getMsgfeed: function (type) {
  1316. Ajax.get({
  1317. url: BILIBLI_PATH.api + '/x/msgfeed/' + type,
  1318. queryStringsObj: {
  1319. build: 0,
  1320. mobi_app: 'web'
  1321. },
  1322. hasCookies: true,
  1323. success: responseText => {
  1324.  
  1325. var json = JSON.parse(responseText);
  1326.  
  1327. if (json.code != 0 || !json.data.cursor.is_end || json.data.items == null) {
  1328. return false;
  1329. } else {
  1330. chackAtMsg(json.data.items);
  1331.  
  1332. return true;
  1333. }
  1334.  
  1335.  
  1336. }
  1337. })
  1338.  
  1339. },
  1340.  
  1341. /** 未读消息数 http://api.bilibili.com/x/space/arc/search?mid=99439379&pn=1&ps=5
  1342. * @returns {Promise<void>}
  1343. */
  1344. getUnrewad: async function () {
  1345.  
  1346. GM_xmlhttpRequest({
  1347. method: "GET",
  1348. data: {
  1349. "mid": 99439379,
  1350. "pn": 1,
  1351. "ps": 5,
  1352. },
  1353. url: BILIBLI_PATH.api + "/x/space/arc/search",
  1354. onload: function (response) {
  1355.  
  1356. let json = JSON.parse(response.response);
  1357. if (json.code == 0) {
  1358.  
  1359. BiliData.Video = json.data;
  1360. console.log("未读消息数" + json);
  1361. }
  1362.  
  1363. }
  1364. });
  1365. },
  1366.  
  1367. /** 动态评论区点赞 https://api.bilibili.com/x/v2/reply/action
  1368. * @param {number} oid
  1369. * @param {nbumber} rpid
  1370. * @param {number} action
  1371. * @returns {Promise<void>}
  1372. * type: 11
  1373. * ordering: heat
  1374. * jsonp: jsonp
  1375. * csrf: 54a******* CSRF Token(位于cookie)
  1376. */
  1377.  
  1378. likeInDynamicComments: async function (oid, rpid, action) {
  1379.  
  1380.  
  1381. Ajax.post({
  1382. url: BILIBLI_PATH.api + "/x/v2/reply/action",
  1383. hasCookies: true,
  1384. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1385. data: {
  1386. "oid": oid,
  1387. "type": 11,
  1388. "rpid": rpid,
  1389. "action": action,
  1390. "ordering": "heat",
  1391. "jsonp": "jsonp",
  1392. "csrf": Live_info.csrf_token,
  1393. },
  1394. success: responseText => {
  1395.  
  1396. if (/^{"code":0/.test(responseText)) {
  1397.  
  1398. BiliData.replyAction = JSON.parse(responseText);
  1399. console.log("点赞成功!" + responseText);
  1400. }
  1401. }
  1402. })
  1403.  
  1404. }
  1405.  
  1406.  
  1407. }
  1408.  
  1409. /*-----------------------------------------------常用工具函数--------------------------------------------------*/
  1410.  
  1411.  
  1412. let HNTOOL = {
  1413.  
  1414. split_array: function (arr, len) {
  1415.  
  1416. let arr_length = arr.length;
  1417. let newArr = [];
  1418. for (let i = 0; i < arr_length; i += len) {
  1419. newArr.push(arr.slice(i, i + len));
  1420. }
  1421. return newArr;
  1422. },
  1423. strToJson: function (params) {
  1424. const isJSON = (str => {
  1425. if (typeof str === 'string') {
  1426. try {
  1427. const obj = JSON.parse(str);
  1428. return typeof obj === 'object' ? obj : false
  1429. } catch (_) {
  1430. console.log(str);
  1431. return false;
  1432. }
  1433. } else {
  1434. console.log(`${str}\nIt is not a string!`);
  1435. return false;
  1436. }
  1437. })(params);
  1438. return isJSON ? isJSON : {}
  1439. },
  1440.  
  1441. chackAtMsg: function () {
  1442.  
  1443. let config = HNTOOL.getConfig();
  1444. if (config.qmsg_checked == true && config.qmsg_key) {
  1445.  
  1446. document.getElementById("getAtMsg").click();
  1447.  
  1448. }
  1449.  
  1450. },
  1451.  
  1452. cssChecked: function (id, dom) {
  1453.  
  1454. dom == true ? $(id).attr("checked", true) : $(id).removeProp("checked");
  1455.  
  1456.  
  1457. },
  1458. getConfig: function () {
  1459.  
  1460. let CONFIG = JSON.parse(localStorage.getItem(`HN_SETUP_CONFIG`));
  1461.  
  1462. if (CONFIG == null) {
  1463. CONFIG = HN_SETUP_CONFIG;
  1464. }
  1465.  
  1466. return CONFIG;
  1467. },
  1468.  
  1469. /**
  1470. * 获取cookie 中某个键对应的值
  1471. * @param name
  1472. */
  1473.  
  1474. getCookie: function (name) {
  1475. let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  1476. if (arr != null) return unescape(arr[2]);
  1477. return false;
  1478. },
  1479. /**
  1480. * 得到一个字符串数组的中随机一个
  1481. * @param {List} list
  1482. */
  1483. getRandomWordOfList: function (list) {
  1484. var L = list.length;
  1485. var i = Math.ceil(Math.random() * L);
  1486.  
  1487. return list[i];
  1488. },
  1489. random: function (min, max) {
  1490.  
  1491. return Math.floor(Math.random() * (max - min)) + min;
  1492. },
  1493.  
  1494. Sleep: function (ms) {
  1495. return new Promise(resolve => setTimeout(() => resolve('sleep'), ms));
  1496. }
  1497.  
  1498. }
  1499.  
  1500. let errorMsg = {
  1501. "-1": "应用程序不存在或已被封禁!",
  1502. "-2": "Access Key错误!",
  1503. "-3": "API校验密匙错误!",
  1504. "-4": "调用方对该Method没有权限!",
  1505. "-101": "账号未登录!",
  1506. "-102": "账号被封停!",
  1507. "-103": "积分不足!",
  1508. "-104": "硬币不足!",
  1509. "-105": "验证码错误!",
  1510. "-106": "账号非正式会员或在适应期!",
  1511. "-107": "应用不存在或者被封禁!",
  1512. "-108": "未绑定手机!",
  1513. "-109": "未知!",
  1514. "-110": "未绑定手机!",
  1515. "-111": "csrf 校验失败!",
  1516. "-112": "系统升级中!",
  1517. "-113": "账号尚未实名认证!",
  1518. "-114": "请先绑定手机!",
  1519. "-115": "请先完成实名认证!",
  1520. "-304": "木有改动!",
  1521. "-307": "撞车跳转!",
  1522. "-400": "请求错误!",
  1523. "-401": "未认证!",
  1524. "-403": "访问权限不足!",
  1525. "-404": "啥都木有!",
  1526. }
  1527.  
  1528. /*-----------------------------------------------CODE 统一检查--------------------------------------------------*/
  1529. /**
  1530. *
  1531. * @param code
  1532. * @constructor
  1533. */
  1534. let chackCode = function (code) {
  1535.  
  1536. let emsg = errorMsg[code + ""];
  1537. if (emsg != null) {
  1538. javaex.tip({content: emsg, type: "error"});
  1539.  
  1540. return false;
  1541. }
  1542.  
  1543. return true;
  1544. }
  1545.  
  1546.  
  1547. /*-----------------------------------------------localStorage封装 (本地存储信息)--------------------------------------------------*/
  1548. //javaex.setLocalStorage(key, value); var str = javaex.getLocalStorage(key); javaex.deleteLocalStorage(key);
  1549.  
  1550. /*window.onbeforeunload = function() {
  1551. if (!canLeavePage()) {
  1552. return ('确认离开当前页面吗?未保存的数据将会丢失!');
  1553. }
  1554. };*/
  1555.  
  1556.  
  1557. /**
  1558. * Ajax请求对象
  1559. */
  1560. const Ajax = (() => {
  1561. /**
  1562. * 检查options是否符合要求
  1563. * @param {object} options
  1564. * @returns {boolean}
  1565. */
  1566. function checkOptions(options) {
  1567. let result = false;
  1568. if (typeof options !== 'object') {
  1569. console.warn('类型错误: typeof Options !== Object');
  1570. return result;
  1571. } else {
  1572. if (typeof options.url !== 'string') {
  1573. console.warn('类型错误: typeof Link !== Strings');
  1574. return result;
  1575. } else {
  1576. const reg = /^https?:\/\/(?:\w+\.?)+(?:\/.*)*\/?$/i;
  1577. if (!reg.test(options.url)) {
  1578. console.warn('url字符串须为完整http链接');
  1579. return result;
  1580. }
  1581. result = true;
  1582. }
  1583. }
  1584. return result;
  1585. }
  1586.  
  1587. /**
  1588. * 对象转URL编码
  1589. * @param {object} data
  1590. */
  1591. function objToURLCode(data) {
  1592. var _result = [];
  1593. for (var key in data) {
  1594. var value = data[key];
  1595. if (value instanceof Array) {
  1596. value.forEach(function (_value) {
  1597. _result.push(key + "=" + _value);
  1598. });
  1599. } else {
  1600. _result.push(key + '=' + value);
  1601. }
  1602. }
  1603. return _result.join('&');
  1604. }
  1605.  
  1606. /**
  1607. * 请求
  1608. * @param {string} method
  1609. * @param {object} options
  1610. */
  1611. function request(method, options) {
  1612. if (checkOptions(options)) {
  1613. let xhr = new XMLHttpRequest();
  1614. const {url: _url, queryStringsObj, data, dataType, hasCookies} = options
  1615. , url = typeof queryStringsObj === 'object' ?
  1616. _url + '?' + objToURLCode(queryStringsObj) : _url;
  1617. switch (method) {
  1618. case 'GET':
  1619. xhr.open("GET", url);
  1620. break;
  1621. case 'POST':
  1622. xhr.open("POST", url);
  1623. xhr.setRequestHeader('Content-Type', dataType);
  1624. break;
  1625. default:
  1626. break;
  1627. }
  1628. if (hasCookies) xhr.withCredentials = true;
  1629. xhr.timeout = 3000;
  1630. xhr.addEventListener('load', () => {
  1631. if (xhr.status === 200) {
  1632. options.success(xhr.responseText)
  1633. } else {
  1634. console.error(`status:${xhr.status}`);
  1635. options.success(`{"code":${xhr.status},"msg":"频繁访问"}`);
  1636. }
  1637. })
  1638. xhr.addEventListener('error', () => {
  1639. console.error('ajax请求出错')
  1640. options.success('{"code":-1,"msg":"ajax请求出错"}');
  1641. })
  1642. xhr.addEventListener('timeout', () => {
  1643. console.error('请求超时')
  1644. options.success('{"code":-1,"msg":"请求超时"}');
  1645. })
  1646. switch (method) {
  1647. case 'GET':
  1648. xhr.send()
  1649. break;
  1650. case 'POST':
  1651. xhr.send((/urlencoded/.test(dataType)) ? objToURLCode(data) : data)
  1652. break;
  1653. default:
  1654. break;
  1655. }
  1656. }
  1657. }
  1658.  
  1659. return {
  1660. /**
  1661. * 发送Get请求
  1662. * @param {Object} options
  1663. */
  1664. get(options) {
  1665. request("GET", options);
  1666. },
  1667. /**
  1668. * 发送Post请求
  1669. * @param {object} options
  1670. */
  1671. post(options) {
  1672. request("POST", options);
  1673. }
  1674. }
  1675. })()