-哔哩猫-(试用版)

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

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

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