-哔哩猫-(试用版)

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

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

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