-哔哩猫-(试用版)

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

目前为 2021-07-20 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/422731/952281/-%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.8.8
  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.  
  35.  
  36. GM_addStyle(
  37. `
  38.  
  39. #switch-qsmg:before {
  40. content: "开关";
  41. letter-spacing: 16px;
  42. top: 4px;
  43. left: 10px;
  44. }
  45. #left_navbar{
  46. z-index: 1000;
  47. position: absolute;
  48. top: 100px;
  49. left: 5px;
  50. }
  51. button[hnBtn="btn_open"] {
  52. z-index: 1001;
  53. z-index: 1000px;
  54. position: absolute;
  55. top: 58px;
  56. left: 220px;
  57. }
  58. .javaex-panel.javaex-panel-right.javaex-animated-zoom-in {
  59. top: 60px;
  60. }
  61. .javaex-menu-container {
  62. border: 1px solid #eee;
  63. }
  64. .javaex-panel-box p {
  65. text-align: center;
  66. background: #fb7299;
  67. }
  68. .fontbold{
  69. color: #00a1d6;
  70. font-weight: bold;
  71. cursor: pointer;
  72. }
  73. `
  74. );
  75.  
  76.  
  77. let HN_SETUP_CONFIG = {
  78.  
  79. qmsg_key: null, //后期改为kull 存储到本地
  80. qmsg_checked: false,
  81.  
  82.  
  83. }
  84.  
  85. let Live_info = {
  86. room_id: undefined,
  87. uid: undefined,
  88. blocked: undefined,
  89. csrf_token: undefined,
  90. SESSDATA: undefined,
  91. visit_id: undefined,
  92. rnd: undefined,
  93. ruid: undefined,
  94. uname: undefined,
  95. user_level: undefined,
  96. ruid: undefined,
  97. };
  98.  
  99. let BILIBLI_PATH = {
  100.  
  101. "live": "https://api.live.bilibili.com",
  102. "passport": "https://passport.bilibili.com",
  103. "api": "https://api.bilibili.com",
  104. "video": "https://www.bilibili.com/video/",
  105. "single_unread": "http://api.vc.bilibili.com/"
  106. }
  107.  
  108. let BILIBILI_URL = {
  109. // 导航栏用户信息
  110. "nav": BILIBLI_PATH.api + "/x/web-interface/nav",
  111. }
  112.  
  113. let BiliData = {
  114.  
  115. this_uid: window.location.href.split("/")[3], //当前页面uid
  116. author_uid: 99439379,
  117. login_code: null,
  118. login_message: "",
  119. LoginData: {},
  120. CoinLog: {},
  121. Unread: null,
  122. Video: {},
  123. replyAction: {},
  124. upCard: {},
  125. BVList: [],
  126. }
  127.  
  128. window.onload = function() {
  129.  
  130.  
  131. //界面显示
  132. init();
  133.  
  134.  
  135. }
  136.  
  137.  
  138. function init() {
  139.  
  140. Live_info.csrf_token = HNTOOL.getCookie("bili_jct");
  141. Live_info.uid = HNTOOL.getCookie("DedeUserID");
  142. Live_info.SESSDATA = HNTOOL.getCookie("SESSDATA");
  143.  
  144. addStyle();
  145. addSetPage();
  146.  
  147. HNTOOL.chackAtMsg();
  148.  
  149. $("#getCoinLog").bind("click", async function() {
  150.  
  151.  
  152. if (HNAPI.getCoinLog()) {
  153.  
  154. await HNTOOL.Sleep(500);
  155. let html = '';
  156. html += '<div class="javaex-panel-box" style="width: 250px;">';
  157. html += ' <ul>';
  158. html += ` <p style="color: #FFF;">硬币使用记录</p>`;
  159.  
  160. BiliData.CoinLog.list.forEach(function(item) {
  161.  
  162. let BV = item.reason.replace(/[^a-z0-9]+/ig, "");
  163. if (BV.indexOf("BV") != -1) {
  164. html += `<li><a href="${BILIBLI_PATH.video}${BV}">${item.reason}${item.delta}币 ${item.time}</a> </li> `;
  165. }
  166. html += `<li>${item.reason}${item.delta}币 ${item.time}</li> `;
  167.  
  168.  
  169. });
  170. html += ' <hr class="javaex-divider"></hr>';
  171. html += ' </ul>';
  172. html += '</div>';
  173.  
  174. javaex.panel(this, {
  175. position: "right",
  176. //offsetTop: "104",
  177. content: html
  178. });
  179. javaex.tip({
  180. content: "获取用户成功!",
  181. type: "success"
  182. });
  183.  
  184. } else {
  185. javaex.tip({
  186. content: "获取硬币记录失败,请稍后重试!",
  187. type: "error"
  188. });
  189. }
  190.  
  191.  
  192. });
  193.  
  194. $("#getUnread").bind("click", async function() {
  195.  
  196. javaex.tip({
  197. content: "获取中,请稍候...",
  198. type: "submit"
  199. });
  200. HNAPI.getUnread();
  201.  
  202.  
  203. });
  204.  
  205.  
  206. $("#likeInDynamicComments").bind("click", async function() {
  207.  
  208. let prid = LocalData.get("likeInDynamic_PRID") == null ? "4015599048" : LocalData.get("likeInDynamic_PRID");
  209. let oid = LocalData.get("likeInDynamic_OID") == null ? "108928314" : LocalData.get("likeInDynamic_OID");
  210.  
  211. let html = '';
  212.  
  213. html += '<div style="padding: 10px 10px 10px 0px;">'
  214. html += '<form id="likeInDynamic_form">'
  215. html += ' <div class="javaex-unit clear">'
  216. html += ' <div class="javaex-unit-left"><p class="subtitle required">评论RPID</p></div>'
  217. html += ' <div class="javaex-unit-right">'
  218. html += ' <input type="text" class="javaex-text" data-type="positive_int" error-msg="评论RPID格式错误"'
  219. html += ` id="likeInDynamic_PRID" value=${prid} placeholder="请输入评论RPID"/>`
  220. html += ' </div>'
  221. html += ' </div>'
  222. html += ' <div class="javaex-unit clear">'
  223. html += ' <div class="javaex-unit-left"><p class="subtitle required">OID</p></div>'
  224. html += ' <div class="javaex-unit-right">'
  225. html += ' <input type="text" class="javaex-text" data-type="positive_int" error-msg="OID格式错误"'
  226. html += ` id="likeInDynamic_OID" value=${oid} placeholder="请输入OID"/>`
  227. html += ' </div>'
  228. html += ' </div>'
  229. html += ' <div class="javaex-unit clear tc">'
  230. html +=
  231. ' <input type="button" id="likeInDynamic_no" class="javaex-hover-pulse javaex-btn no " value="取消赞"/>'
  232. html +=
  233. ' <input type="button" id="likeInDynamic_yes" class="javaex-hover-pulse javaex-btn yes" value="点赞"/>'
  234. html += ' </div>'
  235. html += '</form>';
  236. html += '<hr class="javaex-divider"></hr>';
  237. html += '</div>';
  238.  
  239.  
  240. javaex.panel(this, {
  241. position: "right",
  242. content: html
  243. });
  244.  
  245.  
  246. // 监听点击保存按钮事件
  247. $("#likeInDynamic_yes").click(async function() {
  248. // 表单验证函数
  249. if (javaexVerify()) {
  250.  
  251. HNAPI.likeInDynamicComments(+javaex.getSelectVal("#likeInDynamic_OID"), +javaex.getSelectVal(
  252. "#likeInDynamic_PRID"), 1);
  253. await HNTOOL.Sleep(1000);
  254.  
  255. if (BiliData.replyAction.code == 0) {
  256.  
  257. LocalData.set("likeInDynamic_PRID", javaex.getSelectVal("#likeInDynamic_PRID"));
  258. LocalData.set("likeInDynamic_OID", javaex.getSelectVal("#likeInDynamic_OID"));
  259.  
  260. javaex.tip({
  261. content: "评论区点赞成功!",
  262. type: "success"
  263. });
  264. } else {
  265. javaex.tip({
  266. content: "评论区点赞失败!",
  267. type: "error"
  268. });
  269. }
  270. if (BiliData.replyAction.code == 65006) {
  271. javaex.tip({
  272. content: "请勿重复点赞!",
  273. type: "error"
  274. });
  275. }
  276. }
  277. });
  278.  
  279. // 监听点击返回按钮事件
  280. $("#likeInDynamic_no").click(async function() {
  281.  
  282. if (javaexVerify()) {
  283.  
  284. HNAPI.likeInDynamicComments(+javaex.getLocalStorage("#likeInDynamic_OID"), +javaex.getLocalStorage(
  285. "#likeInDynamic_PRID"), 0);
  286. await HNTOOL.Sleep(500);
  287.  
  288. if (BiliData.replyAction.code == 0) {
  289.  
  290. javaex.setLocalStorage("likeInDynamic_PRID", javaex.getSelectVal("#likeInDynamic_PRID"));
  291. javaex.setLocalStorage("likeInDynamic_OID", javaex.getSelectVal("#likeInDynamic_OID"));
  292.  
  293. javaex.tip({
  294. content: "评论区取消点赞成功!",
  295. type: "success"
  296. });
  297. } else {
  298. javaex.tip({
  299. content: "评论区取消点赞失败!",
  300. type: "error"
  301. });
  302. }
  303. if (BiliData.replyAction.code == 65006) {
  304. javaex.tip({
  305. content: "请勿重复取消点赞!",
  306. type: "error"
  307. });
  308. }
  309. }
  310. });
  311.  
  312. });
  313.  
  314. $("#biliUserMsg").bind("click", async function() {
  315.  
  316.  
  317. //刷新信息
  318. HNAPI.getUserNav();
  319. await HNTOOL.Sleep(500);
  320.  
  321. let isLogin = "未登录";
  322. let vipType = "无";
  323. //判断是否成功
  324. if (BiliData.login_code == 0) {
  325.  
  326.  
  327. if (BiliData.LoginData.isLogin) {
  328. isLogin = "已登录";
  329. }
  330.  
  331. if (BiliData.LoginData.vipType == 1) {
  332. vipType = "月度大会员";
  333. } else if (BiliData.LoginData.vipType == 2) {
  334. vipType = "年度大会员";
  335. }
  336.  
  337. let html = '';
  338. html += '<div class="javaex-panel-box" style="width: 250px;">';
  339. html += ' <ul>';
  340. html += ` <p style="color: #FFF;">用户信息</p>`;
  341. html += ` <li><a href="https://account.bilibili.com/account/home">当前用户:${BiliData.LoginData.uname}</a> </li> `;
  342. html += ` <li>用户状态:${isLogin} </li> `;
  343. html += ` <li>用户等级:${BiliData.LoginData.level_info.current_level}</li> `;
  344. html +=
  345. ` <li>升级下一等级需:${BiliData.LoginData.level_info.next_exp - BiliData.LoginData.level_info.current_exp} 经验</li> `;
  346. html += ` <li>UID${BiliData.LoginData.mid} </li> `;
  347. html += ` <li><a href="https://account.bilibili.com/account/coin">硬币:${BiliData.LoginData.money}</a> </li> `;
  348. html += ` <li>节操值:${BiliData.LoginData.moral} </li> `;
  349. html += ` <li>会员:${vipType} </li> `;
  350. html += ' <hr class="javaex-divider"></hr>';
  351. html += ' </ul>';
  352. html += '</div>';
  353.  
  354.  
  355. javaex.panel(this, {
  356. position: "right",
  357. content: html
  358. });
  359.  
  360. javaex.tip({
  361. content: "获取用户成功!",
  362. type: "success"
  363. });
  364.  
  365. } else {
  366. javaex.tip({
  367. content: "获取用户信息失败!",
  368. type: "error"
  369. });
  370. }
  371.  
  372.  
  373. });
  374.  
  375. $("#getAtMsg").bind("click", async function() {
  376.  
  377. if (HNAPI.getMsgfeed("at") && typeof(HNAPI.getMsgfeed("at")) != "undefined") {
  378.  
  379. javaex.tip({
  380. content: "可能中奖了!!!",
  381. type: "success"
  382. });
  383. }
  384. });
  385.  
  386.  
  387. $("#disUser").bind("click", async function() {
  388.  
  389. let html = '';
  390. html += '<div class="javaex-panel-box" style="width: 500px;">';
  391. html += ' <div class="javaex-unit clear">';
  392. html += ' <div class="javaex-unit-left ml-10 mt-10">*UID列表</div>';
  393. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  394. html +=
  395. ' <textarea id="disUser_uidList" class="javaex-desc" placeholder="请填写用户UID,多个用英文逗号,隔开"></textarea>';
  396. html += ' </div>';
  397. html += ' </div>';
  398. html += ' <div class="javaex-unit clear tc">';
  399. html += ' <input type="button" id="disUser_block" class="javaex-btn yes" value="拉黑" />';
  400. html += ' <input type="button" id="disUser_cancelAtt_uid" class="javaex-btn yes" value="UID取关" />';
  401. html += ' <input type="button" id="disUser_cancelAtt_room" class="javaex-btn yes" value="房间号取关" />';
  402. html += ' </div>';
  403. html += '</div>';
  404.  
  405. javaex.panel(this, {
  406. position: "right",
  407. content: html
  408. });
  409.  
  410. let disUser_str;
  411. //拉黑
  412. $("#disUser_block").bind("click", async function() {
  413.  
  414. disUser_str = javaex.getSelectVal("#disUser_uidList");
  415. let disUser_uidList = disUser_str.split(",");
  416. let disUserStr = HNTOOL.split_array(disUser_uidList, 10);
  417.  
  418. for (const vmid of disUserStr) {
  419.  
  420. HNAPI.batchModify(vmid.toString(), 5);
  421. await HNTOOL.Sleep(2000);
  422. }
  423. });
  424. //取关uid
  425. $("#disUser_cancelAtt_uid").bind("click", async function() {
  426. disUser_str = javaex.getSelectVal("#disUser_uidList");
  427. let disUser_uidList = disUser_str.split(",");
  428.  
  429. javaex.tip({
  430. content: "根据uid批量取关开始!!!",
  431. type: "success"
  432. });
  433.  
  434. /*
  435. let disuidList = [];
  436. let PN = 100;
  437. PN = disUser_uidList.length == 1 ? 0 : PN;
  438.  
  439. for (var i = 0; i < PN; i++) {
  440.  
  441. let uidList = await HNAPI.getDisuidList(HNTOOL.getCookie("DedeUserID"), i);
  442. javaex.tip({
  443. content: "获取第" + i + "页黑名单成功!",
  444. type: "success"
  445. });
  446. await HNTOOL.Sleep(1000);
  447.  
  448. if (uidList.length == 0) {
  449. break;
  450. }
  451. if (uidList == null) {
  452. continue;
  453. }
  454.  
  455. for (let disuid of uidList) {
  456. if (disuidList.indexOf(disuid.mid) == -1) {
  457. disuidList.push(disuid.mid + "");
  458. }
  459. }
  460.  
  461.  
  462. } */
  463. let J = 1;
  464.  
  465. for (let uid of disUser_uidList) {
  466.  
  467. /* let uidType = "未在黑名单";
  468. if (disuidList.indexOf(uid) == -1) {
  469.  
  470. await HNAPI.cancelAtt(uid, 2);
  471. } else {
  472.  
  473. await HNAPI.cancelAtt(uid, 6, 116);
  474. uidType = "黑名单用户";
  475. } */
  476. await HNAPI.cancelAtt(uid, 2);
  477.  
  478. javaex.tip({
  479. content: "【UID:" + uid + "】" + "取关成功!(" + (J++) + "/" + disUser_uidList.length + ")",
  480. type: "success"
  481. });
  482. await HNTOOL.Sleep(1000);
  483. }
  484.  
  485.  
  486. alert("根据uid批量取关完成!");
  487.  
  488. /* javaex.alert({
  489. content: "根据uid批量取关完成!",
  490. confirm: function() {
  491.  
  492. //return false;
  493. }
  494. }); */
  495.  
  496. });
  497. //取关room
  498. $("#disUser_cancelAtt_room").bind("click", async function() {
  499.  
  500. javaex.tip({
  501. content: "根据房间号批量取关开始!!!",
  502. type: "success"
  503. });
  504.  
  505. disUser_str = javaex.getSelectVal("#disUser_uidList");
  506. let disUser_roomList = disUser_str.split(",");
  507. /* let disuidList = [];
  508. let PN = 100;
  509. PN = disUser_roomList.length == 1 ? 0 : PN;
  510.  
  511. for (var i = 0; i < PN; i++) {
  512.  
  513. let uidList = await HNAPI.getDisuidList(HNTOOL.getCookie("DedeUserID"), i);
  514. javaex.tip({
  515. content: "获取第" + i + "页黑名单成功!",
  516. type: "success"
  517. });
  518. await HNTOOL.Sleep(1000);
  519.  
  520. if (uidList.length == 0) {
  521. break;
  522. }
  523. if (uidList == null) {
  524. continue;
  525. }
  526.  
  527. for (let disuid of uidList) {
  528.  
  529. if (disuidList.indexOf(disuid.mid) == -1) {
  530. disuidList.push(disuid.mid);
  531. }
  532.  
  533. }
  534.  
  535.  
  536. } */
  537. let J = 1;
  538. for (let room of disUser_roomList) {
  539.  
  540. let uid = await HNAPI.getRoomMsg(room);
  541.  
  542. await HNTOOL.Sleep(1000);
  543.  
  544. if (uid == false) {
  545. javaex.tip({
  546. content: "uid查询失败跳过!",
  547. type: "error"
  548. });
  549. continue;
  550. }
  551. /* let uidType = "未在黑名单";
  552. if (disuidList.indexOf(uid) == -1) {
  553.  
  554. await HNAPI.cancelAtt(uid, 2);
  555. } else {
  556.  
  557. await HNAPI.cancelAtt(uid, 6, 116);
  558. uidType = "黑名单用户";
  559. } */
  560. await HNAPI.cancelAtt(uid, 2);
  561.  
  562. javaex.tip({
  563. content: "Room:" + room + "-【UID:" + uid + "】" + "取关成功!(" + (J++) + "/" + disUser_roomList.length +
  564. ")",
  565. type: "success"
  566. });
  567. await HNTOOL.Sleep(1000);
  568.  
  569.  
  570. }
  571. alert("根据房间号批量取关完成!");
  572. /* javaex.alert({
  573. content: ,
  574. confirm: function() {
  575.  
  576. return false;
  577. }
  578. }); */
  579.  
  580. });
  581.  
  582. });
  583.  
  584. $("#getNeetCookie").bind("click", async function() {
  585.  
  586. let html = '';
  587. html += '<div class="javaex-panel-box" style="width: 750px;">';
  588. html += ' <div class="javaex-unit clear">';
  589. html += ' <div class="javaex-unit-left ml-10 mt-10">*cookie</div>';
  590. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  591. html +=
  592. ' <textarea id="neetCookie" class="javaex-desc" placeholder="获取需要的cookie,注意需要取消掉application->cookie>SESSDATA httpOnly 的对钩"></textarea>';
  593. html += ' </div>';
  594. html += ' </div>';
  595. html += ' <div class="javaex-unit clear tc">';
  596. html += ' <input type="button" id="getCookie_type1" class="javaex-btn yes" value="方式一" />';
  597. html += ' <input type="button" id="getCookie_type2" class="javaex-btn yes" value="方式二" />';
  598. html += ' <input type="button" id="getCookie_type3" class="javaex-btn yes" value="方式三" />';
  599. html += ' <input type="button" id="getCookie_copy" class="javaex-btn yes" value="复制" />';
  600. html += ' </div>';
  601. html += '</div>';
  602.  
  603. javaex.panel(this, {
  604. position: "right",
  605. content: html
  606. });
  607.  
  608. $('#getCookie_copy').bind('click', function() {
  609.  
  610. HNTOOL.copyText("neetCookie");
  611.  
  612. });
  613.  
  614. Live_info.csrf_token = HNTOOL.getCookie("bili_jct");
  615. Live_info.uid = HNTOOL.getCookie("DedeUserID");
  616. Live_info.SESSDATA = HNTOOL.getCookie("SESSDATA");
  617.  
  618.  
  619. $("#getCookie_type1").bind("click", async function() {
  620.  
  621. var cookie01 = "DedeUserID=" + Live_info.uid + "; SESSDATA=" + Live_info.SESSDATA.replace(/%25/g, "%") +
  622. "; bili_jct=" + Live_info.csrf_token +
  623. "; "
  624. document.getElementById("neetCookie").value = cookie01;
  625.  
  626. });
  627. $("#getCookie_type3").bind("click", async function() {
  628.  
  629. var cookie01 = "DedeUserID=" + Live_info.uid + "; SESSDATA=" + Live_info.SESSDATA.replace(/%25/g, "%%") +
  630. "; bili_jct=" + Live_info.csrf_token +
  631. "; "
  632. document.getElementById("neetCookie").value = cookie01;
  633.  
  634. });
  635.  
  636. $("#getCookie_type2").bind("click", async function() {
  637.  
  638. var cookie02 = Live_info.uid + "\n" + Live_info.SESSDATA.replace(/%25/g, "%") + "\n" + Live_info.csrf_token;
  639. document.getElementById("neetCookie").value = cookie02;
  640. });
  641.  
  642. });
  643.  
  644. $("#arrUnique").bind("click", async function() {
  645.  
  646. let html = '';
  647. html += '<div class="javaex-panel-box" style="width: 500px;">';
  648. html += ' <div class="javaex-unit clear">';
  649. html += ' <div id="arrNub" class="javaex-unit-left ml-10 mt-10">*数组0</div>';
  650. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  651. html += ' <textarea id="arrUnique_str" class="javaex-desc" placeholder="请填写,多个用英文逗号,隔开"></textarea>';
  652. html += ' </div>';
  653. html += ' </div>';
  654. html += ' <div class="javaex-unit clear tc">';
  655. html += ' <input type="button" id="arrUnique_beg" class="javaex-btn yes" value="去重" />';
  656. //html += ' <input type="button" id="arrUnique_copy" class="javaex-btn yes" value="粘贴" />';
  657. html += ' <input type="button" id="arrUnique_copy" class="javaex-btn yes" value="复制" />';
  658. html += ' </div>';
  659. html += '</div>';
  660.  
  661. javaex.panel(this, {
  662. position: "right",
  663. content: html
  664. });
  665.  
  666. $('#arrUnique_str').bind('input propertychange', function() {
  667.  
  668. $('#arrNub').text("*数组" + $(this).val().split(",").length);
  669.  
  670. });
  671. $('#arrUnique_copy').bind('click', function() {
  672.  
  673. HNTOOL.copyText("arrUnique_str");
  674.  
  675. });
  676.  
  677.  
  678.  
  679.  
  680. $("#arrUnique_beg").bind("click", async function() {
  681.  
  682. let arrUnique_str = javaex.getSelectVal("#arrUnique_str");
  683. let arrUnique_uidList = arrUnique_str.split(",");
  684.  
  685. let new_arr = HNTOOL.arrUnique(arrUnique_uidList);
  686.  
  687. document.getElementById("arrUnique_str").value = new_arr.toString();
  688.  
  689. $('#arrNub').text("*数组" + new_arr.length);
  690.  
  691. });
  692.  
  693. });
  694.  
  695. $("#batchFollow").bind("click", async function() {
  696.  
  697. var thisUPName = $("#h-name").text();
  698.  
  699.  
  700. let html = '';
  701. html += '<div class="javaex-panel-box" style="width: 600px;">';
  702. html += ' <div class="javaex-unit clear">';
  703. html += ' <div id="followNub" class="javaex-unit-left ml-10 mt-10">*关注列表0</div>';
  704. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  705. html +=
  706. ' <textarea id="batchFollow_uidList" class="javaex-desc" placeholder="1.请填写用户UID,多个用英文逗号,隔开,此功能会强制关注,解决账号异常不能关注问题!!!2.爬取当前用户的高质量关注"></textarea>';
  707. html += ' </div>';
  708. html += ' </div>';
  709. html += ' <div class="javaex-unit clear tc" >';
  710. html += ' <input type="button" id="batchFollow_beg" class="javaex-btn yes" value="开始" />';
  711. html += ' <input type="button" id="crawler_follow" class="javaex-btn yes tc" value="爬取关注" />';
  712. html += ` <input type="button" id="Follow_thisUp" class="javaex-btn yes tc" value="关注${thisUPName}" />`;
  713. html += ` <input type="button" id="disFollow_thisUp" class="javaex-btn yes tc" value="拉黑${thisUPName}" /> `;
  714. html += ' </div>';
  715. html += '</div>';
  716.  
  717. javaex.panel(this, {
  718. position: "right",
  719. content: html
  720. });
  721.  
  722. $('#batchFollow_uidList').bind('input propertychange', function() {
  723.  
  724. $('#followNub').text("*关注列表" + $(this).val().split(",").length);
  725.  
  726. });
  727.  
  728. $("#disFollow_thisUp").bind("click", async function() {
  729.  
  730. HNAPI.batchModify(BiliData.this_uid, 5);
  731.  
  732. });
  733.  
  734. $("#Follow_thisUp").bind("click", async function() {
  735.  
  736. HNAPI.batchModify(BiliData.this_uid);
  737.  
  738. });
  739.  
  740. $("#batchFollow_beg").bind("click", async function() {
  741.  
  742. let mid_str = javaex.getSelectVal("#batchFollow_uidList");
  743. mid_list = mid_str.split(",");
  744.  
  745. let mid_Lists = HNTOOL.split_array(mid_list, 15);
  746. for (const mids of mid_Lists) {
  747.  
  748. HNAPI.batchModify(mids.toString());
  749. await HNTOOL.Sleep(8000);
  750. }
  751.  
  752. alert("关注完成!")
  753.  
  754. });
  755.  
  756. $("#crawler_follow").bind("click", async function() {
  757.  
  758. //x/space/myinfo
  759. let myinfoData = await HNAPI.getMyinfo();
  760. await HNAPI.getUpCard(myinfoData.mid);
  761. await HNTOOL.Sleep(1000);
  762. let len = parseInt(BiliData.upCard.data.card.attention / 20);
  763. let followData = [];
  764.  
  765. for (let i = 0; i < len; i++) {
  766. if (BiliData.upCard.code != 0) {
  767. javaex.tip({
  768. content: `爬取关注出现异常 终止爬取!{BiliData.upCard.message}`,
  769. type: "error"
  770. });
  771. break;
  772. }
  773.  
  774. javaex.tip({
  775. content: `正在爬取` + myinfoData.mid + `的` + i + `页的关注!!!`,
  776. type: "success"
  777. });
  778.  
  779. let followList = await HNAPI.getMyFollow(myinfoData.mid, i);
  780. if (followList != null) {
  781. for (const fl of followList.list) {
  782.  
  783. if (fl.official_verify.type != 1 || fl.vip.vipType == 0) {
  784. continue;
  785. }
  786.  
  787. followData.push(fl.mid);
  788.  
  789. }
  790. }
  791.  
  792.  
  793. await HNTOOL.Sleep(3000);
  794. }
  795.  
  796. document.getElementById("batchFollow_uidList").value = followData.toString();
  797.  
  798. });
  799.  
  800.  
  801. });
  802.  
  803. $("#batchTargetMedal").bind("click", async function() {
  804.  
  805.  
  806. let html = '';
  807. html += '<div class="javaex-panel-box" style="width: 600px;">';
  808. html += ' <div class="javaex-unit clear">';
  809. html += ' <div id="targetNub" class="javaex-unit-left ml-10 mt-10">*房间列表0</div>';
  810. html += ' <div class="javaex-unit-right mr-10 mt-10">';
  811. html +=
  812. ' <textarea id="batchTargetMedal_roomlist" class="javaex-desc" placeholder="特别注意:请填写用户真实房间号,多个用英文逗号,隔开!!"></textarea>';
  813. html += ' </div>';
  814. html += ' </div>';
  815. html += ' <div class="javaex-unit clear tc" >';
  816. html += ' <input type="button" id="batchTargetMedal_beg" class="javaex-btn yes" value="开始" />';
  817. html += ' </div>';
  818. html += '</div>';
  819.  
  820. javaex.panel(this, {
  821. position: "right",
  822. content: html
  823. });
  824.  
  825. $('#batchTargetMedal_roomlist').bind('input propertychange', function() {
  826.  
  827. $('#targetNub').text("*房间列表" + $(this).val().split(",").length);
  828.  
  829. });
  830.  
  831. $("#batchTargetMedal_beg").bind("click", async function() {
  832.  
  833. let room_str = javaex.getSelectVal("#batchTargetMedal_roomlist");
  834. let room_list = room_str.split(",");
  835.  
  836.  
  837. for (const room of room_list) {
  838.  
  839. let uid = await HNAPI.getRoomMsg(room);
  840. await HNTOOL.Sleep(500);
  841.  
  842. if (uid == false) {
  843.  
  844. javaex.tip({
  845. content: room + "获取勋章失败!",
  846. type: "error"
  847. });
  848.  
  849. continue;
  850. }
  851.  
  852. let result = await HNAPI.getFansMedalInfo(uid, room);
  853.  
  854. if (result) {
  855. javaex.tip({
  856. content: room + "勋章已经存在!",
  857. type: "success"
  858. });
  859. continue;
  860. }
  861. //获取包裹列表
  862. let giftRes = await HNAPI.getGiftList(room);
  863.  
  864. if (giftRes == false) {
  865.  
  866. continue;
  867. }
  868.  
  869. let bag_id = null;
  870.  
  871. for (let gr of giftRes) {
  872.  
  873. if (gr.gift_id == 3) {
  874.  
  875. bag_id = gr.bag_id;
  876. break;
  877. }
  878.  
  879. }
  880. if (bag_id != null) {
  881.  
  882. await HNAPI.bagSendGift(uid, room, bag_id);
  883. }
  884.  
  885.  
  886.  
  887. await HNTOOL.Sleep(5000);
  888. }
  889.  
  890. alert("批量送b克拉完毕!")
  891.  
  892.  
  893. });
  894.  
  895.  
  896. });
  897.  
  898.  
  899. $("#HNSetup").bind("click", async function() {
  900.  
  901. var CONFIG = HNTOOL.getConfig();
  902.  
  903.  
  904. let html = '';
  905.  
  906. html += '<div style="padding: 10px 10px 10px 0px;width:400px; ">'
  907. html += '<form id="HNGG_SETUP">'
  908. html += ' <div class="javaex-unit clear">'
  909. html += ' <div class="javaex-unit-left mr-10"><p class="subtitle required">Qmsg-key</p></div>'
  910. html += ' <div class="javaex-unit-left mr-10" style="width:200px">'
  911. html += ' <input type="text" class="javaex-text" data-type="english_number" error-msg="Q酱key不正确" ;'
  912. html += ` id="HNSetup_Qmsg_key" value="${CONFIG.qmsg_key}" placeholder="请输入Q酱key"/>`
  913. html += ' </div>'
  914. html += ' <div class="javaex-unit-left mr-10">'
  915. html += ` <input type="checkbox" class="javaex-switch" id="switch-qsmg" /> `
  916. html += ' </div>'
  917. html += ' </div>'
  918. html += '</form>';
  919. html += '<div class="javaex-unit clear tc">';
  920. html += ' <input type="button" id="HNSetup_save" class="javaex-btn yes" value="保存" />';
  921. html += '</div>';
  922. html += '<hr class="javaex-divider"></hr>';
  923. html += '</div>';
  924.  
  925. javaex.panel(this, {
  926. position: "right",
  927. content: html
  928. });
  929.  
  930.  
  931. HNTOOL.cssChecked("#switch-qsmg", CONFIG.qmsg_checked, HN_SETUP_CONFIG.qmsg_checked);
  932.  
  933. $("#switch-qsmg").bind("click", function() {
  934.  
  935. HN_SETUP_CONFIG.qmsg_checked = CONFIG.qmsg_checked == true ? false : true;
  936.  
  937. })
  938.  
  939.  
  940. $("#HNSetup_save").bind("click", async function() {
  941.  
  942.  
  943. HN_SETUP_CONFIG.qmsg_key = javaex.getSelectVal("#HNSetup_Qmsg_key");
  944.  
  945. localStorage.setItem(`HN_SETUP_CONFIG`, JSON.stringify(HN_SETUP_CONFIG));
  946.  
  947. javaex.tip({
  948. content: "设置成功!",
  949. type: "success"
  950. });
  951.  
  952. });
  953.  
  954. });
  955.  
  956. //
  957. $("#getUpMassage").bind("click", async function() {
  958.  
  959.  
  960. let html = '';
  961.  
  962. html += '<div style="padding: 10px 10px 10px 0px;">'
  963. html += '<form id="getUpMassage_form">'
  964. html += ' <div class="javaex-unit clear">'
  965. html += ' <div class="javaex-unit-left mr-10"><p class="subtitle required">用户uid</p></div>'
  966. html += ' <div class="javaex-unit-left mr-10">'
  967. html +=
  968. ' <input type="text" class="javaex-text javaex-grid-4" data-type="positive_int" error-msg="用户uid"'
  969. html += ` id="up_uid" value="${BiliData.this_uid}" placeholder="请输入评论uid"/>`
  970. html += ' </div>'
  971. html += ' <div class="javaex-unit-right mr-10">'
  972. html += ' <input type="button" id="getUpMsg" class="javaex-btn blue" value="查询"/>'
  973. html += ' </div>'
  974. html += ' </div>'
  975. html += ' <div class="javaex-unit clear tc" style="width: 500px;">'
  976. html += ' <table id="upMsgTable" class="javaex-table td-c-1">'
  977. html += ' <thead>'
  978. html += ' <tr><th>内容</th><th>详情</th></tr>'
  979. html += ' </thead>'
  980. html += ' <tbody id="upMsgTbody">'
  981.  
  982. html += ' </tbody>'
  983. html += '</table> '
  984. html += '</div>'
  985. html += '</form>';
  986. html += '<hr class="javaex-divider"></hr>';
  987. html += '</div>';
  988.  
  989.  
  990. javaex.panel(this, {
  991. position: "right",
  992. content: html
  993. });
  994.  
  995. javaex.table({
  996. id: "upMsgTable",
  997. isDragColWidth: true, // 是否允许拖动改变列宽
  998. mode: "overflow", // overflow表示允许使用父容器溢出来调整列的大小
  999. leftFixedColNum: 2, // 左侧固定列数
  1000. rightFixedColNum: 1, // 右侧固定列数
  1001. sort: {
  1002. "1": "create_time", // 4表示第几列(从1开始计)。create_time表示排序字段,回调函数会返回该值
  1003. "2": "update_time"
  1004. },
  1005. sortCallback: function(rtn) {
  1006. //console.log(rtn.sortArr);
  1007. }
  1008. });
  1009.  
  1010. //
  1011. $("#getUpMsg").click(async function() {
  1012.  
  1013. let thismid = javaex.getSelectVal("#up_uid");
  1014. await HNAPI.userInfo(thismid)
  1015.  
  1016. let temp = await HNAPI.getUpCard(thismid);
  1017.  
  1018.  
  1019. await HNTOOL.Sleep(500);
  1020.  
  1021.  
  1022. if (temp != false) {
  1023. let data = BiliData.upCard.data;
  1024.  
  1025. let html = ``;
  1026. html += `<tr><td>用户UID</td><td>${data.card.mid}</td></tr> `
  1027. html += `<tr><td>用户等级</td><td>lv${data.card.level_info.current_level}</td></tr> `
  1028. html += `<tr><td>用户昵称</td><td>${data.card.name}</td></tr> `
  1029. html += `<tr><td>用户性别</td><td>${data.card.sex}</td></tr> `
  1030. html +=
  1031. `<tr><td>用户头像</td><td><a href="javascript:;"><img src= ${data.card.face} width="50%"></a></td></tr> `
  1032. html += `<tr><td>粉丝数</td><td>${data.follower}</td></tr> `
  1033. html += `<tr><td>关注数</td><td>${data.card.friend}</td></tr> `
  1034. html += `<tr><td>是否关注此用户</td><td>${data.following}</td></tr> `
  1035. html += `<tr><td>用户稿件数</td><td>${data.archive_count}</td></tr> `
  1036. html +=
  1037. `<tr><td>用户勋章</td><td>${data.card.nameplate.name}<a href="javascript:;"><img src= ${data.card.nameplate.image} width="50%"></a> </td></tr> `
  1038. html += `<tr><td>用户勋章等级</td><td>${data.card.nameplate.level}</td></tr> `
  1039. html += `<tr><td>认证信息</td><td>${data.card.Official.title}</td></tr> `
  1040.  
  1041.  
  1042. $("#upMsgTbody").empty();
  1043. $("#upMsgTbody").append(html);
  1044. }
  1045.  
  1046.  
  1047. });
  1048. //点击放大
  1049. /* $("img").click(function() {
  1050. javaex.dialog({
  1051. type : "image", // 弹出层类型
  1052. url : $(this).attr("src") // 图片地址
  1053. });
  1054. });*/
  1055.  
  1056. });
  1057.  
  1058.  
  1059. $("#everyDayTask").bind("click", async function() {
  1060.  
  1061. let videoAid = 758643487;
  1062. let videoCid = 357521682;
  1063. let videoBvid = "BV1V64y1d7ed";
  1064. let videoMid = 99439379;
  1065. //1.直播签到 https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign
  1066. await HNAPI.DoSign();
  1067. await HNTOOL.Sleep(3000);
  1068.  
  1069.  
  1070. //2.每日观看视频 获取分区最新视频列表 http://api.bilibili.com/x/web-interface/dynamic/region pn=1 ps=20 rid=21
  1071. let archivesList = await HNAPI.dynamicRegion();
  1072. await HNTOOL.Sleep(2000);
  1073.  
  1074. let num = HNTOOL.random(0, archivesList.length - 1);
  1075.  
  1076. if (archivesList == true && num != 2) {
  1077.  
  1078. videoAid = archivesListp[num].aid;
  1079. videoCid = archivesListp[num].bvid;
  1080. videoBvid = archivesListp[num].cid;
  1081. videoMid = archivesListp[num].owner.mid;
  1082. }
  1083.  
  1084. await HNAPI.playOneVideo(videoBvid, videoMid);
  1085.  
  1086. await HNAPI.addCoin(videoAid);
  1087. await HNTOOL.Sleep(3000);
  1088.  
  1089. await HNAPI.addShare(videoAid);
  1090. await HNTOOL.Sleep(3000);
  1091.  
  1092. await HNAPI.clickNow();
  1093.  
  1094.  
  1095. });
  1096.  
  1097. $("#reserveActivity").bind("click", async function() {
  1098.  
  1099.  
  1100. let url = "https://gitee.com/java_cn/BILIBLI_RES/raw/master/HNPLATE/reserveSid.json";
  1101. let myjson = await HNAPI.getMyJson(url);
  1102.  
  1103.  
  1104. for (const sid in myjson) {
  1105.  
  1106. let siddata = myjson[sid];
  1107.  
  1108. console.log("时间:" + javaex.dateFormat(siddata.livePlanStartTime, 'yyyy-MM-dd HH:mm:ss') + "---upUID:" + siddata.upmid +
  1109. "---奖品:" + siddata.prizeInfo.text);
  1110.  
  1111.  
  1112. await HNAPI.reserveActivity(sid);
  1113. await HNTOOL.Sleep(3000);
  1114.  
  1115. javaex.tip({
  1116. content: "时间:" + javaex.dateFormat(siddata.livePlanStartTime, 'yyyy-MM-dd HH:mm:ss') + "--upUID:" + siddata.upmid +
  1117. "--奖品:" + siddata.prizeInfo.text,
  1118. type: "success"
  1119. });
  1120.  
  1121. }
  1122.  
  1123. alert("预约抽奖结束");
  1124. });
  1125.  
  1126. $("#plateActivity").bind("click", async function() {
  1127.  
  1128. //获取轮盘数据
  1129.  
  1130. let url = "https://gitee.com/java_cn/BILIBLI_RES/raw/master/HNPLATE/activities.json";
  1131. let myjson = await HNAPI.getMyJson(url);
  1132. let lmt = 0;
  1133. let k = 20; //重试次数 防止卡主
  1134. let giftArr = [];
  1135. let endAtion = [];
  1136.  
  1137. javaex.tip({
  1138. content: "开始参加轮盘!!!",
  1139. type: "success"
  1140. });
  1141.  
  1142. await HNAPI.getUserNav();
  1143. await HNTOOL.Sleep(1500);
  1144.  
  1145.  
  1146. for (const json of myjson) {
  1147. //let x = json.name;
  1148. for (let i = 0; i < 20; i++) {
  1149. //结果为true 表示增加次数完成 终止增加 0 成功 1:活动结束 2 发生错误
  1150. let resout = await HNAPI.addLotteryTimes(json.sid);
  1151.  
  1152. await HNTOOL.Sleep(200);
  1153. if (resout == 1) {
  1154.  
  1155. endAtion.push(json.name + ":活动已结束!");
  1156. javaex.tip({
  1157. content: json.name + "活动已结束!",
  1158. type: "success"
  1159. });
  1160.  
  1161. break;
  1162. }
  1163. if (resout != 0 && resout != 1) {
  1164.  
  1165. javaex.tip({
  1166. content: json.name + resout,
  1167. type: "error"
  1168. });
  1169.  
  1170. break;
  1171. }
  1172.  
  1173. if (resout == 0) {
  1174.  
  1175. lmt = await HNAPI.getLotteryMytimes(json.sid);
  1176. continue;
  1177. }
  1178.  
  1179. }
  1180.  
  1181. javaex.tip({
  1182. content: "可参加" + lmt + "次(" + json.name + ")抽奖!!!",
  1183. type: "success"
  1184. });
  1185.  
  1186. await HNTOOL.Sleep(1500);
  1187.  
  1188. for (let i = 0; i < lmt; i++) {
  1189.  
  1190. let gift = await HNAPI.lotteryDo(json.sid);
  1191.  
  1192.  
  1193. if (gift == true) {
  1194.  
  1195. javaex.tip({
  1196. content: "点击过快,9秒后自动重试!!!",
  1197. type: "error"
  1198. });
  1199.  
  1200. i--;
  1201. k--;
  1202. }
  1203.  
  1204. if (gift == false || k == 0) {
  1205. break;
  1206. }
  1207.  
  1208. if (gift != "未中奖0" && gift != true) {
  1209. giftArr.push(json.name + "奖品为:" + gift);
  1210. break;
  1211. } else {
  1212. javaex.tip({
  1213. content: "未中奖---8秒后执行下一次(" + json.name + ")抽奖!!!",
  1214. type: "success"
  1215. });
  1216. }
  1217. await HNTOOL.Sleep(9000);
  1218.  
  1219. }
  1220.  
  1221.  
  1222. }
  1223.  
  1224.  
  1225. HNAPI.sendQmsg(HNTOOL.getConfig().qmsg_key, `【哔哩猫转盘推送】:` + BiliData.LoginData.uname + `中奖详情:` + (giftArr.length ==
  1226. 0 ? "未中奖" : giftArr.toString()) + endAtion.toString());
  1227.  
  1228. alert(`【哔哩猫转盘推送】:` + BiliData.LoginData.uname + `中奖详情:` + (giftArr.length ==
  1229. 0 ? "未中奖" : giftArr.toString()) + endAtion.toString());
  1230.  
  1231.  
  1232. });
  1233.  
  1234. $("#addPlay").bind("click", async function() {
  1235.  
  1236.  
  1237. let html = '';
  1238.  
  1239. html += '<div style="padding: 10px 10px 10px 0px;">'
  1240. html += '<form id="getUpMassage_form">'
  1241.  
  1242. html += ' <div class="javaex-unit clear">'
  1243. html += ' <div class="javaex-unit-left"><p class="subtitle required">UID</p></div>'
  1244. html += ` <div class="javaex-unit-right" tooltip="请输入用户UID,默认自己" tooltip-pos="up"> `
  1245. html +=
  1246. ' <input type="text" class="javaex-text" data-type="positive_int|required" error-msg="请正确输入uid"'
  1247. html += ` id="addPlay_uid" value="${Live_info.uid}" placeholder="默认${BiliData.author_uid}"/>`
  1248. html += ' </div>'
  1249. html += ' </div>'
  1250. html += ' <div class="javaex-unit clear">'
  1251. html += ' <div class="javaex-unit-left"><p class="subtitle required">BV</p></div>'
  1252. html += ' <div class="javaex-unit-right" tooltip="请输入视频BV号 例如BV14r4y1A7Q9 (0表示全部)" tooltip-pos="up">'
  1253. html += ' <input type="text" class="javaex-text" data-type="required|english_number" error-msg=""'
  1254. html += ` id="addPlay_bv" value="0" placeholder="请输入视频BV号 例如BV14r4y1A7Q9 (0表示全部)"/>`
  1255. html += ' </div>'
  1256. html += ' </div>'
  1257. html += '</form>';
  1258. html += ' <div class="javaex-unit clear tc">'
  1259. html += ' <button id="addPlay_bgn" class="javaex-btn blue radius-3">开始</button> '
  1260. html += ' </div>'
  1261. html += '<hr class="javaex-divider"></hr>';
  1262. html += '</div>';
  1263.  
  1264.  
  1265. javaex.panel(this, {
  1266. position: "right",
  1267. content: html
  1268. });
  1269.  
  1270. $("#addPlay_bgn").click(async function() {
  1271.  
  1272. let MID = javaex.getSelectVal("#addPlay_uid")
  1273. let BV = javaex.getSelectVal("#addPlay_bv");
  1274. let bvArr = [];
  1275. let bvArr2 = [];
  1276.  
  1277. MID = javaex.ifnull(MID, BiliData.author_uid);
  1278.  
  1279.  
  1280. if (BV == "0") {
  1281.  
  1282. //1.查询up所有视频BV号 2.发送心跳间隔2s
  1283. HNAPI.getUpAllBV(BiliData.author_uid, 1, 2);
  1284. await HNTOOL.Sleep(500);
  1285. bvArr2 = BiliData.BVList;
  1286.  
  1287. for (let i = 1; i > 0; i++) {
  1288.  
  1289. HNAPI.getUpAllBV(MID, i);
  1290.  
  1291. await HNTOOL.Sleep(500);
  1292.  
  1293. if (BiliData.BVList.length == 0) {
  1294. if (bvArr.length == 0) {
  1295. javaex.tip({
  1296. content: "该用户无投稿视频,请确认是否有误!",
  1297. type: "success"
  1298. });
  1299. await HNTOOL.Sleep(2000);
  1300. }
  1301. //bvArr = bvArr.ifnull(bvArr2, bvArr.concat(bvArr2));
  1302. bvArr = bvArr.concat(bvArr2);
  1303. break;
  1304. }
  1305.  
  1306. bvArr = bvArr.concat(BiliData.BVList);
  1307. }
  1308.  
  1309.  
  1310. if (bvArr.length != 0) {
  1311.  
  1312. for (const emt of bvArr) {
  1313.  
  1314. HNAPI.playOneVideo(emt.bvid, MID);
  1315.  
  1316. await HNTOOL.Sleep(2000);
  1317.  
  1318. }
  1319.  
  1320. alert("播放完成!!!");
  1321.  
  1322. }
  1323.  
  1324.  
  1325. } else {
  1326. //1.调用点击播放接口
  1327. //2.发送心跳
  1328.  
  1329. await HNTOOL.Sleep(500);
  1330.  
  1331. HNAPI.playOneVideo(BV);
  1332. }
  1333.  
  1334.  
  1335. });
  1336.  
  1337.  
  1338. });
  1339.  
  1340. }
  1341.  
  1342.  
  1343. let addSetPage = async function() {
  1344.  
  1345. HNTOOL.Sleep(1000);
  1346.  
  1347. $('body').append('' +
  1348. '<div id="left_navbar">' +
  1349. '<div class="javaex-menu-container"> ' +
  1350. ' <div id="menu" class="javaex-menu"> ' +
  1351. ' <ul> ' +
  1352. ' <li class="javaex-menu-item alone hover" > ' +
  1353. ' <a href="javaScript:;" style="background: #fb7299;padding-left: 0px;text-align: center;color: #ffffff;font-weight: bold;border-bottom: 1px solid #eee;" ' +
  1354. ` tooltip="我是来测试的" tooltip-pos="right">管理中心 v${GM_info.script.version}</a> ` +
  1355. ' </li> ' +
  1356. ' </ul> ' +
  1357. ' <ul> ' +
  1358. ' <li class="javaex-menu-item"> ' +
  1359. ' <a href="javascript:;">个人中心<i class="icon-angle-down"></i></a> ' +
  1360. ' <ul> ' +
  1361. ' <li id="biliUserMsg" class="javaex-hover-pulse"><a href="javaScript:;">用户信息</a></li> ' +
  1362. ' </ul> ' +
  1363. ' </li> ' +
  1364. ' <li id="chackList" class="javaex-menu-item"> ' +
  1365. ' <a href="javaScript:;">查询<i class="icon-angle-down"></i></a> ' +
  1366. ' <ul> ' +
  1367. ' <li id="getUpMassage" ><a href="javaScript:;">查询用户详细信息</a></li> ' +
  1368. //' <li><a href="javaScript:;">查询每日最热视频【禁用】</a></li> ' +
  1369. ' <li id="getAtMsg"><a href="javaScript:;">查询动态艾特信息</a></li> ' +
  1370. ' <li id="getCoinLog" class="javaex-hover-pulse"><a href="javaScript:;">查询硬币变化</a></li> ' +
  1371. ' <li id="getUnread" class="javaex-hover-pulse"><a href="javaScript:;">查询消息</a></li> ' +
  1372. ' </ul> ' +
  1373. ' </li> ' +
  1374. ' <li class="javaex-menu-item"> ' +
  1375. ' <a href="javascript:;">批量操作工具<i class="icon-angle-down"></i></a> ' +
  1376. ' <ul> ' +
  1377. ' <li id="addPlay" class="javaex-hover-pulse"><a href="javaScript:;" >批量播放视频</a></li> ' +
  1378. ' <li id="disUser" class="javaex-hover-pulse"><a href="javaScript:;" >批量拉黑&取关</a></li> ' +
  1379. ' <li id="batchFollow" class="javaex-hover-pulse"><a href="javaScript:;" >批量关注</a></li> ' +
  1380. ' <li id="batchTargetMedal" class="javaex-hover-pulse"><a href="javaScript:;" >批量勋章</a></li> ' +
  1381. //' <li class="javaex-hover-pulse"><a href="javaScript:;" >批量发私信</a></li> ' +
  1382. //' <li class="javaex-hover-pulse"><a href="javaScript:;" >批量发送视频弹幕</a></li> ' +
  1383. ' </ul> ' +
  1384. ' </li> ' +
  1385. ' <li class="javaex-menu-item"> ' +
  1386. ' <a href="javascript:;">其他工具<i class="icon-angle-down"></i></a> ' +
  1387. ' <ul> ' +
  1388. ' <li id="everyDayTask" class="javaex-hover-pulse"><a href="javaScript:;" >一键日常任务</a></li> ' +
  1389. //' <li class="javaex-hover-pulse"><a href="javaScript:;" >移动粉丝勋章</a></li> ' +
  1390. //' <li class="javaex-hover-pulse"><a href="javaScript:;" >评论区抽奖</a></li> ' +
  1391. //' <li class="javaex-hover-pulse"><a href="javaScript:;" >注册答题</a></li> ' +
  1392. ' <li id="plateActivity" class="javaex-hover-pulse"><a href="javaScript:;" >轮盘抽奖</a></li> ' +
  1393. ' <li id="reserveActivity" class="javaex-hover-pulse"><a href="javaScript:;" >预约抽奖</a></li> ' +
  1394. //' <li id="" class="javaex-hover-pulse" ><a href="javaScript:;">动态评论区点赞</a></li> ' + //likeInDynamicComments
  1395. ' <li id="getNeetCookie" class="javaex-hover-pulse"><a href="javaScript:;">获取Cookie</a></li> ' +
  1396. ' <li id="arrUnique" class="javaex-hover-pulse"><a href="javaScript:;">数组去重</a></li> ' +
  1397. ' </ul> ' +
  1398. ' </li> ' +
  1399. ' <li class="javaex-menu-item"> ' +
  1400. ' <a href="javascript:;">设置及更新<i class="icon-angle-down"></i></a> ' +
  1401. ' <ul> ' +
  1402. ' <li class="javaex-hover-pulse"><a href="https://greasyfork.org/zh-CN/scripts/422731" >更新</a></li> ' +
  1403. ' <li id="HNSetup" class="javaex-hover-pulse" ><span class="icon-cogs" style="font-size:50px;color:#ff0000;"></span><a href="javaScript:;">设置</a></li> ' +
  1404. ' </ul> ' +
  1405. ' </li> ' +
  1406.  
  1407. ' </ul> ' +
  1408. ' </div> ' +
  1409. '</div>' +
  1410. '</div>');
  1411. //$("#left_navbar").before('<button hnBtn="btn_open" class="javaex-btn green" onclick="openBar()">点我关闭</button>')
  1412.  
  1413. javaex.menu({
  1414. id: "menu",
  1415. isShowAll: false
  1416. });
  1417.  
  1418. }
  1419.  
  1420.  
  1421.  
  1422.  
  1423. let showUnreadMsg = function() {
  1424.  
  1425. var html = '';
  1426. html += '<div class="javaex-panel-box" style="width: 250px;">';
  1427. html += ' <ul>';
  1428. html += ` <p style="color: #FFF;">用户消息</p>`;
  1429. html += ` <li><a href="https://message.bilibili.com/#/at">未读艾特数:${BiliData.Unread.at}</a> </li> `;
  1430. html += ` <li><a href="https://message.bilibili.com/#/love">未读点赞数:${BiliData.Unread.like}</a> </li> `;
  1431. html += ` <li><a href="https://message.bilibili.com/#/reply">未读回复数:${BiliData.Unread.reply}</a> </li> `;
  1432. html += ` <li><a href="https://message.bilibili.com/#/system">未读系统通知数:${BiliData.Unread.sys_msg}</a> </li> `;
  1433. html += ` <li><a href="">UP主助手信息数:${BiliData.Unread.up}</a> </li> `;
  1434. html += ' <hr class="javaex-divider"></hr>';
  1435. html += ' </ul>';
  1436. html += '</div>';
  1437.  
  1438.  
  1439. javaex.panel(document.getElementById("getUnread"), {
  1440. position: "right",
  1441. content: html
  1442. });
  1443.  
  1444. javaex.tip({
  1445. content: "查询用户通知成功!",
  1446. type: "success"
  1447. });
  1448.  
  1449. }
  1450.  
  1451. /**
  1452. * 检查 艾特信息
  1453. * @returns {Promise<void>}
  1454. */
  1455. let chackAtMsg = async function(items) {
  1456.  
  1457. await HNTOOL.Sleep(500);
  1458.  
  1459. if (items != false && typeof(items) != "undefined") {
  1460.  
  1461.  
  1462. var html = '';
  1463. html += '<div class="javaex-panel-box" style="width: auto;">';
  1464. html += ' <ul>';
  1465. html += ` <p style="color: #FFF;">@信息</p>`;
  1466. items.forEach(function(item) {
  1467.  
  1468. var atTime = javaex.dateFormat(item.at_time, 'yyyy-MM-dd HH:mm:ss');
  1469. HNAPI.sendQmsg(HNTOOL.getConfig().qmsg_key, atTime + " 恭喜动态中奖了!" +
  1470. `${item.user.nickname}在动态中艾特了你! 内容:${item.item.source_content}`);
  1471.  
  1472. html +=
  1473. ` <li>${atTime} <a class="fontbold" href="https://space.bilibili.com/${item.user.mid}">:${item.user.nickname}</a>在动态中艾特了你!</li> `
  1474. html += ` <li class="fontbold">内容:${item.item.source_content}</li> `;
  1475. html += ` <li><a href="${item.item.uri}">---点击查看详情---</a> </li> `;
  1476. html += ' <hr class="javaex-divider"></hr>';
  1477. });
  1478. html += ' </ul>';
  1479. html += '</div>';
  1480.  
  1481.  
  1482. if (($("#chackList").attr("class")).indexOf("hover") > -1) {
  1483. javaex.panel(document.getElementById("getAtMsg"), {
  1484. position: "right",
  1485. content: html
  1486. });
  1487. } else {
  1488. javaex.panel(document.getElementById("chackList"), {
  1489. position: "right",
  1490. content: html
  1491. });
  1492. }
  1493.  
  1494.  
  1495. }
  1496.  
  1497. }
  1498.  
  1499.  
  1500. let addStyle = function() {
  1501. const animate = GM_getResourceText('animate');
  1502. const common = GM_getResourceText('common');
  1503. const defaultCss = GM_getResourceText('defaultCss');
  1504. //const icomoonex = GM_getResourceText('icomoonex');
  1505. //const AllCss = animate + common + defaultCss + icomoonex;
  1506. const AllCss = animate + common + defaultCss;
  1507. const style = document.createElement('style');
  1508. style.innerHTML = AllCss;
  1509. return document.getElementsByTagName('head')[0].appendChild(style);
  1510. }
  1511.  
  1512. /*-----------------------------------------------点击事件绑定--------------------------------------------------*/
  1513.  
  1514.  
  1515. /*-----------------------------------------------常用API--------------------------------------------------*/
  1516.  
  1517. let HNAPI = {
  1518.  
  1519. /**
  1520. * 每日登录 https://api.bilibili.com/x/report/click/now : "jsonp"
  1521. */
  1522. clickNow: async function() {
  1523. return new Promise((resolve) => {
  1524. Ajax.get({
  1525.  
  1526. url: BILIBLI_PATH.api + '/x/report/click/now',
  1527. queryStringsObj: {
  1528. jsonp:"jsonp"
  1529. },
  1530. hasCookies: true,
  1531. success: responseText => {
  1532. let res = HNTOOL.strToJson(responseText);
  1533. if (res.code === 0) {
  1534.  
  1535. javaex.tip({
  1536. content: "每日登录" + res.data.text,
  1537. type: "success"
  1538. });
  1539. resolve(true);
  1540.  
  1541. } else {
  1542.  
  1543. javaex.tip({
  1544. content: res.message,
  1545. type: "error"
  1546. });
  1547.  
  1548. resolve(false);
  1549. }
  1550. }
  1551. })
  1552. });
  1553. },
  1554.  
  1555. /**
  1556. * 每日分享视频(客户端) psot https://api.bilibili.com/x/web-interface/share/add aid csrf
  1557. * @param {number} videoAid
  1558. */
  1559. addShare: async function(videoAid) {
  1560. return new Promise((resolve) => {
  1561. Ajax.post({
  1562. url: BILIBLI_PATH.api + '/x/web-interface/share/add',
  1563. hasCookies: true,
  1564. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1565. data: {
  1566. aid: videoAid,
  1567. csrf: Live_info.csrf_token
  1568. },
  1569. success: responseText => {
  1570. let res = HNTOOL.strToJson(responseText);
  1571. if (res.code === 0) {
  1572.  
  1573. javaex.tip({
  1574. content: "每日分享视频成功",
  1575. type: "success"
  1576. });
  1577.  
  1578. resolve(true);
  1579. } else {
  1580.  
  1581. javaex.tip({
  1582. content: res.message,
  1583. type: "error"
  1584. });
  1585.  
  1586. resolve(false);
  1587. }
  1588. }
  1589. })
  1590. });
  1591. },
  1592.  
  1593. /**
  1594. * 每日投币 post https://api.bilibili.com/x/web-interface/coin/add
  1595. * @param {number} videoAid
  1596. */
  1597. addCoin: async function(videoAid) {
  1598. return new Promise((resolve) => {
  1599. Ajax.post({
  1600. url: BILIBLI_PATH.api + '/x/web-interface/coin/add',
  1601. hasCookies: true,
  1602. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1603. data: {
  1604. aid: videoAid,
  1605. multiply: 2,
  1606. select_like: 0,
  1607. cross_domain: true,
  1608. csrf: Live_info.csrf_token
  1609. },
  1610. success: responseText => {
  1611. let res = HNTOOL.strToJson(responseText);
  1612. if (res.code === 0) {
  1613.  
  1614. javaex.tip({
  1615. content: "投币成功",
  1616. type: "success"
  1617. });
  1618.  
  1619. resolve(true);
  1620. } else {
  1621.  
  1622. javaex.tip({
  1623. content: res.message,
  1624. type: "error"
  1625. });
  1626.  
  1627. resolve(false);
  1628. }
  1629. }
  1630. })
  1631. });
  1632. },
  1633.  
  1634.  
  1635. //1.直播签到 https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign
  1636.  
  1637. DoSign: async function() {
  1638. return new Promise((resolve) => {
  1639. Ajax.get({
  1640.  
  1641. url: BILIBLI_PATH.live + '/xlive/web-ucenter/v1/sign/DoSign',
  1642. queryStringsObj: {
  1643.  
  1644. },
  1645. hasCookies: true,
  1646. success: responseText => {
  1647. let res = HNTOOL.strToJson(responseText);
  1648. if (res.code === 0) {
  1649.  
  1650. javaex.tip({
  1651. content: "签到成功:" + res.data.text,
  1652. type: "success"
  1653. });
  1654. resolve(true);
  1655.  
  1656. } else if (res.code === 1011040) {
  1657.  
  1658. javaex.tip({
  1659. content: res.message,
  1660. type: "success"
  1661. });
  1662.  
  1663. resolve(true);
  1664. } else {
  1665.  
  1666. javaex.tip({
  1667. content: res.message,
  1668. type: "error"
  1669. });
  1670.  
  1671. resolve(false);
  1672. }
  1673. }
  1674. })
  1675. });
  1676. },
  1677.  
  1678.  
  1679. /**
  1680. * // 获取分区最新视频列表
  1681. */
  1682. dynamicRegion: async function() {
  1683. return new Promise((resolve) => {
  1684. Ajax.get({
  1685.  
  1686. url: BILIBLI_PATH.api + '/x/web-interface/dynamic/region',
  1687. queryStringsObj: {
  1688. "pn": 1,
  1689. "ps": 20,
  1690. "rid": 21
  1691. },
  1692. hasCookies: true,
  1693. success: responseText => {
  1694. let res = HNTOOL.strToJson(responseText);
  1695. if (res.code === 0) {
  1696.  
  1697. javaex.tip({
  1698. content: "获取分区最新视频成功",
  1699. type: "success"
  1700. });
  1701. resolve(res.data.archives);
  1702.  
  1703. } else {
  1704.  
  1705. javaex.tip({
  1706. content: "获取分区最新视频失败" + res.message,
  1707. type: "error"
  1708. });
  1709.  
  1710. resolve(false);
  1711. }
  1712. }
  1713. })
  1714. });
  1715. },
  1716.  
  1717. /**
  1718. * 预约抽奖 https://api.bilibili.com/x/space/reserve sid jsonp=jsonp csrf
  1719. * @param {Object} sid
  1720. */
  1721. reserveActivity: async function(sid) {
  1722. return new Promise((resolve) => {
  1723. Ajax.post({
  1724. url: BILIBLI_PATH.api + '/x/space/reserve',
  1725. hasCookies: true,
  1726. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1727. data: {
  1728. sid: sid, //当前用户
  1729. jsonp: "jsonp",
  1730. csrf: Live_info.csrf_token
  1731. },
  1732. success: responseText => {
  1733. let res = HNTOOL.strToJson(responseText);
  1734. if (res.code === 0) {
  1735.  
  1736. /* javaex.tip({
  1737. content: sid + "参加成功!" + res.message,
  1738. type: "success"
  1739. }); */
  1740.  
  1741. resolve(true);
  1742. } else {
  1743.  
  1744. javaex.tip({
  1745. content: res.message,
  1746. type: "error"
  1747. });
  1748.  
  1749. resolve(false);
  1750. }
  1751. }
  1752. })
  1753. });
  1754. },
  1755.  
  1756. getGiftList: async function(room) {
  1757. return new Promise((resolve) => {
  1758. Ajax.get({
  1759.  
  1760. url: BILIBLI_PATH.live + '/xlive/web-room/v1/gift/bag_list',
  1761. queryStringsObj: {
  1762. "room_id": room
  1763. },
  1764. hasCookies: true,
  1765. success: responseText => {
  1766. let res = HNTOOL.strToJson(responseText);
  1767. if (res.code === 0) {
  1768.  
  1769. resolve(res.data.list);
  1770. } else {
  1771.  
  1772. javaex.tip({
  1773. content: "查询包裹失败!" + res.message,
  1774. type: "error"
  1775. });
  1776.  
  1777. resolve(false)
  1778. }
  1779. }
  1780. })
  1781. });
  1782. },
  1783.  
  1784. /**
  1785. * 送银B克拉
  1786. * @param {Object} ruid
  1787. * @param {Object} roomid
  1788. */
  1789. bagSendGift: async function(ruid, roomid, bag_id) {
  1790. return new Promise((resolve) => {
  1791. Ajax.post({
  1792. url: BILIBLI_PATH.live + '/gift/v2/live/bag_send',
  1793. hasCookies: true,
  1794. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1795. data: {
  1796. uid: Live_info.uid, //当前用户
  1797. gift_id: 3,
  1798. ruid: ruid,
  1799. send_ruid: 0,
  1800. gift_num: 1,
  1801. bag_id: bag_id,
  1802. //rnd: Math.round(new Date() / 1000); //时间戳,
  1803. platform: 'pc',
  1804. biz_code: 'Live',
  1805. biz_id: roomid,
  1806. storm_beat_id: 0,
  1807. price: 0,
  1808. csrf_token: Live_info.csrf_token,
  1809. csrf: Live_info.csrf_token
  1810.  
  1811. },
  1812. success: responseText => {
  1813. let res = HNTOOL.strToJson(responseText);
  1814. if (res.code === 0) {
  1815.  
  1816. javaex.tip({
  1817. content: roomid + "赠送b克拉成功!" + res.message,
  1818. type: "success"
  1819. });
  1820.  
  1821. resolve(true);
  1822. } else {
  1823.  
  1824. javaex.tip({
  1825. content: res.message,
  1826. type: "error"
  1827. });
  1828.  
  1829. resolve(false);
  1830. }
  1831. }
  1832. })
  1833. });
  1834. },
  1835.  
  1836.  
  1837. /**
  1838. * 判断是否有勋章
  1839. * @param {Object} uid
  1840. * @param {Object} room
  1841. */
  1842.  
  1843. getFansMedalInfo: async function(uid, room) {
  1844. return new Promise((resolve) => {
  1845. Ajax.get({
  1846.  
  1847. url: BILIBLI_PATH.live + '/xlive/app-ucenter/v1/fansMedal/fans_medal_info',
  1848. queryStringsObj: {
  1849. "target_id": uid,
  1850. "room_id": room
  1851. },
  1852. //dataType:'application/json, text/plain, */*',
  1853. hasCookies: true,
  1854. success: responseText => {
  1855. let res = HNTOOL.strToJson(responseText);
  1856. if (res.code === 0) {
  1857.  
  1858. if (res.data.my_fans_medal.level == 0) {
  1859. resolve(false)
  1860. } else {
  1861. resolve(true)
  1862. }
  1863.  
  1864. } else {
  1865.  
  1866. javaex.tip({
  1867. content: "查询勋章失败!" + res.message,
  1868. type: "error"
  1869. });
  1870.  
  1871. resolve(false)
  1872. }
  1873. }
  1874. })
  1875. });
  1876. },
  1877.  
  1878.  
  1879.  
  1880.  
  1881. getDisuidList: async function(re_version, pn) {
  1882. return new Promise((resolve) => {
  1883. Ajax.get({
  1884.  
  1885. url: BILIBLI_PATH.api + '/x/relation/blacks',
  1886. queryStringsObj: {
  1887. "re_version": re_version,
  1888. "pn": pn
  1889. },
  1890. hasCookies: true,
  1891. success: responseText => {
  1892. let res = HNTOOL.strToJson(responseText);
  1893. if (res.code === 0) {
  1894. resolve(res.data.list)
  1895. } else {
  1896.  
  1897. javaex.tip({
  1898. content: "查询黑名单失败!" + res.message,
  1899. type: "error"
  1900. });
  1901.  
  1902. resolve(null)
  1903. }
  1904. }
  1905. })
  1906. });
  1907. },
  1908.  
  1909. /**
  1910. * @param {Object} uid
  1911. * @param {Object} act 1关注,2取关,3悄悄关注,4取消悄悄关注,5拉黑,6取消拉黑,7踢出粉丝;
  1912. */
  1913. cancelAtt: async function(uid, act, re_src) {
  1914. return new Promise((resolve) => {
  1915. Ajax.post({
  1916. url: BILIBLI_PATH.api + '/x/relation/modify',
  1917. hasCookies: true,
  1918. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1919. data: {
  1920. fid: uid,
  1921. act: act,
  1922. re_src: re_src == undefined ? 11 : 116,
  1923. jsonp: "jsonp",
  1924. csrf: Live_info.csrf_token,
  1925. },
  1926. success: responseText => {
  1927. let res = HNTOOL.strToJson(responseText);
  1928. if (res.code === 0) {
  1929.  
  1930. //HNAPI.cancelAtt(uid, 6);
  1931.  
  1932. javaex.tip({
  1933. content: "取关成功!" + res.message,
  1934. type: "success"
  1935. });
  1936.  
  1937. resolve(true);
  1938. } else if (res.code === 22003) {
  1939.  
  1940. HNAPI.cancelAtt(uid, 6);
  1941.  
  1942. javaex.tip({
  1943. content: "取消拉黑" + res.message,
  1944. type: "success"
  1945. });
  1946. resolve(true);
  1947. } else {
  1948.  
  1949. javaex.tip({
  1950. content: res.message,
  1951. type: "error"
  1952. });
  1953.  
  1954. resolve(false);
  1955. }
  1956. }
  1957. })
  1958. });
  1959. },
  1960.  
  1961. getRoomMsg: async function(roomid) {
  1962. return new Promise((resolve) => {
  1963. Ajax.get({
  1964.  
  1965. url: BILIBLI_PATH.live + '/live_user/v1/UserInfo/get_anchor_in_room',
  1966. queryStringsObj: {
  1967. "roomid": roomid
  1968. },
  1969. hasCookies: true,
  1970. success: responseText => {
  1971. let res = HNTOOL.strToJson(responseText);
  1972. if (res.code === 0) {
  1973. resolve(res.data.info.uid)
  1974. } else {
  1975. resolve(false)
  1976. }
  1977. }
  1978. })
  1979. });
  1980. },
  1981.  
  1982. /**
  1983. *
  1984. * @param sid
  1985. * @returns {Promise<unknown>}
  1986. */
  1987. lotteryDo: async function(sid) {
  1988. return new Promise((resolve) => {
  1989. Ajax.post({
  1990. url: BILIBLI_PATH.api + '/x/activity/lottery/do',
  1991. hasCookies: true,
  1992. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  1993. data: {
  1994.  
  1995. sid: sid,
  1996. type: 1,
  1997. csrf: Live_info.csrf_token,
  1998. },
  1999. success: responseText => {
  2000. let res = HNTOOL.strToJson(responseText);
  2001. if (res.code === 0) {
  2002. resolve((res.data)[0].gift_name);
  2003.  
  2004. } else if (res.code === 75400) {
  2005.  
  2006. resolve(true);
  2007. } else {
  2008. javaex.tip({
  2009. content: "本次抽奖失败!" + res.message,
  2010. type: "error"
  2011. });
  2012. resolve(false);
  2013. }
  2014. }
  2015. })
  2016. });
  2017. },
  2018.  
  2019.  
  2020. getLotteryMytimes: async function(sid) {
  2021. return new Promise((resolve) => {
  2022. Ajax.get({
  2023. url: BILIBLI_PATH.api + '/x/activity/lottery/mytimes',
  2024. queryStringsObj: {
  2025. sid: sid
  2026. },
  2027. hasCookies: true,
  2028. success: responseText => {
  2029. let res = HNTOOL.strToJson(responseText);
  2030. if (res.code === 0) {
  2031. resolve(res.data.times)
  2032. } else {
  2033. resolve(0)
  2034. }
  2035. }
  2036. })
  2037. });
  2038. },
  2039.  
  2040. /**
  2041. * 增加抽奖次数一般是分享
  2042. * @param sid 活动sid
  2043. * @returns {Promise<unknown>} 0 成功 1:活动结束
  2044. */
  2045. addLotteryTimes: async function(sid) {
  2046. return new Promise((resolve) => {
  2047. Ajax.post({
  2048. url: BILIBLI_PATH.api + '/x/activity/lottery/addtimes',
  2049. hasCookies: true,
  2050. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  2051. data: {
  2052.  
  2053. sid: sid,
  2054. action_type: 3,
  2055. csrf: Live_info.csrf_token,
  2056. },
  2057. success: responseText => {
  2058. let res = HNTOOL.strToJson(responseText);
  2059. if (res.code === 0) {
  2060.  
  2061. resolve(0)
  2062. } else if (res.code === 75003) {
  2063.  
  2064. resolve(1)
  2065.  
  2066. } else {
  2067.  
  2068. resolve(res.message);
  2069. }
  2070. }
  2071. })
  2072. });
  2073. },
  2074. /**
  2075. * 查询用户关注 默认一次查询50
  2076. * @param vmid 用户uid
  2077. * @param pn 页码
  2078. * @returns {Promise<unknown>}
  2079. */
  2080. getMyFollow: async function(vmid, pn) {
  2081. return new Promise((resolve) => {
  2082. Ajax.get({
  2083. url: BILIBLI_PATH.api + '/x/relation/followings',
  2084. queryStringsObj: {
  2085. vmid: vmid,
  2086. pn: pn
  2087. },
  2088. hasCookies: true,
  2089. success: responseText => {
  2090. let res = HNTOOL.strToJson(responseText);
  2091. if (res.code === 0) {
  2092. resolve(res.data)
  2093. } else {
  2094. resolve(null)
  2095. }
  2096. }
  2097. })
  2098. });
  2099. },
  2100.  
  2101.  
  2102. getMyinfo: function() {
  2103. return new Promise((resolve) => {
  2104. Ajax.get({
  2105. url: BILIBLI_PATH.api + '/x/space/myinfo',
  2106. queryStringsObj: {},
  2107. hasCookies: true,
  2108. success: responseText => {
  2109. let res = HNTOOL.strToJson(responseText);
  2110. if (res.code === 0) {
  2111. resolve(res.data)
  2112. } else {
  2113. resolve(null)
  2114. }
  2115. }
  2116. })
  2117. });
  2118. },
  2119.  
  2120. getMyJson: function(url) {
  2121. return new Promise((resolve) => {
  2122. GM_xmlhttpRequest({
  2123. method: "GET",
  2124. url: url,
  2125. onload: function(response) {
  2126. const res = HNTOOL.strToJson((response || {}).responseText)
  2127. resolve(res);
  2128. }
  2129. });
  2130. })
  2131. },
  2132.  
  2133.  
  2134. userInfo: function(mid) {
  2135.  
  2136. Ajax.get({
  2137. url: BILIBLI_PATH.api + '/x/space/acc/info',
  2138. queryStringsObj: {
  2139. mid: mid
  2140. },
  2141. hasCookies: true,
  2142. success: responseText => {
  2143.  
  2144. var json = JSON.parse(responseText);
  2145.  
  2146. if (json.code != 0) {
  2147.  
  2148.  
  2149. }
  2150. }
  2151. });
  2152.  
  2153. },
  2154.  
  2155. sendQmsg: async function(key, msg) {
  2156.  
  2157. $.ajax({
  2158. url: "https://qmsg.zendee.cn/send/" + key + "?msg=" + msg,
  2159.  
  2160. success: function(result) {
  2161.  
  2162. }
  2163. });
  2164.  
  2165.  
  2166. /*GM_xmlhttpRequest({
  2167. method: "GET",
  2168. url: `https://qmsg.zendee.cn/send/${key}?msg=${msg}`,
  2169. onload: function (response) {
  2170.  
  2171. let json = JSON.parse(response.response);
  2172. if (json.code == 0) {
  2173.  
  2174. javaex.tip({
  2175. content: "自动动态中奖提醒成功!" + json.reason,
  2176. type: "success"
  2177. });
  2178. } else {
  2179. console.log("自动动态中奖提醒失败!" + json.reason);
  2180. javaex.tip({
  2181. content: "自动动态中奖提醒失败!" + json.reason,
  2182. type: "error"
  2183. });
  2184. }
  2185.  
  2186. }
  2187. });*/
  2188.  
  2189. },
  2190.  
  2191. /**
  2192. * 批量关注和拉黑 batchModify
  2193. *
  2194. * https://api.bilibili.com/x/relation/batch/modify
  2195. * @param uid
  2196. */
  2197.  
  2198. batchModify: function(uids, act) {
  2199.  
  2200.  
  2201. Ajax.post({
  2202. url: BILIBLI_PATH.api + "/x/relation/batch/modify",
  2203. hasCookies: true,
  2204. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  2205. data: {
  2206.  
  2207. "fids": uids,
  2208. "act": act == undefined ? 1 : act, //1 关注 5 拉黑
  2209. "re_src": 151,
  2210. csrf: Live_info.csrf_token,
  2211. },
  2212. success: responseText => {
  2213.  
  2214. let json = JSON.parse(responseText);
  2215.  
  2216. if (/^{"code":0/.test(responseText)) {
  2217.  
  2218. javaex.tip({
  2219. content: `执行成功!---失败(` + json.data.failed_fids.length + `/15)名单:` + json.data.failed_fids,
  2220. type: "success"
  2221. });
  2222.  
  2223. } else {
  2224. javaex.tip({
  2225. content: "关注失败!" + json.message,
  2226. type: "error"
  2227. });
  2228. }
  2229. }
  2230. })
  2231. },
  2232.  
  2233.  
  2234. /**
  2235. * //https://api.bilibili.com/x/relation/modify
  2236. *
  2237. * @param UID
  2238. */
  2239. disUserByUid: function(vmid) {
  2240.  
  2241. Ajax.post({
  2242. url: BILIBLI_PATH.api + '/x/relation/modify',
  2243. data: {
  2244. fid: parseInt(vmid),
  2245. re_src: 11,
  2246. act: 5,
  2247. jsonp: "jsonp",
  2248. csrf: Live_info.csrf_token,
  2249. },
  2250. hasCookies: true,
  2251. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  2252. success: responseText => {
  2253.  
  2254. var json = JSON.parse(responseText);
  2255.  
  2256. if (json.code != 0) {
  2257.  
  2258. console.log("拉黑用户失败uid:" + vmid + " 错误信息" + json.message);
  2259. javaex.tip({
  2260. content: "拉黑用户失败uid:" + vmid + " 错误信息" + json.message,
  2261. type: "error"
  2262. });
  2263.  
  2264. } else {
  2265. console.log("拉黑用户成功 uid:" + vmid);
  2266. javaex.tip({
  2267. content: "拉黑用户成功 uid:" + vmid,
  2268. type: "success"
  2269. });
  2270. }
  2271. }
  2272. });
  2273.  
  2274. },
  2275. /**
  2276. * http://api.bilibili.com/x/web-interface/view
  2277. * @param BV
  2278. * 心跳间隔15秒
  2279. */
  2280. playOneVideo: function(BV, MID) {
  2281.  
  2282. //1.调用点击播放接口 https://api.bilibili.com/x/click-interface/click/web/h5
  2283. Ajax.post({
  2284. url: BILIBLI_PATH.api + "/x/click-interface/click/web/h5",
  2285. hasCookies: true,
  2286. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  2287. data: {
  2288.  
  2289. "bvid": BV,
  2290. "part": 1,
  2291. "mid": Live_info.uid,
  2292. "lv": 2,
  2293. "jsonp": "jsonp",
  2294. "type": 3,
  2295. "sub_type": 0
  2296. },
  2297. success: responseText => {
  2298.  
  2299. let json = JSON.parse(responseText);
  2300.  
  2301. if (/^{"code":0/.test(responseText)) {
  2302. //发送一次心跳
  2303. HNAPI.sendHeartbeat(BV, MID);
  2304.  
  2305. } else {
  2306. javaex.tip({
  2307. content: "视频" + data.bvid + "播放失败!" + json.message,
  2308. type: "error"
  2309. });
  2310. }
  2311. }
  2312. })
  2313.  
  2314.  
  2315. },
  2316.  
  2317. //上报视频播放心跳(web端)
  2318. /**
  2319. * http://api.bilibili.com/x/click-interface/web/heartbeat
  2320. * @param json
  2321. */
  2322. sendHeartbeat: function(bvid, MID) {
  2323.  
  2324. Ajax.post({
  2325. url: BILIBLI_PATH.api + "/x/click-interface/web/heartbeat",
  2326. hasCookies: true,
  2327. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  2328. //aid=756988764&bvid=BV1wr4y1P782&cid=304166326&page=1
  2329. data: {
  2330. "bvid": bvid,
  2331. "type": 3,
  2332. "dt": 2,
  2333. "played_time": HNTOOL.random(12, 40),
  2334. "realtime": HNTOOL.random(12, 40),
  2335. "play_type": 0
  2336. },
  2337. success: responseText => {
  2338.  
  2339. if (/^{"code":0/.test(responseText) && MID != BiliData.author_uid) {
  2340.  
  2341. javaex.tip({
  2342. content: "视频BV" + bvid + "播放一次!",
  2343. type: "success"
  2344. });
  2345. }
  2346. }
  2347. })
  2348.  
  2349. },
  2350.  
  2351. //获取up所有投稿视频
  2352. /**
  2353. * https://api.bilibili.com/x/space/arc/search?mid=99439379&ps=30&tid=0&pn=1&keyword=&order=pubdate&jsonp=jsonp
  2354. * @param mid
  2355. */
  2356. getUpAllBV: function(mid, pn, ps) {
  2357. ps = (ps === undefined ? 30 : ps); // a默认值为1
  2358. Ajax.get({
  2359. url: BILIBLI_PATH.api + '/x/space/arc/search',
  2360. queryStringsObj: {
  2361. mid: mid,
  2362. tid: 0,
  2363. order: 'pubdate',
  2364. jsonp: 'jsonp',
  2365. pn: pn,
  2366. ps: ps
  2367. },
  2368. hasCookies: true,
  2369. success: responseText => {
  2370.  
  2371. var json = JSON.parse(responseText);
  2372.  
  2373. if (json.code != 0) {
  2374.  
  2375. javaex.tip({
  2376. content: "获取up所有投稿视频失败!" + json.message,
  2377. type: "success"
  2378. });
  2379.  
  2380. } else {
  2381. BiliData.BVList = json.data.list.vlist;
  2382.  
  2383. }
  2384. }
  2385. });
  2386.  
  2387. },
  2388.  
  2389.  
  2390. /**
  2391. *
  2392. * @param path
  2393. * @param data
  2394. * @param saveObj
  2395. * @param Func
  2396. */
  2397. publicGet: function(path, queryStringsObj) {
  2398.  
  2399. if (typeof(queryStringsObj) != "undefined") {
  2400. queryStringsObj = {};
  2401. }
  2402. Ajax.get({
  2403. url: BILIBLI_PATH.api + path,
  2404. queryStringsObj: queryStringsObj,
  2405. hasCookies: true,
  2406. success: responseText => {
  2407.  
  2408. let json = JSON.parse(responseText);
  2409. if (chackCode(json.code) && json.code == 0) {
  2410.  
  2411. return json.data;
  2412. }
  2413.  
  2414. return false;
  2415.  
  2416. }
  2417. })
  2418.  
  2419. },
  2420.  
  2421. /**
  2422. * 导航栏用户信息
  2423. */
  2424. getUserNav: async function() {
  2425.  
  2426. GM_xmlhttpRequest({
  2427. method: "GET",
  2428. url: BILIBLI_PATH.api + "/x/web-interface/nav",
  2429. //timeout:3000,
  2430. onload: function(response) {
  2431.  
  2432. let json = JSON.parse(response.response);
  2433. console.log(json);
  2434. BiliData.login_code = json.code;
  2435. BiliData.login_message = json.message;
  2436. BiliData.LoginData = json.data;
  2437.  
  2438. }
  2439. });
  2440.  
  2441. },
  2442.  
  2443. /**
  2444. * 获取某up详细信息
  2445. * http://api.bilibili.com/x/web-interface/card
  2446. */
  2447. getUpCard: function(mid) {
  2448.  
  2449. Ajax.get({
  2450. url: BILIBLI_PATH.api + '/x/web-interface/card',
  2451. queryStringsObj: {
  2452. mid: mid,
  2453. photo: false
  2454. },
  2455. hasCookies: true,
  2456. success: responseText => {
  2457.  
  2458. var json = JSON.parse(responseText);
  2459.  
  2460. if (json.code != 0) {
  2461.  
  2462. javaex.tip({
  2463. content: "查询失败!" + json.message,
  2464. type: "success"
  2465. });
  2466. return false;
  2467. } else {
  2468. BiliData.upCard = json;
  2469.  
  2470. }
  2471.  
  2472.  
  2473. }
  2474. })
  2475.  
  2476. },
  2477.  
  2478. /**
  2479. *
  2480. * @param uid 用户uid
  2481. * @param ps 每页视频个数 默认30个
  2482. * @param pn 第几页
  2483. */
  2484. getUpAllVideo: function(uid, ps, pn) {
  2485.  
  2486. },
  2487. getChallenge: async function() {
  2488.  
  2489.  
  2490. },
  2491. /**
  2492. * 硬币记录
  2493. * @returns {Promise<void>}
  2494. */
  2495. getCoinLog: async function() {
  2496.  
  2497. GM_xmlhttpRequest({
  2498. method: "GET",
  2499. url: BILIBLI_PATH.api + "/x/member/web/coin/log",
  2500. //url: "http://api.bilibili.com/x/member/web/coin/log",
  2501. onload: function(response) {
  2502.  
  2503. let json = JSON.parse(response.response);
  2504. if (json.code == 0) {
  2505.  
  2506. console.log("硬币记录" + json);
  2507. BiliData.CoinLog = json.data;
  2508.  
  2509. return true;
  2510. }
  2511.  
  2512. }
  2513. });
  2514. },
  2515. /**
  2516. * 未读消息数 http://api.bilibili.com/x/msgfeed/unread
  2517. * @returns {Promise<void>}
  2518. */
  2519. getUnread: async function() {
  2520.  
  2521. Ajax.get({
  2522. url: BILIBLI_PATH.api + "/x/msgfeed/unread",
  2523. hasCookies: true,
  2524. success: responseText => {
  2525.  
  2526. let json = JSON.parse(responseText);
  2527. if (chackCode(json.code) && json.code == 0) {
  2528.  
  2529. BiliData.Unread = json.data;
  2530. showUnreadMsg();
  2531. }
  2532.  
  2533. return false;
  2534.  
  2535. }
  2536. })
  2537.  
  2538. /* GM_xmlhttpRequest({
  2539. method: "GET",
  2540. url: BILIBLI_PATH.api + "/x/msgfeed/unread",
  2541. onload: function (response) {
  2542.  
  2543. let json = JSON.parse(response.response);
  2544.  
  2545. if (chackCode(json.code) && json.code == 0) {
  2546.  
  2547. BiliData.Unread = json.code;
  2548. showUnreadMsg();
  2549.  
  2550. }
  2551.  
  2552. }
  2553. });*/
  2554. },
  2555. /**
  2556. *
  2557. * @param type reply:回复我的 at @我的
  2558. */
  2559. getMsgfeed: function(type) {
  2560. Ajax.get({
  2561. url: BILIBLI_PATH.api + '/x/msgfeed/' + type,
  2562. queryStringsObj: {
  2563. build: 0,
  2564. mobi_app: 'web'
  2565. },
  2566. hasCookies: true,
  2567. success: responseText => {
  2568.  
  2569. var json = JSON.parse(responseText);
  2570.  
  2571. if (json.code != 0 || !json.data.cursor.is_end || json.data.items == null) {
  2572. return false;
  2573. } else {
  2574. chackAtMsg(json.data.items);
  2575.  
  2576. return true;
  2577. }
  2578.  
  2579.  
  2580. }
  2581. })
  2582.  
  2583. },
  2584.  
  2585. /** 未读消息数 http://api.bilibili.com/x/space/arc/search?mid=99439379&pn=1&ps=5
  2586. * @returns {Promise<void>}
  2587. */
  2588. getUnrewad: async function() {
  2589.  
  2590. GM_xmlhttpRequest({
  2591. method: "GET",
  2592. data: {
  2593. "mid": 99439379,
  2594. "pn": 1,
  2595. "ps": 5,
  2596. },
  2597. url: BILIBLI_PATH.api + "/x/space/arc/search",
  2598. onload: function(response) {
  2599.  
  2600. let json = JSON.parse(response.response);
  2601. if (json.code == 0) {
  2602.  
  2603. BiliData.Video = json.data;
  2604. console.log("未读消息数" + json);
  2605. }
  2606.  
  2607. }
  2608. });
  2609. },
  2610.  
  2611. /** 动态评论区点赞 https://api.bilibili.com/x/v2/reply/action
  2612. * @param {number} oid
  2613. * @param {nbumber} rpid
  2614. * @param {number} action
  2615. * @returns {Promise<void>}
  2616. * type: 11
  2617. * ordering: heat
  2618. * jsonp: jsonp
  2619. * csrf: 54a******* CSRF Token(位于cookie)
  2620. */
  2621.  
  2622. likeInDynamicComments: async function(oid, rpid, action) {
  2623.  
  2624.  
  2625. Ajax.post({
  2626. url: BILIBLI_PATH.api + "/x/v2/reply/action",
  2627. hasCookies: true,
  2628. dataType: 'application/x-www-form-urlencoded; charset=UTF-8',
  2629. data: {
  2630. "oid": oid,
  2631. "type": 11,
  2632. "rpid": rpid,
  2633. "action": action,
  2634. "ordering": "heat",
  2635. "jsonp": "jsonp",
  2636. "csrf": Live_info.csrf_token,
  2637. },
  2638. success: responseText => {
  2639.  
  2640. if (/^{"code":0/.test(responseText)) {
  2641.  
  2642. BiliData.replyAction = JSON.parse(responseText);
  2643. console.log("点赞成功!" + responseText);
  2644. }
  2645. }
  2646. })
  2647.  
  2648. }
  2649.  
  2650.  
  2651. }
  2652.  
  2653. /*-----------------------------------------------常用工具函数--------------------------------------------------*/
  2654.  
  2655.  
  2656. let HNTOOL = {
  2657.  
  2658.  
  2659. copyText: function(domId) {
  2660. let btn = document.getElementById(domId);
  2661. btn.select();
  2662. if (document.execCommand('copy')) {
  2663. document.execCommand('copy');
  2664. javaex.tip({
  2665. content: "复制成功!",
  2666. type: "success"
  2667. });
  2668. }
  2669.  
  2670. },
  2671. /**
  2672. * s数组去重并排序
  2673. */
  2674.  
  2675. arrUnique: function(ary) {
  2676.  
  2677. let obj = {};
  2678. for (let i = 0; i < ary.length; i++) { //this 指向方法.前的对象ary
  2679. let item = ary[i]
  2680. obj.hasOwnProperty(item) ? (ary[i] = ary[ary.length - 1], ary.pop(), i--) : obj[item] = item
  2681. } //判断对象obj中是否有item元素,如果有 让当前元素等于数组最后一个元素,删除最后一个元素
  2682. // 如果没有 将这个元素添加到对象中
  2683. ary.sort((a, b) => {
  2684. return a - b
  2685. }) // 数组去重后 按升序排列
  2686. obj = null;
  2687.  
  2688. javaex.tip({
  2689. content: "已去重!",
  2690. type: "success"
  2691. });
  2692. return ary;
  2693.  
  2694. },
  2695.  
  2696. split_array: function(arr, len) {
  2697.  
  2698. let arr_length = arr.length;
  2699. let newArr = [];
  2700. for (let i = 0; i < arr_length; i += len) {
  2701. newArr.push(arr.slice(i, i + len));
  2702. }
  2703. return newArr;
  2704. },
  2705. strToJson: function(params) {
  2706. const isJSON = (str => {
  2707. if (typeof str === 'string') {
  2708. try {
  2709. const obj = JSON.parse(str);
  2710. return typeof obj === 'object' ? obj : false
  2711. } catch (_) {
  2712. console.log(str);
  2713. return false;
  2714. }
  2715. } else {
  2716. console.log(`${str}\nIt is not a string!`);
  2717. return false;
  2718. }
  2719. })(params);
  2720. return isJSON ? isJSON : {}
  2721. },
  2722.  
  2723. chackAtMsg: function() {
  2724.  
  2725. let config = HNTOOL.getConfig();
  2726. if (config.qmsg_checked == true && config.qmsg_key) {
  2727.  
  2728. document.getElementById("getAtMsg").click();
  2729.  
  2730. }
  2731.  
  2732. },
  2733.  
  2734. cssChecked: function(id, dom) {
  2735.  
  2736. dom == true ? $(id).attr("checked", true) : $(id).removeProp("checked");
  2737.  
  2738.  
  2739. },
  2740. getConfig: function() {
  2741.  
  2742. let CONFIG = JSON.parse(localStorage.getItem(`HN_SETUP_CONFIG`));
  2743.  
  2744. if (CONFIG == null) {
  2745. CONFIG = HN_SETUP_CONFIG;
  2746. }
  2747.  
  2748. return CONFIG;
  2749. },
  2750.  
  2751. /**
  2752. * 获取cookie 中某个键对应的值
  2753. * @param name
  2754. */
  2755.  
  2756. getCookie: function(name) {
  2757. let arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
  2758. if (arr != null) return escape(arr[2]);
  2759. return false;
  2760. },
  2761. /**
  2762. * 得到一个字符串数组的中随机一个
  2763. * @param {List} list
  2764. */
  2765. getRandomWordOfList: function(list) {
  2766. var L = list.length;
  2767. var i = Math.ceil(Math.random() * L);
  2768.  
  2769. return list[i];
  2770. },
  2771. random: function(min, max) {
  2772.  
  2773. return Math.floor(Math.random() * (max - min)) + min;
  2774. },
  2775.  
  2776. Sleep: function(ms) {
  2777. return new Promise(resolve => setTimeout(() => resolve('sleep'), ms));
  2778. }
  2779.  
  2780. }
  2781.  
  2782. let errorMsg = {
  2783. "-1": "应用程序不存在或已被封禁!",
  2784. "-2": "Access Key错误!",
  2785. "-3": "API校验密匙错误!",
  2786. "-4": "调用方对该Method没有权限!",
  2787. "-101": "账号未登录!",
  2788. "-102": "账号被封停!",
  2789. "-103": "积分不足!",
  2790. "-104": "硬币不足!",
  2791. "-105": "验证码错误!",
  2792. "-106": "账号非正式会员或在适应期!",
  2793. "-107": "应用不存在或者被封禁!",
  2794. "-108": "未绑定手机!",
  2795. "-109": "未知!",
  2796. "-110": "未绑定手机!",
  2797. "-111": "csrf 校验失败!",
  2798. "-112": "系统升级中!",
  2799. "-113": "账号尚未实名认证!",
  2800. "-114": "请先绑定手机!",
  2801. "-115": "请先完成实名认证!",
  2802. "-304": "木有改动!",
  2803. "-307": "撞车跳转!",
  2804. "-400": "请求错误!",
  2805. "-401": "未认证!",
  2806. "-403": "访问权限不足!",
  2807. "-404": "啥都木有!",
  2808. }
  2809.  
  2810. /*-----------------------------------------------CODE 统一检查--------------------------------------------------*/
  2811. /**
  2812. *
  2813. * @param code
  2814. * @constructor
  2815. */
  2816. let chackCode = function(code) {
  2817.  
  2818. let emsg = errorMsg[code + ""];
  2819. if (emsg != null) {
  2820. javaex.tip({
  2821. content: emsg,
  2822. type: "error"
  2823. });
  2824.  
  2825. return false;
  2826. }
  2827.  
  2828. return true;
  2829. }
  2830.  
  2831.  
  2832. /*-----------------------------------------------localStorage封装 (本地存储信息)--------------------------------------------------*/
  2833. //javaex.setLocalStorage(key, value); var str = javaex.getLocalStorage(key); javaex.deleteLocalStorage(key);
  2834.  
  2835. /*window.onbeforeunload = function() {
  2836. if (!canLeavePage()) {
  2837. return ('确认离开当前页面吗?未保存的数据将会丢失!');
  2838. }
  2839. };*/
  2840.  
  2841.  
  2842. /**
  2843. * Ajax请求对象
  2844. */
  2845. const Ajax = (() => {
  2846. /**
  2847. * 检查options是否符合要求
  2848. * @param {object} options
  2849. * @returns {boolean}
  2850. */
  2851. function checkOptions(options) {
  2852. let result = false;
  2853. if (typeof options !== 'object') {
  2854. console.warn('类型错误: typeof Options !== Object');
  2855. return result;
  2856. } else {
  2857. if (typeof options.url !== 'string') {
  2858. console.warn('类型错误: typeof Link !== Strings');
  2859. return result;
  2860. } else {
  2861. const reg = /^https?:\/\/(?:\w+\.?)+(?:\/.*)*\/?$/i;
  2862. if (!reg.test(options.url)) {
  2863. console.warn('url字符串须为完整http链接');
  2864. return result;
  2865. }
  2866. result = true;
  2867. }
  2868. }
  2869. return result;
  2870. }
  2871.  
  2872. /**
  2873. * 对象转URL编码
  2874. * @param {object} data
  2875. */
  2876. function objToURLCode(data) {
  2877. var _result = [];
  2878. for (var key in data) {
  2879. var value = data[key];
  2880. if (value instanceof Array) {
  2881. value.forEach(function(_value) {
  2882. _result.push(key + "=" + _value);
  2883. });
  2884. } else {
  2885. _result.push(key + '=' + value);
  2886. }
  2887. }
  2888. return _result.join('&');
  2889. }
  2890.  
  2891. /**
  2892. * 请求
  2893. * @param {string} method
  2894. * @param {object} options
  2895. */
  2896. function request(method, options) {
  2897. if (checkOptions(options)) {
  2898. let xhr = new XMLHttpRequest();
  2899. const {
  2900. url: _url,
  2901. queryStringsObj,
  2902. data,
  2903. dataType,
  2904. hasCookies
  2905. } = options, url = typeof queryStringsObj === 'object' ?
  2906. _url + '?' + objToURLCode(queryStringsObj) : _url;
  2907. switch (method) {
  2908. case 'GET':
  2909. xhr.open("GET", url);
  2910. break;
  2911. case 'POST':
  2912. xhr.open("POST", url);
  2913. xhr.setRequestHeader('Content-Type', dataType);
  2914. break;
  2915. default:
  2916. break;
  2917. }
  2918. if (hasCookies) xhr.withCredentials = true;
  2919. xhr.timeout = 3000;
  2920. xhr.addEventListener('load', () => {
  2921. if (xhr.status === 200) {
  2922. options.success(xhr.responseText)
  2923. } else {
  2924. console.error(`status:${xhr.status}`);
  2925. options.success(`{"code":${xhr.status},"msg":"频繁访问"}`);
  2926. }
  2927. })
  2928. xhr.addEventListener('error', () => {
  2929. console.error('ajax请求出错')
  2930. options.success('{"code":-1,"msg":"ajax请求出错"}');
  2931. })
  2932. xhr.addEventListener('timeout', () => {
  2933. console.error('请求超时')
  2934. options.success('{"code":-1,"msg":"请求超时"}');
  2935. })
  2936. switch (method) {
  2937. case 'GET':
  2938. xhr.send()
  2939. break;
  2940. case 'POST':
  2941. xhr.send((/urlencoded/.test(dataType)) ? objToURLCode(data) : data)
  2942. break;
  2943. default:
  2944. break;
  2945. }
  2946. }
  2947. }
  2948.  
  2949. return {
  2950. /**
  2951. * 发送Get请求
  2952. * @param {Object} options
  2953. */
  2954. get(options) {
  2955. request("GET", options);
  2956. },
  2957. /**
  2958. * 发送Post请求
  2959. * @param {object} options
  2960. */
  2961. post(options) {
  2962. request("POST", options);
  2963. }
  2964. }
  2965. })()