-哔哩猫-(试用版)

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

目前為 2021-04-11 提交的版本,檢視 最新版本

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