-哔哩猫-(试用版)

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

当前为 2021-03-28 提交的版本,查看 最新版本

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