bilibiliHelper.js 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355
  1. /*
  2. 哔哩哔哩每日任务(V1.1)
  3. 更新时间: 2024-04-06
  4. 脚本兼容: QuantumultX, Surge, Loon
  5. 脚本作者: MartinsKing(@ClydeTime)
  6. 软件功能: 登录/观看/分享/投币/直播签到/银瓜子转硬币/大会员积分签到/年度大会员每月B币券+等任务
  7. 注意事项:
  8. 抓取cookie时注意保证账号登录状态;
  9. 账号内须有一定数量的关注数,否则无法完成投币;
  10. 当硬币不足5枚,提示硬币不足,停止投币;
  11. 为保证投币任务成功, 脚本有重试机制(最多重试10次), 以确保任务完成, 前提需要您尽可能多的关注Up主;
  12. 年度大会员每月B币券会在每月1号、15号尝试领取,确保应用正常运行, 以防漏领;
  13. 年度大会员自动充电会在每次领劵之后进行, 默认为自己充电, B币多的用户可自行到boxjs设置,以防误充.
  14. 使用声明: ⚠️此脚本仅供学习与交流,请勿贩卖!⚠️
  15. 脚本参考: Nobyda、Wyatt1026、ABreadTree、chavyleung、SocialSisterYi
  16. ************************
  17. QX, Surge, Loon说明:
  18. ************************
  19. 1.获取cookie
  20. ①后台退出手机B站客户端的情况下, 重新打开APP进入主页
  21. ②通过网址「https://www.bilibili.com」登录,登录后当前网页登录状态失效
  22. 如通知成功获取cookie, 则可以使用此签到脚本.
  23. 脚本将在每天上午7点30执行.
  24. 2.投币设置
  25. 定时任务脚本投币规则为: 随机获取关注列表Up主视频, 默认5视频5硬币, 不点赞.
  26. 用户如需要不投币的版本, 请使用boxjs订阅「https://raw.githubusercontent.com/ClydeTime/BiliBili/main/boxjs/BiliBili.boxjs.json」
  27. 将投币次数置为0, 并保存即可.
  28. /***********************
  29. Surge 脚本配置:
  30. ************************
  31. # B站每日等级任务 「请在模块中添加」
  32. https://raw.githubusercontent.com/ClydeTime/BiliBili/main/modules/BiliBiliDailyBonus.sgmodule
  33. ************************
  34. Loon 远程脚本配置:
  35. ************************
  36. # B站每日等级任务 「请在插件中添加」
  37. https://raw.githubusercontent.com/ClydeTime/BiliBili/main/modules/BiliBiliDailyBonus.plugin
  38. ************************
  39. QuantumultX 远程脚本配置:
  40. ************************
  41. [rewrite local]
  42. # > 哔哩哔哩cookie
  43. ^https?:\/\/app\.bilibili\.com\/x\/resource\/fingerprint\? url script-request-header https://git.jojo21.top/shawenguan/Quantumult-X/raw/master/Scripts/bilibili/bilibiliHelper.js
  44. ^https?:\/\/m.bilibili.com/$ url script-request-header https://git.jojo21.top/shawenguan/Quantumult-X/raw/master/Scripts/bilibili/bilibiliHelper.js
  45. [MITM]
  46. hostname = m.bilibili.com,app.bilibili.com
  47. */
  48. const magicJS = MagicJS(`哔哩哔哩`, "INFO");
  49. const format = (ts, fmt = 'yyyy-MM-dd HH:mm:ss') => {
  50. return magicJS.formatDate(new Date(ts), fmt);
  51. }
  52. const check = key =>
  53. !config.hasOwnProperty(key) ||
  54. !config[key].hasOwnProperty("time") ||
  55. !(config[key]["num"] > 0) ||
  56. format(new Date().toDateString()) > config[key].time
  57. const string2object = cookie => {
  58. let obj = {}
  59. let arr = cookie.split("; ")
  60. arr.forEach(function (val) {
  61. let array = val.split("=")
  62. obj[array[0]] = array[1]
  63. })
  64. return obj
  65. }
  66. const isFlag = exec_times =>
  67. config.user.num === 0 ||
  68. config.watch.num === 0 ||
  69. config.share.num === 0 ||
  70. (config.coins.num < exec_times * 10 && Math.floor(config.user.money) > 5)
  71. const getTimestamp = (d=new Date())=>{
  72. return Math.floor(d.getTime()/1000);
  73. }
  74. const startTime = format();
  75. let cards = [];
  76. let config = {
  77. cookie: {},
  78. cookieStr: "",
  79. key: "",
  80. user: {},
  81. watch: {},
  82. share: {},
  83. coins: {},
  84. score: {}
  85. };
  86. let real_times; //实际需要投币次数
  87. async function Main() {
  88. if (magicJS.isRequest) {
  89. magicJS.logger.info("- 正在获取cookie, 请稍后");
  90. await checkHandleRequest();
  91. } else {
  92. await signBiliBili();
  93. }
  94. magicJS.notification.msg('');
  95. magicJS.done();
  96. }
  97. async function checkHandleRequest(){
  98. const request = magicJS.request;
  99. let cookieStr = request.headers.cookie || request.headers.Cookie;
  100. if(cookieStr){
  101. config.cookie = magicJS.parseCookies(cookieStr);
  102. const PStoreConfig = magicJS.data.read("bilibili_daily_bonus", {})
  103. if (PStoreConfig.cookie && PStoreConfig.cookie.bili_jct !== config.cookie.bili_jct) {
  104. if (PStoreConfig.Settings) config.Settings = PStoreConfig.Settings // 同步boxjs数据
  105. config.FirstInsert = false;
  106. magicJS.logger.info(magicJS.toStr(config));
  107. await persistentStore(config)
  108. } else if (PStoreConfig.cookie) {
  109. magicJS.logger.info("- cookie未失效,无需更新");
  110. } else {
  111. config.FirstInsert = true;
  112. await persistentStore(config);
  113. }
  114. }
  115. }
  116. async function persistentStore(config){
  117. if (config.cookie.DedeUserID) {
  118. const url = $request.url;
  119. config.key = url.match(/.*access_key=(.*?)&build/)?.[1];
  120. config.cookieStr = `DedeUserID=${config.cookie.DedeUserID}; DedeUserID__ckMd5=${config.cookie.DedeUserID__ckMd5}; SESSDATA=${config.cookie.SESSDATA}; bili_jct=${config.cookie.bili_jct}; sid=${config.cookie.sid}`;
  121. if (!config.key) { //网页方式登录
  122. let auth_code = "0", access_key = "0", login_confirm = false;
  123. auth_code = await getAuthCode();
  124. if (auth_code !== "0"){
  125. login_confirm = await loginConfirm(auth_code)
  126. }
  127. if (login_confirm){
  128. access_key = await getAccessKey(auth_code)
  129. }
  130. if (access_key !== "0") {
  131. config.key = access_key
  132. } else {
  133. magicJS.logger.info("- 获取用户access_key失败!");
  134. magicJS.notification.post(magicJS.scriptName, "🤒获取用户access_key失败!");
  135. }
  136. }
  137. const isFirstInsert = config.FirstInsert;
  138. delete config.FirstInsert;
  139. magicJS.logger.info(magicJS.toStr(config))
  140. const successMessage = magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config))
  141. ? "🎉cookie存储成功"
  142. : "🤒cookie存储失败"
  143. magicJS.notification.post(magicJS.scriptName, isFirstInsert ? "首次获取cookie" : "检测到cookie已更新", successMessage);
  144. } else {
  145. magicJS.notification.post(magicJS.scriptName, "- 尚未登录, 请登录后重新获取cookie");
  146. }
  147. }
  148. async function signBiliBili() {
  149. config = magicJS.data.read("bilibili_daily_bonus", {});
  150. if (config.cookie && await getUserInfo()) {
  151. await queryStatus();
  152. let exec_times = config.Settings?.exec; //用户设置投币次数
  153. if (!Boolean(exec_times)) {
  154. exec_times = 5;
  155. real_times = 5 - (Number(config.coins.num) / 10);
  156. } else {
  157. exec_times = Number(exec_times);
  158. real_times = Math.max(0, exec_times - (Number(config.coins.num) / 10));
  159. }
  160. let flag = isFlag(exec_times);
  161. if (flag){
  162. await dynamic();
  163. if (cards.length) {
  164. let item = cards[Math.floor(Math.random() * cards.length)];
  165. let card = magicJS.toObj(item.card);
  166. short_link = encodeURIComponent(card?.short_link_v2.replace(/\\\//g, '/'));
  167. await watch(item.desc.rid, item.desc.bvid, card.cid);
  168. await share(item.desc.rid, card.cid, short_link);
  169. } else {
  170. magicJS.logger.info("- 获取视频失败,请重试或寻求帮助");
  171. }
  172. magicJS.logger.info("3️⃣ 投币任务");
  173. if (typeof config.coins.failures !== 'undefined' && config.coins.failures > 0){
  174. config.coins.failures = 0; //重置投币失败次数
  175. }
  176. if (real_times === 0){
  177. magicJS.logger.info(`- 今日已完成 ${config.coins.time}`);
  178. } else {
  179. for (let i = 0; i < real_times; i ++) {
  180. if (Math.floor(config.user.money) <= 5) {
  181. magicJS.logger.info("- 硬币不足,投币失败");
  182. break;
  183. } else {
  184. await coin();
  185. await magicJS.utils.sleep(300); //减少频繁请求概率
  186. }
  187. }
  188. }
  189. magicJS.logger.info("---- 将尝试额外任务");
  190. } else {
  191. magicJS.logger.info("---- 经验值任务均已完成,将尝试额外任务");
  192. }
  193. await liveSign();
  194. await silver2coin();
  195. await vipScoreSign();
  196. if (config.user.vipStatus === 1) {
  197. await vipExtraEx();
  198. await vipScoreGo();
  199. await vipScoreFan();
  200. await vipScoreMovie();
  201. await vipScoreDress();
  202. await vipWatchAccept();
  203. //B币券每月尝试两次领取
  204. let day = magicJS.utils.formatTime(new Date(), 'dd');
  205. if (day === '1' || day === '15') {
  206. if (config.user.vipType === 2) {
  207. await vipPrivilege(1);
  208. await magicJS.utils.sleep(800); //延迟执行,防止领劵延迟
  209. let charge_mid = config.Settings?.charge_mid || config.user.mid; //用户设置充电id
  210. let bp_num = config.Settings?.bp_num || 5; //用户设置充电数量
  211. await Charge(charge_mid, bp_num);//充电
  212. for (let i = 2; i <= 7; i++) await vipPrivilege(i);
  213. } else if (config.user.vipType === 1) {
  214. await vipPrivilege(6);
  215. await vipPrivilege(7);
  216. }
  217. }
  218. }
  219. flag = !isFlag(exec_times);
  220. let title = `登录${config.user.num}/观看${config.watch.num}/分享${config.share.num}/投币${config.coins.num / 10}${flag ? "已完成" : "未完成"}`;
  221. magicJS.logger.info(`#### ${title}`);
  222. magicJS.logger.info(`- 登录时间: ${config.user.time || "暂无"}`);
  223. magicJS.logger.info(`- 观看时间: ${config.watch.time || "暂无"}`);
  224. magicJS.logger.info(`- 分享时间: ${config.share.time || "暂无"}`);
  225. magicJS.logger.info(`- 投币时间: ${config.coins.time || "暂无"}`);
  226. let notice = {
  227. title: `[${config.user.uname}]`,
  228. subTitle: `${flag ? "✅任务完成" : "❗️有未完成的任务"}`,
  229. content:
  230. `任务:登录(观看)${check("watch") ? "" : "+10exp"} 分享${check("share") ? "" : "+5exp"} 投币${check("coins") ? "" : "+50exp"}\n` +
  231. `经验:当前${config.user.level_info.current_exp}/下级${config.user.level_info.next_exp}/满级28800\n` +
  232. `等级:当前${config.user.level_info.current_level}级 升满级最快需${Math.ceil((config.user.v6_exp)/65)}天`,
  233. };
  234. magicJS.notification.post(notice.title, notice.subTitle, notice.content);
  235. } else {
  236. magicJS.notification.post(`任务失败`,`📅 ${startTime}`, "🤒请更新cookie")
  237. }
  238. }
  239. // async function getAuthCode() {
  240. // return new Promise((resolve, reject) => {
  241. // const body = {
  242. // appkey: "27eb53fc9058f8c3",
  243. // local_id: 0,
  244. // ts: getTimestamp()
  245. // };
  246. // const sortedBody = magicJS.objToQueryStr(Object.fromEntries(new Map(Array.from(Object.entries(body)).sort())));
  247. // const sign = md5(sortedBody + 'c2ed53a74eeefe3cf99fbd01d8c9c375');
  248. // body['sign'] = sign;
  249. // const myRequest = {
  250. // url: "https://passport.bilibili.com/x/passport-tv-login/qrcode/auth_code",
  251. // headers: {
  252. // "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
  253. // },
  254. // body: magicJS.objToQueryStr(body),
  255. // }
  256. // magicJS.http.post(myRequest).then(response => {
  257. // try {
  258. // const body = response.body;
  259. // if (body.code === 0 && body.message === "0") {
  260. // magicJS.logger.info("- 获取auth_code成功");
  261. // resolve(body.data.auth_code);
  262. // } else {
  263. // magicJS.logger.info("- 获取auth_code失败");
  264. // resolve("0");
  265. // }
  266. // } catch (e) {
  267. // magicJS.logger.error(e);
  268. // resolve();
  269. // }
  270. // }).catch(err => {
  271. // const msg = `获取AuthCode异常\n${JSON.stringify(err)}`;
  272. // magicJS.logger.error(msg);
  273. // reject(msg);
  274. // });
  275. // });
  276. // }
  277. // async function loginConfirm(auth_code) {
  278. // return new Promise((resolve, reject) => {
  279. // const body = {
  280. // auth_code,
  281. // build: 7082000,
  282. // csrf: config.cookie.bili_jct
  283. // };
  284. // const myRequest = {
  285. // url: "https://passport.bilibili.com/x/passport-tv-login/h5/qrcode/confirm",
  286. // headers: {
  287. // "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
  288. // 'cookie': `DedeUserID=${config.cookie.DedeUserID}; SESSDATA=${config.cookie.SESSDATA}`
  289. // },
  290. // body: magicJS.objToQueryStr(body),
  291. // };
  292. // magicJS.http.post(myRequest).then(response => {
  293. // try {
  294. // const body = response.body;
  295. // if (body.code === 0 && body.message === "0") {
  296. // magicJS.logger.info("- 确认登录成功")
  297. // resolve(true);
  298. // } else {
  299. // magicJS.logger.info("- 确认登录失败")
  300. // resolve(false);
  301. // }
  302. // } catch (e) {
  303. // magicJS.logger.error(e);
  304. // resolve();
  305. // }
  306. // }).catch(err => {
  307. // const msg = `确认登录异常\n${JSON.stringify(err)}`;
  308. // magicJS.logger.error(msg);
  309. // reject(msg);
  310. // });
  311. // });
  312. // }
  313. // async function getAccessKey(auth_code) {
  314. // return new Promise((resolve, reject) => {
  315. // const body = {
  316. // appkey: "27eb53fc9058f8c3",
  317. // auth_code,
  318. // local_id: 0,
  319. // ts: getTimestamp()
  320. // }
  321. // const sortedBody = magicJS.objToQueryStr(Object.fromEntries(new Map(Array.from(Object.entries(body)).sort())));
  322. // const sign = md5(sortedBody + 'c2ed53a74eeefe3cf99fbd01d8c9c375');
  323. // body['sign'] = sign;
  324. // const myRequest = {
  325. // url: "https://passport.bilibili.com/x/passport-tv-login/qrcode/poll",
  326. // headers: {
  327. // "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
  328. // },
  329. // body: magicJS.objToQueryStr(body),
  330. // };
  331. // magicJS.http.post(myRequest).then(response => {
  332. // try {
  333. // const body = response.body;
  334. // if (body.code === 0 && body.message === "0") {
  335. // magicJS.logger.info("- 获取access_key成功");
  336. // resolve(body.data.access_token);
  337. // } else {
  338. // magicJS.logger.info("- 获取access_key失败");
  339. // resolve("0");
  340. // }
  341. // } catch (e) {
  342. // magicJS.logger.error(e);
  343. // resolve();
  344. // }
  345. // }).catch(err => {
  346. // const msg = `获取AccessKey异常\n${JSON.stringify(err)}`;
  347. // magicJS.logger.error(msg);
  348. // reject(msg);
  349. // });
  350. // });
  351. // }
  352. // async function watch(aid, bvid, cid) {
  353. // return new Promise((resolve, reject) => {
  354. // magicJS.logger.info("1️⃣ 观看(登录)任务");
  355. // if (check("watch")) {
  356. // magicJS.logger.info(`- 正在观看(登录)(${bvid})`);
  357. // const body = {
  358. // aid,
  359. // cid,
  360. // bvid,
  361. // mid: config.user.mid,
  362. // csrf: config.cookie.bili_jct,
  363. // played_time : 1,
  364. // real_played_time: 1,
  365. // realtime: 1,
  366. // start_ts: getTimestamp(),
  367. // type: 3,
  368. // dt: 2,
  369. // play_type: 0,
  370. // from_spmid: 0,
  371. // spmid: 0,
  372. // auto_continued_play: 0,
  373. // refer_url: "https%3A%2F%2Ft.bilibili.com%2F",
  374. // bsource: ""
  375. // };
  376. // const myRequest = {
  377. // url: 'https://api.bilibili.com/x/click-interface/web/heartbeat',
  378. // headers: {
  379. // "cookie": config.cookieStr,
  380. // "referrer": `https://www.bilibili.com/video/${bvid}`
  381. // },
  382. // body: magicJS.objToQueryStr(body),
  383. // };
  384. // magicJS.http.post(myRequest).then(response => {
  385. // const body = response.body;
  386. // if (body?.code === 0) {
  387. // magicJS.logger.info(`- 累计观看(登录)次数 ${(config.watch.num || 0) + 1}`);
  388. // config.user.num = (config.user.num || 0) + 1;
  389. // config.watch.num = (config.watch.num || 0) + 1;
  390. // magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config));
  391. // } else {
  392. // magicJS.logger.info("- 观看失败, 失败原因: " + body?.message);
  393. // }
  394. // resolve(body);
  395. // }).catch(err => {
  396. // const msg = `观看异常\n${JSON.stringify(err)}`;
  397. // magicJS.logger.error(msg);
  398. // reject();
  399. // });
  400. // } else {
  401. // magicJS.logger.info(`- 今日已经观看 ${config.watch.time}`);
  402. // resolve();
  403. // }
  404. // });
  405. // }
  406. async function share(aid, cid, short_link) {
  407. return new Promise((resolve, reject) => {
  408. magicJS.logger.info("2️⃣ 分享任务");
  409. if (check("share")) {
  410. magicJS.logger.info("- 正在分享, aid=" + aid);
  411. const body = {
  412. access_key: config.key.replace(/&actionKey=.*?&appkey=.*$/, ''),
  413. actionKey: 'appkey',
  414. appkey: '27eb53fc9058f8c3',
  415. build: '72700100',
  416. c_locale: 'zh-Hans_CN',
  417. device: 'phone',
  418. disable_rcmd: 0,
  419. link: short_link,
  420. mobi_app: 'iphone',
  421. object_extra_fields: '%7B%7D',
  422. oid: aid,
  423. panel_type: 1,
  424. platform: 'ios',
  425. s_locale:'zh-Hans_CN',
  426. share_channel: 'WEIXIN',
  427. share_id: 'main.ugc-video-detail.0.0.pv',
  428. share_origin: 'vinfo_share',
  429. sid: cid,
  430. spm_id: 'main.ugc-video-detail.0.0',
  431. statistics: '%7B%22appId%22%3A1%2C%22version%22%3A%227.27.0%22%2C%22abtest%22%3A%22%22%2C%22platform%22%3A1%7D',
  432. success: 1,
  433. ts: getTimestamp()
  434. }
  435. const sign = md5(magicJS.objToQueryStr(body) + 'c2ed53a74eeefe3cf99fbd01d8c9c375');
  436. body['sign'] = sign;
  437. const myRequest = {
  438. url: 'https://api.bilibili.com/x/share/finish',
  439. headers: {},
  440. body: magicJS.objToQueryStr(Object.fromEntries(new Map(Array.from(Object.entries(body)).sort())))
  441. };
  442. magicJS.http.post(myRequest).then(response => {
  443. const body = response.body;
  444. if (body?.code === 0) {
  445. config.share.num = (config.share.num || 0) + 1;
  446. magicJS.logger.info("- 分享成功");
  447. magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config));
  448. } else {
  449. magicJS.logger.info("- 分享失败, 失败原因: " + body?.message);
  450. }
  451. resolve(body);
  452. }).catch(err => {
  453. const msg = `分享异常\n${JSON.stringify(err)}`;
  454. magicJS.logger.error(msg);
  455. reject();
  456. });
  457. } else {
  458. magicJS.logger.info(`- 今日已经分享 ${config.share.time}`);
  459. resolve();
  460. }
  461. });
  462. }
  463. async function coin() {
  464. return new Promise((resolve, reject) => {
  465. if (config.coins.num >= 50) {
  466. magicJS.logger.info(`- 今日已完成 ${config.coins.time}`);
  467. resolve();
  468. return;
  469. }
  470. let like_uid_list = await getFavUid()
  471. if (like_uid_list && like_uid_list.length > 0) {
  472. let aid = await getFavAid(like_uid_list)
  473. //magicJS.logger.info("即将投币的视频aid: " + aid)
  474. if (aid !== 0) {
  475. const body = {
  476. aid,
  477. multiply: 1,
  478. select_like: 0,
  479. cross_domain: true,
  480. csrf: config.cookie.bili_jct
  481. }
  482. const myRequest = {
  483. url: "https://api.bilibili.com/x/web-interface/coin/add",
  484. headers: {
  485. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
  486. 'accept': 'application/json, text/plain, */*',
  487. 'content-type': 'application/x-www-form-urlencoded',
  488. 'origin': 'https://www.bilibili.com',
  489. 'referer': 'https://www.bilibili.com/video/BV1MT411G7fG?vd_source=1970993e2eff4af7be029aefcfa468b8',
  490. 'cookie': config.cookieStr + ';buvid3=fuckchenruilovelaoliu'
  491. },
  492. body: magicJS.objToQueryStr(body)
  493. }
  494. magicJS.http.post(myRequest).then(async response => {
  495. try {
  496. const body = response.body;
  497. if (body?.code === 0 && body?.message === "0") {
  498. magicJS.logger.info("- 投币成功");
  499. config.user.money -= 1;
  500. config.coins.num += 10;
  501. magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config));
  502. } else {
  503. magicJS.logger.info("- 投币失败,失败原因 " + body.message);
  504. config.coins.failures = (config.coins.failures === 0 || typeof config.coins.failures === 'undefined' ? 1 : config.coins.failures + 1);
  505. magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config));
  506. if (config.coins.failures < 11) {
  507. magicJS.logger.info("- 正在重试...重试次数 " + (config.coins.failures - 1) + "(超过十次不再重试)");
  508. // await coin();
  509. }
  510. }
  511. } catch (e) {
  512. magicJS.logger.error(e);
  513. } finally {
  514. resolve();
  515. }
  516. }).catch(err => {
  517. const msg = `投币异常\n${JSON.stringify(err)}`;
  518. magicJS.logger.error(msg);
  519. reject();
  520. });
  521. } else {
  522. magicJS.logger.info("获取随机投币视频失败");
  523. resolve();
  524. }
  525. } else {
  526. magicJS.logger.info("获取随机关注用户列表失败");
  527. resolve();
  528. }
  529. });
  530. }
  531. async function getFavUid() {
  532. return new Promise((resolve, reject) => {
  533. const myRequest = {
  534. url: `https://api.bilibili.com/x/relation/followings?vmid=${config.cookie.DedeUserID}&ps=10&order_type=attention`,
  535. headers: {
  536. 'cookie': config.cookieStr
  537. }
  538. };
  539. magicJS.http.get(myRequest).then(response => {
  540. try {
  541. const body = response.body;
  542. let like_uid_list = new Array();
  543. if (body?.code === 0) {
  544. magicJS.logger.info("- 获取关注列表成功");
  545. let like_list = body?.data?.list;
  546. for (let i = 0; i < like_list.length; i ++) {
  547. like_uid_list[i] = like_list[i].mid;
  548. }
  549. resolve(like_uid_list);
  550. } else {
  551. magicJS.logger.info("- 获取关注列表成失败");
  552. magicJS.logger.info("- 失败原因 " + body?.message);
  553. resolve(like_uid_list);
  554. }
  555. } catch (e) {
  556. magicJS.logger.error(JSON.stringify(e));
  557. resolve();
  558. }
  559. }).catch(err => {
  560. const msg = `获取关注列表异常\n${JSON.stringify(err)}`;
  561. magicJS.logger.error(msg);
  562. reject();
  563. });
  564. });
  565. }
  566. async function getFavAid(arr) {
  567. return new Promise((resolve, reject) => {
  568. //magicJS.logger.info("- 获取关注列表中的随机视频")
  569. let random_int = Math.floor((Math.random()*arr.length));
  570. let random_mid = arr[random_int];
  571. let wbiSigns = getWbiSigns({mid: random_mid});
  572. const myRequest = {
  573. url: `https://api.bilibili.com/x/space/wbi/arc/search?${wbiSigns}`,
  574. headers: {
  575. 'cookie': config.cookieStr
  576. }
  577. };
  578. magicJS.http.get(myRequest).then(response => {
  579. try {
  580. const body = response.body;
  581. if (body?.code === 0) {
  582. magicJS.logger.info("- 获取投币视频成功");
  583. let vlist = body.data?.list?.vlist;
  584. let random_v_int = Math.floor((Math.random() * vlist.length));
  585. let aid = vlist[random_v_int]?.aid;
  586. magicJS.logger.info("- 作者: " + vlist[random_v_int]['author'] + "; 视频标题: " + vlist[random_v_int]['title']);
  587. resolve(aid);
  588. } else {
  589. magicJS.logger.info("- 获取投币视频失败");
  590. magicJS.logger.info("- 失败原因 " + body?.message);
  591. resolve(0);
  592. }
  593. } catch (e) {
  594. magicJS.logger.error(e);
  595. resolve();
  596. }
  597. }, reason => {
  598. magicJS.logger.info("- 获取投币视频失败");
  599. magicJS.logger.info("- 失败原因 " + magicJS.toStr(reason));
  600. resolve(0);
  601. }).catch(err => {
  602. const msg = `获取投币视频异常\n${JSON.stringify(err)}`;
  603. magicJS.logger.error(msg);
  604. reject();
  605. });
  606. });
  607. }
  608. async function silver2coin() {
  609. return new Promise((resolve, reject) => {
  610. magicJS.logger.info("#### 银瓜子兑换硬币任务");
  611. const body = {
  612. csrf: config.cookie.bili_jct,
  613. csrf_token: config.cookie.bili_jct
  614. };
  615. const myRequest = {
  616. url: "https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin",
  617. headers: {
  618. 'cookie': config.cookieStr
  619. },
  620. body: magicJS.objToQueryStr(body)
  621. };
  622. magicJS.http.get(myRequest).then(response => {
  623. try {
  624. let result = response.body;
  625. let title = `银瓜子转硬币`;
  626. // 兑换成功
  627. if (result && result.code === 0) {
  628. let subTitle = `- ${result.message}`;
  629. let detail = `- 成功兑换: ${result.data.coin} 个硬币\n当前银瓜子: ${result.data.silver} , 当前金瓜子: ${result.data.gold}`;
  630. magicJS.logger.info(subTitle);
  631. magicJS.logger.info(detail);
  632. magicJS.notification.post(title, subTitle, detail);
  633. }
  634. // 兑换中止(重复兑换&银瓜子不足)
  635. else if (result && result.code === 403) {
  636. let subTitle = "- 未成功兑换";
  637. let detail = `- 原因: ${result.message}`;
  638. magicJS.logger.info(subTitle);
  639. magicJS.logger.info(detail);
  640. magicJS.notification.post(title, subTitle, detail);
  641. }
  642. // 兑换失败
  643. else {
  644. let subTitle = "- 兑换失败";
  645. let detail = `- 原因: ${result.message}`;
  646. magicJS.logger.info(subTitle);
  647. magicJS.logger.info(detail);
  648. magicJS.notification.post(title, subTitle, detail);
  649. }
  650. } catch (e) {
  651. magicJS.logger.error(e);
  652. } finally {
  653. resolve();
  654. }
  655. }).catch(err => {
  656. const msg = `兑换异常\n${JSON.stringify(err)}`;
  657. magicJS.logger.error(msg);
  658. reject(msg);
  659. });
  660. });
  661. }
  662. async function liveSign() {
  663. return new Promise((resolve, reject) => {
  664. magicJS.logger.info("#### 直播签到任务");
  665. const myRequest = {
  666. url: "https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign",
  667. headers: {
  668. 'cookie': config.cookieStr
  669. }
  670. };
  671. magicJS.http.get(myRequest).then(response => {
  672. try {
  673. let body = response.body;
  674. if (body?.code === 0) {
  675. magicJS.logger.info("- 签到成功");
  676. magicJS.logger.info(`签到奖励:${body.data.text},连续签到${body.data.hadSignDays}天`);
  677. } else if (body && body.code === 1011040){
  678. magicJS.logger.info("- 今日已完成");
  679. } else {
  680. magicJS.logger.info("- 签到失败");
  681. magicJS.logger.info("- 失败原因 " + body?.message);
  682. }
  683. } catch (e) {
  684. magicJS.logger.error(e);
  685. } finally {
  686. resolve();
  687. }
  688. }).catch(err => {
  689. const msg = `签到异常\n${JSON.stringify(err)}`;
  690. magicJS.logger.error(msg);
  691. reject(msg);
  692. });
  693. });
  694. }
  695. async function vipScoreSign() {
  696. return new Promise((resolve, reject) => {
  697. magicJS.logger.info("#### 大会员大积分签到任务");
  698. if (config.user.vipStatus === 0) {
  699. magicJS.logger.info("- 当前用户非大会员, 无法完成任务");
  700. resolve();
  701. } else {
  702. if (check("score")) {
  703. const myRequest = {
  704. url: "https://api.bilibili.com/pgc/activity/score/task/sign",
  705. method: "POST",
  706. headers: {
  707. 'Referer': 'https://big.bilibili.com/mobile/bigPoint/task',
  708. 'cookie': config.cookieStr
  709. }
  710. };
  711. magicJS.http.get(myRequest).then(response => {
  712. try {
  713. const body = response.body;
  714. if (body?.code === 0 && body?.message === "success") {
  715. magicJS.logger.info("- 签到成功")
  716. config.score.time = startTime
  717. config.score.num = 1
  718. magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config))
  719. } else {
  720. magicJS.logger.info("- 签到失败")
  721. magicJS.logger.info("- 失败原因 " + body?.message)
  722. }
  723. } catch (e) {
  724. magicJS.logger.error(e);
  725. } finally {
  726. resolve();
  727. }
  728. }).catch(err => {
  729. const msg = `签到异常\n${JSON.stringify(err)}`;
  730. magicJS.logger.error(msg);
  731. reject();
  732. });
  733. } else {
  734. magicJS.logger.info("- 今日已完成");
  735. resolve();
  736. }
  737. }
  738. });
  739. }
  740. // async function vipExtraEx() {
  741. // return new Promise((resolve, reject) => {
  742. // magicJS.logger.info("#### 大会员每日额外经验值");
  743. // const body = {
  744. // csrf: config.cookie.bili_jct,
  745. // ts: getTimestamp(),
  746. // buvid: config.cookie.Buvid,
  747. // mobi_app: 'iphone',
  748. // platform: 'ios',
  749. // appkey: '27eb53fc9058f8c3',
  750. // access_key: config.key
  751. // };
  752. // const sortedBody = magicJS.objToQueryStr(Object.fromEntries(new Map(Array.from(Object.entries(body)).sort())));
  753. // const sign = md5(sortedBody + 'c2ed53a74eeefe3cf99fbd01d8c9c375');
  754. // body['sign'] = sign;
  755. // const myRequest = {
  756. // url: "https://api.bilibili.com/x/vip/experience/add",
  757. // headers: {
  758. // 'accept': 'application/json, text/plain, */*',
  759. // 'app-key': 'iphone'
  760. // },
  761. // body: magicJS.objToQueryStr(body)
  762. // };
  763. // magicJS.http.get(myRequest).then(response => {
  764. // try {
  765. // const body = response.body;
  766. // if (body?.code === 0 && body?.message === "0") {
  767. // magicJS.logger.info("- 成功获得10经验值");
  768. // } else {
  769. // magicJS.logger.info("- 每日额外经验任务失败");
  770. // magicJS.logger.info("- 失败原因 " + body?.message);
  771. // }
  772. // } catch (e) {
  773. // magicJS.logger.error(e);
  774. // }
  775. // resolve();
  776. // }).catch(err => {
  777. // const msg = `获取额外经验异常\n${JSON.stringify(err)}`;
  778. // magicJS.logger.error(msg);
  779. // reject();
  780. // });
  781. // });
  782. // }
  783. // async function vipScoreGo() {
  784. // return new Promise((resolve, reject) => {
  785. // magicJS.logger.info("#### 大会员浏览会员购10s任务");
  786. // const myRequest = {
  787. // url: "https://show.bilibili.com/api/activity/fire/common/event/dispatch",
  788. // headers: {
  789. // 'Content-Type' : 'application/json',
  790. // 'Cookie': config.cookieStr
  791. // },
  792. // body: `{"eventId":"hevent_oy4b7h3epeb"}`
  793. // };
  794. // magicJS.http.get(myRequest).then(response => {
  795. // try {
  796. // const body = response.body;
  797. // if (body?.code === 0 && body?.message === "SUCCESS") {
  798. // magicJS.logger.info("- 成功获得10点大积分");
  799. // } else {
  800. // magicJS.logger.info("- 浏览会员购任务失败");
  801. // magicJS.logger.info("- 失败原因 " + body?.message);
  802. // }
  803. // } catch (e) {
  804. // magicJS.logger.error(e);
  805. // }
  806. // resolve();
  807. // }).catch(err => {
  808. // const msg = `浏览会员购任务异常\n${JSON.stringify(err)}`;
  809. // magicJS.logger.error(msg);
  810. // reject();
  811. // });
  812. // });
  813. // }
  814. // async function vipScoreFan() {
  815. // return new Promise((resolve, reject) => {
  816. // magicJS.logger.info("#### 大会员浏览追番频道10s任务");
  817. // const myRequest = {
  818. // url: `https://api.bilibili.com/pgc/activity/deliver/task/complete?access_key=${config.key}&position=jp_channel&sign=768d600feba34e6d1109e4157c0f0c5f&task_sign=557D1ACE13E9E81393259FFB621D6D0E`,
  819. // method: "POST",
  820. // headers: {}
  821. // };
  822. // magicJS.http.get(myRequest).then(response => {
  823. // try {
  824. // const body = response.body;
  825. // if (body?.code === 0 && body?.message === "success") {
  826. // magicJS.logger.info("- 成功获得10点大积分");
  827. // } else {
  828. // magicJS.logger.info("- 浏览追番频道任务失败");
  829. // magicJS.logger.info("- 失败原因 " + body?.message);
  830. // }
  831. // } catch (e) {
  832. // magicJS.logger.error(e);
  833. // }
  834. // resolve();
  835. // }).catch(err => {
  836. // const msg = `浏览追番频道任务异常\n${JSON.stringify(err)}`;
  837. // magicJS.logger.error(msg);
  838. // reject();
  839. // });
  840. // });
  841. // }
  842. // async function vipScoreMovie() {
  843. // return new Promise((resolve, reject) => {
  844. // magicJS.logger.info("#### 大会员浏览影视频道10s任务");
  845. // const myRequest = {
  846. // url: `https://api.bilibili.com/pgc/activity/deliver/task/complete?access_key=${config.key}&position=tv_channel&sign=09ece1c295cb86d74778b93c59c0da3a&task_sign=B7DA5FAE25C39F53C62C03076CF2878B`,
  847. // method: "POST",
  848. // headers: {}
  849. // };
  850. // magicJS.http.get(myRequest).then(response => {
  851. // try {
  852. // const body = response.body;
  853. // if (body?.code === 0 && body?.message === "success") {
  854. // magicJS.logger.info("- 成功获得10点大积分");
  855. // } else {
  856. // magicJS.logger.info("- 浏览影视频道任务失败");
  857. // magicJS.logger.info("- 失败原因 " + body?.message);
  858. // }
  859. // } catch (e) {
  860. // magicJS.logger.error(e);
  861. // }
  862. // resolve();
  863. // }).catch(err => {
  864. // const msg = `浏览影视频道任务异常\n${JSON.stringify(err)}`;
  865. // magicJS.logger.error(msg);
  866. // reject();
  867. // });
  868. // });
  869. // }
  870. // async function vipScoreDress() {
  871. // return new Promise((resolve, reject) => {
  872. // magicJS.logger.info("#### 大会员浏览装扮商城主页任务");
  873. // const body = {
  874. // csrf: config.cookie.bili_jct,
  875. // ts: getTimestamp(),
  876. // taskCode: 'dress-view',
  877. // access_key: config.key
  878. // };
  879. // const myRequest = {
  880. // url: 'https://api.bilibili.com/pgc/activity/score/task/complete/v2',
  881. // headers: {},
  882. // body: magicJS.objToQueryStr(body)
  883. // };
  884. // magicJS.http.get(myRequest).then(response => {
  885. // try {
  886. // const body = response.body;
  887. // if (body?.code === 0 && body?.message === "success") {
  888. // magicJS.logger.info("- 成功获得10点大积分");
  889. // } else {
  890. // magicJS.logger.info("- 浏览装扮商城主页任务失败");
  891. // }
  892. // } catch (e) {
  893. // magicJS.logger.error(e);
  894. // }
  895. // resolve();
  896. // }).catch(err => {
  897. // const msg = `浏览装扮商城主页任务异常\n${JSON.stringify(err)}`;
  898. // magicJS.logger.error(msg);
  899. // reject();
  900. // });
  901. // });
  902. // }
  903. // async function vipWatchAccept() {
  904. // return new Promise((resolve, reject) => {
  905. // magicJS.logger.info("#### 接取大会员观看剧集10min任务");
  906. // const body = {
  907. // csrf: config.cookie.bili_jct,
  908. // ts: getTimestamp(),
  909. // taskCode: 'ogvwatchnew',
  910. // mobi_app: 'iphone',
  911. // platform: 'ios',
  912. // appkey: '27eb53fc9058f8c3',
  913. // access_key: config.key
  914. // };
  915. // const sortedBody = magicJS.objToQueryStr(Object.fromEntries(new Map(Array.from(Object.entries(body)).sort())));
  916. // const sign = md5(sortedBody + 'c2ed53a74eeefe3cf99fbd01d8c9c375');
  917. // body['sign'] = sign
  918. // const myRequest = {
  919. // url: 'https://api.bilibili.com/pgc/activity/score/task/receive/v2',
  920. // headers: {
  921. // 'Content-Type': 'application/x-www-form-urlencoded',
  922. // 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_6_1 like Mac OS X) AppleWebKit/615.2.9.10.4 (KHTML, like Gecko) Mobile/20F75 BiliApp/77200100 os/ios model/iPhone 15 Pro Max mobi_app/iphone build/77200100 osVer/17.4.1 network/2 channel/AppStore c_locale/zh-Hans_CN s_locale/zh-Hans_CN disable_rcmd/0',
  923. // 'Cookie': `SESSDATA=${config.cookie.SESSDATA}`,
  924. // 'Referer': `https://big.bilibili.com/mobile/bigPoint/task`
  925. // },
  926. // body: magicJS.objToQueryStr(body)
  927. // };
  928. // magicJS.http.get(myRequest).then(response => {
  929. // try {
  930. // const body = response.body;
  931. // if (body?.code === 0 && body?.message === "success") {
  932. // magicJS.logger.info("- 大会员观看剧集任务接取成功, 需自行观看");
  933. // } else {
  934. // magicJS.logger.info("- 大会员观看剧集任务接取失败");
  935. // magicJS.logger.info("- 失败原因 " + body?.message);
  936. // }
  937. // } catch (e) {
  938. // magicJS.logger.error(e);
  939. // }
  940. // resolve();
  941. // }).catch(err => {
  942. // const msg = `大会员观看剧集任务异常\n${JSON.stringify(err)}`;
  943. // magicJS.logger.error(msg);
  944. // reject();
  945. // });
  946. // });
  947. // }
  948. // async function vipPrivilege(type) {
  949. // return new Promise((resolve, reject) => {
  950. // magicJS.logger.info("#### 领取大会员月度福利");
  951. // const body = {
  952. // csrf: config.cookie.bili_jct,
  953. // type
  954. // };
  955. // const myRequest = {
  956. // url: 'https://api.bilibili.com/x/vip/privilege/receive',
  957. // headers: {
  958. // 'Cookie': config.cookieStr
  959. // },
  960. // body: magicJS.objToQueryStr(body)
  961. // };
  962. // magicJS.http.get(myRequest).then(response => {
  963. // try {
  964. // const body = response.body;
  965. // if (body?.code === 0) {
  966. // switch (type) {
  967. // case 1:
  968. // magicJS.logger.info("- 领取年度大会员每月B币券成功");
  969. // magicJS.notification.post("年度大会员月度福利", "B币券", "🎉🎉🎉领取成功");
  970. // break
  971. // case 2:
  972. // magicJS.logger.info("- 领取年度大会员每月会员购优惠券成功");
  973. // break
  974. // case 3:
  975. // magicJS.logger.info("- 领取年度大会员每月漫画福利券成功");
  976. // break
  977. // case 4:
  978. // magicJS.logger.info("- 领取年度大会员每月会员购包邮券成功");
  979. // break
  980. // case 5:
  981. // magicJS.logger.info("- 领取年度大会员每月漫画商城优惠券成功");
  982. // break
  983. // case 6:
  984. // magicJS.logger.info("- 领取大会员每月装扮体验卡成功");
  985. // break
  986. // case 7:
  987. // magicJS.logger.info("- 领取大会员每月课堂优惠券成功");
  988. // break
  989. // default:
  990. // break
  991. // }
  992. // } else {
  993. // magicJS.logger.info("- 领取大会员每月福利失败, 福利编码为" + type);
  994. // magicJS.logger.info("- 失败原因 " + body?.message);
  995. // if (type === 1) {
  996. // magicJS.notification.post("年度大会员月度福利", "B币券领取失败", "失败原因为: " + body?.message);
  997. // }
  998. // //其他福利没什么用,失败也无需单独通知
  999. // }
  1000. // } catch (e) {
  1001. // magicJS.logger.error(e);
  1002. // }
  1003. // resolve();
  1004. // }).catch(err => {
  1005. // const msg = `领取大会员月度福利异常\n${JSON.stringify(err)}`;
  1006. // magicJS.logger.error(msg);
  1007. // reject();
  1008. // });
  1009. // });
  1010. // }
  1011. // async function Charge(mid, bp_num) {
  1012. // return new Promise((resolve, reject) => {
  1013. // magicJS.logger.info("#### B币券自动充电");
  1014. // const body = {
  1015. // bp_num,
  1016. // is_bp_remains_prior: true,
  1017. // up_mid: mid,
  1018. // otype: 'up',
  1019. // oid: mid,
  1020. // csrf: config.cookie.bili_jct
  1021. // };
  1022. // const myRequest = {
  1023. // url: 'https://api.bilibili.com/x/ugcpay/web/v2/trade/elec/pay/quick',
  1024. // headers: {
  1025. // 'Cookie': config.cookieStr
  1026. // },
  1027. // body: magicJS.objToQueryStr(body)
  1028. // };
  1029. // magicJS.http.get(myRequest).then(response => {
  1030. // try {
  1031. // const body = response.body;
  1032. // if (body?.code === 0) {
  1033. // if (body?.data?.status === 4) {
  1034. // if (mid === config.user.mid) {
  1035. // magicJS.logger.info("- 为自己充电成功");
  1036. // } else {
  1037. // magicJS.logger.info(`- 为用户id为${mid}的用户充电成功`);
  1038. // }
  1039. // } else if (body?.data?.status === -4) {
  1040. // magicJS.logger.info("- 充电失败, B币不足");
  1041. // } else {
  1042. // magicJS.logger.info("- 充电失败");
  1043. // magicJS.logger.info("- 失败原因 " + body?.message);
  1044. // }
  1045. // } else {
  1046. // magicJS.logger.info("- 充电失败");
  1047. // magicJS.logger.info("- 失败原因 " + body?.message);
  1048. // }
  1049. // } catch (e) {
  1050. // magicJS.logger.error(e);
  1051. // }
  1052. // resolve();
  1053. // }).catch(err => {
  1054. // const msg = `充电异常\n${JSON.stringify(err)}`;
  1055. // magicJS.logger.error(msg);
  1056. // reject();
  1057. // });
  1058. // });
  1059. // }
  1060. async function getUserInfo() {
  1061. return new Promise((resolve, reject) => {
  1062. magicJS.logger.info("#### 用户信息");
  1063. const myRequest = {
  1064. url: 'https://api.bilibili.com/x/web-interface/nav',
  1065. headers: {
  1066. "cookie": config.cookieStr
  1067. }
  1068. };
  1069. magicJS.http.get(myRequest).then(response => {
  1070. try {
  1071. const body = response.body;
  1072. if (body?.code) {
  1073. magicJS.logger.info("- ❌❌获得用户信息失败(请更新cookie)");
  1074. magicJS.data.write("bilibili_daily_bonus", null);
  1075. resolve(false);
  1076. } else {
  1077. magicJS.logger.info("- 🎉cookie有效任务即将开始🎉");
  1078. config.user = body?.data;
  1079. config.user.num = check("user") ? 1 : (config.user.num || 0) + 1;
  1080. magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config));
  1081. config.user.mext_exp = config.user.level_info.next_exp - config.user.level_info.current_exp;
  1082. config.user.next_day = Math.ceil(config.user.mext_exp / 15);
  1083. config.user.v6_exp = 28800 - config.user.level_info.current_exp;
  1084. config.user.v6_day = Math.ceil(config.user.v6_exp / 15);
  1085. if (config.user.vipStatus === 1) {
  1086. magicJS.logger.log("- 💖尊贵的大会员用户💖");
  1087. }
  1088. magicJS.logger.log("- 用户名称: " + config.user.uname);
  1089. magicJS.logger.log("- 用户ID: " + config.user.mid);
  1090. magicJS.logger.log("- 用户硬币: " + Math.floor(config.user.money));
  1091. magicJS.logger.log("- 用户B币: " + config.user.wallet.bcoin_balance);
  1092. magicJS.logger.log("- 用户等级: " + config.user.level_info.current_level);
  1093. magicJS.logger.log(
  1094. `- 当前经验: ${config.user.level_info.current_exp}/${config.user.level_info.next_exp}`
  1095. );
  1096. magicJS.logger.log(`- 升级还需经验: ${config.user.mext_exp}`);
  1097. magicJS.logger.log(
  1098. `- 距离下级还需: ${config.user.next_day}天(登录 观看 分享)`
  1099. );
  1100. magicJS.logger.log(
  1101. `- 距离满级还需: ${Math.max(0, config.user.v6_day)}天(登录 观看 分享)`
  1102. );
  1103. magicJS.logger.log(`- 剩余硬币最多可投: ${Math.floor((config.user.money)/5)}天`);
  1104. magicJS.logger.log(
  1105. "- 距离满级最快还需: " +
  1106. Math.max(0, Math.ceil(config.user.v6_exp / 65)) +
  1107. "天(日常 + 投币*5)"
  1108. );
  1109. resolve(true);
  1110. }
  1111. } catch (e) {
  1112. magicJS.logger.error(JSON.stringify(e));
  1113. resolve();
  1114. }
  1115. }, reason => {
  1116. magicJS.notification.post(magicJS.scriptName, "- 获取用户信息失败", magicJS.toStr(reason));
  1117. resolve(false);
  1118. }).catch(err => {
  1119. const msg = `用户信息异常\n${JSON.stringify(err)}`;
  1120. magicJS.logger.error(msg);
  1121. reject();
  1122. });
  1123. });
  1124. }
  1125. async function queryStatus() {
  1126. return new Promise((resolve, reject) => {
  1127. magicJS.logger.info("#### 检查任务进行状况");
  1128. const myRequest = {
  1129. url: "https://api.bilibili.com/x/member/web/exp/reward",
  1130. headers: {
  1131. "cookie": config.cookieStr
  1132. }
  1133. };
  1134. magicJS.http.get(myRequest).then(response => {
  1135. try {
  1136. const body = response.body;
  1137. if (body?.code === 0) {
  1138. if (body.data.login) {
  1139. magicJS.logger.info("- 今日已登录");
  1140. config.user.num = (config.user.num === 0 ? 1 : config.user.num);
  1141. if (!config['user'].hasOwnProperty("time")) {
  1142. config.user.time = startTime;
  1143. }
  1144. } else {
  1145. magicJS.logger.info("! 今日尚未登录");
  1146. config.user.num = 0;
  1147. }
  1148. if (body.data.watch){
  1149. magicJS.logger.info("- 今日已观看");
  1150. config.watch.num = (config.watch.num === 0 || typeof config.watch.num === 'undefined' ? 1 : config.watch.num);
  1151. if (!config['watch'].hasOwnProperty("time")) {
  1152. config.watch.time = startTime;
  1153. }
  1154. } else {
  1155. magicJS.logger.info("! 今日尚未观看");
  1156. config.watch.num = 0;
  1157. }
  1158. if (body.data.share){
  1159. magicJS.logger.info("- 今日已分享");
  1160. config.share.num = (config.share.num === 0 || typeof config.share.num === 'undefined' ? 1 : config.share.num);
  1161. if (!config['share'].hasOwnProperty("time")) {
  1162. config.share.time = startTime;
  1163. }
  1164. } else {
  1165. magicJS.logger.info("! 今日尚未分享");
  1166. config.share.num = 0;
  1167. }
  1168. if (body.data.coins === 50){
  1169. magicJS.logger.info("- 今日已投币")
  1170. if (!config['coins'].hasOwnProperty("time")) {
  1171. config.coins.time = startTime;
  1172. } else {
  1173. if (format(new Date().toDateString()) > config.coins.time) {
  1174. config.coins.time = startTime;
  1175. }
  1176. }
  1177. } else if ((body.data.coins / 10) >= real_times) {
  1178. config.coins.time = startTime;
  1179. magicJS.logger.info("- 已完成用户设置的投币量");
  1180. } else if (config.user.money <= 5) {
  1181. magicJS.logger.info("! 硬币数不足");
  1182. } else {
  1183. magicJS.logger.info("! 今日投币未完成");
  1184. }
  1185. config.coins.num = body.data.coins;
  1186. magicJS.data.write("bilibili_daily_bonus", magicJS.toStr(config));
  1187. } else {
  1188. magicJS.logger.info("- 查询失败");
  1189. magicJS.logger.info("- 失败原因 " + body?.message);
  1190. }
  1191. } catch (e) {
  1192. magicJS.logger.error(e);
  1193. } finally {
  1194. resolve();
  1195. }
  1196. }).catch(err => {
  1197. const msg = `检查任务进行状况异常\n${JSON.stringify(err)}`;
  1198. magicJS.logger.error(msg);
  1199. reject();
  1200. });
  1201. });
  1202. }
  1203. async function dynamic() {
  1204. return new Promise((resolve, reject) => {
  1205. magicJS.logger.info("#### 获取首页视频");
  1206. const myRequest = {
  1207. url: `https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/dynamic_new?uid=${config.cookie.DedeUserID}&type_list=8&from=&platform=web`,
  1208. headers: {
  1209. "cookie": config.cookieStr
  1210. }
  1211. };
  1212. magicJS.http.get(myRequest).then(response => {
  1213. try {
  1214. const body = response.body;
  1215. if (body?.data?.cards) {
  1216. cards = body.data.cards;
  1217. const { user, watch, share } = config;
  1218. user.time = watch.time = share.time = startTime;
  1219. magicJS.logger.info("- 获取视频动态成功");
  1220. } else {
  1221. magicJS.logger.info("- 获取视频动态失败");
  1222. }
  1223. } catch (e) {
  1224. magicJS.logger.error(JSON.stringify(e));
  1225. }
  1226. resolve();
  1227. }).catch(err => {
  1228. const msg = `获取首页视频异常\n${JSON.stringify(err)}`;
  1229. magicJS.logger.error(msg);
  1230. reject();
  1231. });
  1232. });
  1233. }
  1234. // Wbi签名获取
  1235. function getWbiSigns(requestParams) {
  1236. // 从给定字符串生成特定的签名
  1237. function generateSignature(baseString) {
  1238. let signature = "";
  1239. signatureIndices.forEach(index => {
  1240. signature += baseString[index];
  1241. });
  1242. return signature.slice(0, 32);
  1243. }
  1244. // 主要函数来构建请求参数并生成最终的请求字符串
  1245. function buildRequestWithSignature(params, imageKey, subscriptionKey) {
  1246. const signatureBase = generateSignature(imageKey + subscriptionKey);
  1247. const startTimeInMillisecond = new Date().getTime();
  1248. const startTimeInSeconds = parseInt(startTimeInMillisecond / 1000);
  1249. let queryString = "";
  1250. // 添加时间戳到请求参数
  1251. params = Object.assign(params, {
  1252. wts: startTimeInSeconds
  1253. });
  1254. // 将参数对象转换为排序后的查询字符串
  1255. queryString = objectToQueryString(sortedObjectEntries(params));
  1256. // 生成请求ID并附加到查询字符串
  1257. const requestId = md5(queryString + signatureBase);
  1258. return queryString + "&w_rid=" + requestId;
  1259. }
  1260. // 转换对象为查询字符串
  1261. function objectToQueryString(obj) {
  1262. return magicJS.objToQueryStr(Object.fromEntries(new Map(Array.from(Object.entries(obj)).sort())));
  1263. }
  1264. // 获取图片和订阅的关键信息
  1265. function getImageAndSubscriptionKeys() {
  1266. const imageUrl = config.user.wbi_img.img_url;
  1267. const subscriptionUrl = config.user.wbi_img.sub_url;
  1268. return {
  1269. img_key: imageUrl.substring(imageUrl.lastIndexOf("/") + 1).split(".")[0],
  1270. sub_key: subscriptionUrl.substring(subscriptionUrl.lastIndexOf("/") + 1).split(".")[0]
  1271. };
  1272. }
  1273. // 签名索引数组
  1274. const signatureIndices = [
  1275. 46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49, 33, 9, 42, 19, 29, 28, 14, 39,
  1276. 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40, 61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63,
  1277. 57, 62, 11, 36, 20, 34, 44, 52
  1278. ];
  1279. // 提取图片和订阅关键信息
  1280. const { img_key, sub_key } = getImageAndSubscriptionKeys();
  1281. // 构建并返回请求字符串,包含签名
  1282. return buildRequestWithSignature(requestParams, img_key, sub_key);
  1283. }
  1284. Main()
  1285. .catch((e) => magicJS.logger.error(`Error: ${e}`))
  1286. .finally(() => magicJS.done());
  1287. //---SyncByPyScript---MagicJS3-start
  1288. function MagicJS(e="MagicJS",t="INFO"){const r=()=>{const e="undefined"!=typeof $loon,t="undefined"!=typeof $task,n="undefined"!=typeof module,r="undefined"!=typeof $httpClient&&!e,o="undefined"!=typeof $storm,i="undefined"!=typeof $environment&&void 0!==$environment["stash-build"];var s=r||e||o||i;const a="undefined"!=typeof importModule;return{isLoon:e,isQuanX:t,isNode:n,isSurge:r,isStorm:o,isStash:i,isSurgeLike:s,isScriptable:a,get name(){return e?"Loon":t?"QuantumultX":n?"NodeJS":r?"Surge":a?"Scriptable":"unknown"},get build(){return r?$environment["surge-build"]:i?$environment["stash-build"]:o?$storm.buildVersion:void 0},get language(){if(r||i)return $environment.language},get version(){return r?$environment["surge-version"]:i?$environment["stash-version"]:o?$storm.appVersion:n?process.version:void 0},get system(){return r?$environment.system:n?process.platform:void 0},get systemVersion(){if(o)return $storm.systemVersion},get deviceName(){if(o)return $storm.deviceName}}},o=(n,e="INFO")=>{let r=e,t="\n";const o={SNIFFER:6,DEBUG:5,INFO:4,NOTIFY:3,WARNING:2,ERROR:1,CRITICAL:0,NONE:-1},i={SNIFFER:"",DEBUG:"",INFO:"",NOTIFY:"",WARNING:"❗ ",ERROR:"❌ ",CRITICAL:"❌ ",NONE:""},s=(e,t="INFO")=>{o[r]<o[t.toUpperCase()]||console.log(`██[${n}][${t}]`+i[t.toUpperCase()]+e+"\n")};return{getLevel:()=>r,setLevel:e=>{r=e},sniffer:(...e)=>{e=e.join(t);s(e,"SNIFFER")},log:(...e)=>{e=e.join(t);console.log(`██[${n}]`+e+"\n")},debug:(...e)=>{e=e.join(t);s(e,"DEBUG")},info:(...e)=>{e=e.join(t);s(e,"INFO")},notify:(...e)=>{e=e.join(t);s(e,"NOTIFY")},warning:(...e)=>{e=e.join(t);s(e,"WARNING")},error:(...e)=>{e=e.join(t);s(e,"ERROR")},retry:(...e)=>{e=e.join(t);s(e,"RETRY")}}};return new class{constructor(e,t){var n;this._startTime=Date.now(),this.version="3.0.0",this.scriptName=e,this.env=r(),this.logger=o(e,t),this.http="function"==typeof MagicHttp?MagicHttp(this.env,this.logger):void 0,this.data="function"==typeof MagicData?MagicData(this.env,this.logger):void 0,this.notification="function"==typeof MagicNotification?MagicNotification(this.scriptName,this.env,this.logger,this.http):void 0,this.utils="function"==typeof MagicUtils?MagicUtils(this.env,this.logger):void 0,this.qinglong="function"==typeof MagicQingLong?MagicQingLong(this.env,this.data,this.logger):void 0,void 0!==this.data&&(t=this.data.read("magic_loglevel"),n=this.data.read("magic_bark_url"),t&&this.logger.setLevel(t.toUpperCase()),n)&&this.notification.setBark(n),this.logger.info(e+", 开始执行!")}get isRequest(){return"undefined"!=typeof $request}get isStrictRequest(){return"undefined"!=typeof $request&&"undefined"==typeof $response}get isResponse(){return"undefined"!=typeof $response}get isDebug(){return"DEBUG"===this.logger.level}get request(){return"undefined"!=typeof $request?$request:void 0}get response(){if("undefined"!=typeof $response)return $response.hasOwnProperty("status")&&($response.statusCode=$response.status),$response.hasOwnProperty("statusCode")&&($response.status=$response.statusCode),$response}toStr(e,t=null){try{return JSON.stringify(e)}catch{return t}}toObj(e,t=null){try{return JSON.parse(e)}catch{return t}}checkRecordRequestBody(){if(this.isRequest){var t=$request.body;if(t){var n=this.env,r=$request.path;let e=this.scriptName+"#"+r.replace("/","_");e=e.replace("?","#"),n.isQuanX&&$prefs.setValueForKey(t,e),(n.isLoon||n.isSurge)&&$persistentStore.write(t,e),n.isNode&&require("fs").writeFileSync(e+".json",t,{flag:"w"},e=>console.log(e))}}}getRequestBody(){var e=this.env,t=$request.path;let n=this.scriptName+"#"+t.replace("/","_");if(n=n.replace("?","#"),e.isSurge||e.isLoon)return $persistentStore.read(n);if(e.isQuanX)return $prefs.valueForKey(n);if(e.isNode){t=n+".json",e=require("fs");if(!e.existsSync(t))return JSON.parse(e.readFileSync(t))}}getResponseBody(){if($response)return $response.body}parseCookies(e){let t={};return e&&e.split(";").forEach(function(e){e=e.split("=");t[e.shift().trim()]=decodeURI(e.join("="))}),t}serializeCookies(e){var t,n=[];for(t in e){var r=e[t],r=encodeURIComponent(t)+"="+encodeURIComponent(r);n.push(r)}return n.join("; ")}parseSetCookies(e){const o=["Expires","Max-Age","Domain","Path","HttpOnly","SameSite"];e=e.split(";");let i=null;const s={},a=[];return e.forEach(e=>{var t,e=e.trim();let n=null,r=!0;if(e.includes("=")?(t=e.split("="),n=t[0].trim(),r=t[1].trim()):n=e,o.includes(n))s[i]&&(s[i][n]=r,s[i].attribs[n]=r);else{i=n;let t={};i.includes(",")&&i.split(",").forEach(e=>{e=e.trim();o.includes(e)?t[e]=!0:i=e}),s[i]={name:i,value:r,attribs:t},a.push(s[i])}}),a}objToQueryStr(t,n){let r="";for(const o in t){let e=t[o];null!=e&&""!==e&&("object"==typeof e?e=JSON.stringify(e):n&&(e=encodeURIComponent(e)),r+=`${o}=${e}&`)}return r=r.substring(0,r.length-1)}parseQueryStr(e){var t={},n=(e=-1<e.indexOf("?")?e.split("?")[1]:e).split("&");for(let e=0;e<n.length;e++){var r=n[e].split("=");t[r[0]]=r[1]}return t}deepClone(e,t){for(var n in t=t||{},e)"object"==typeof e[n]?(t[n]=e[n].constructor===Array?[]:{},this.deepClone(e[n],t[n])):t[n]=e[n];return t}formatDate(e,t){var n,r={"M+":e.getMonth()+1,"d+":e.getDate(),"H+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(n in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),r)new RegExp("("+n+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?r[n]:("00"+r[n]).substr((""+r[n]).length)));return t}parseDate(a,e){let l={y:0,M:1,d:0,H:0,h:0,m:0,s:0,S:0};(e=e||"yyyy-MM-dd").replace(/([^yMdHmsS]*?)(([yMdHmsS])\3*)([^yMdHmsS]*?)/g,function(e,t,n,r,o,i,s){return a=a.replace(new RegExp(t+"(\\d{"+n.length+"})"+o),function(e,t){return l[r]=parseInt(t),""}),""}),l.M--;e=new Date(l.y,l.M,l.d,l.H,l.m,l.s);return 0!==l.S&&e.setMilliseconds(l.S),e}costTime(){var e=this.scriptName+"执行完毕!",t=(this._endTime=(new Date).getTime(),this._endTime-this._startTime);this.logger.info(e+`耗时【${t/1e3}】秒`)}done=(e={})=>{this.costTime(),"undefined"!=typeof $done&&$done(e)}}(e,t)}function MagicHttp(d,g){var e;let p;d.isNode&&(e=require("axios"),p=e.create());class t{constructor(e=!0){this.handlers=[],this.isRequest=e}use(e,t,n){return"function"==typeof e&&g.debug("Register fulfilled "+e.name),"function"==typeof t&&g.debug("Register rejected "+t.name),this.handlers.push({fulfilled:e,rejected:t,synchronous:!(!n||"boolean"!=typeof n.synchronous)&&n.synchronous,runWhen:n?n.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}forEach(t){this.handlers.forEach(e=>{null!==e&&t(e)})}}function f(e){let n={...e};return n.params&&!d.isNode&&(e=Object.keys(n.params).map(e=>{var t=encodeURIComponent(e);return n.url=n.url.replace(new RegExp(e+"=[^&]*","ig"),""),n.url=n.url.replace(new RegExp(t+"=[^&]*","ig"),""),t+"="+encodeURIComponent(n.params[e])}).join("&"),n.url.indexOf("?")<0&&(n.url+="?"),/(&|\?)$/g.test(n.url)||(n.url+="&"),n.url+=e,delete n.params,g.debug("Params to QueryString: "+n.url)),n}const y=(e,t=null)=>{if(e){t={...e,config:e.config||t,status:e.statusCode||e.status,body:e.body||e.data,headers:e.headers||e.header};if("string"==typeof t.body)try{t.body=JSON.parse(t.body)}catch{}return delete t.data,t}return e};const h=(e,t=null)=>{if(e&&400<=e.status)return g.debug("Raise exception when status code is "+e.status),{name:"RequestException",message:"Request failed with status code "+e.status,config:t||e.config,response:e}},m={request:new t,response:new t(!1)};let v=[],b=[],S=!0;function N(e){return e=f(e),g.debug(`HTTP ${e.method.toUpperCase()}:`+"\n"+JSON.stringify(e)),e}function E(t){try{t=t&&y(t),g.sniffer(`HTTP ${t.config.method.toUpperCase()}:`+"\n"+JSON.stringify(t.config)+"\nSTATUS CODE:\n"+t.status+"\nRESPONSE:\n"+("object"==typeof t.body?JSON.stringify(t.body):t.body));var e=h(t);return e?Promise.reject(e):t}catch(e){return g.error(e),t}}const n=(e,n)=>{let r;n=((e,t)=>{let n="object"==typeof t?{headers:{},...t}:{url:t,headers:{}};return n.method||(n.method=e),!0===(n=f(n)).rewrite&&(d.isSurge?(n.headers["X-Surge-Skip-Scripting"]=!1,delete n.rewrite):d.isQuanX&&(n.hints=!1,delete n.rewrite)),d.isSurgeLike?(t=n.headers["content-type"]||n.headers["Content-Type"],"GET"!==n.method&&t&&0<=t.indexOf("application/json")&&n.body instanceof Array&&(n.body=JSON.stringify(n.body),g.debug("Convert Array object to String: "+n.body))):d.isQuanX?(n.hasOwnProperty("body")&&"string"!=typeof n.body&&(n.body=JSON.stringify(n.body)),n.method=e):d.isNode&&("POST"===e||"PUT"===e||"PATCH"===e||"DELETE"===e?n.data=n.data||n.body:"GET"===e&&(n.params=n.params||n.body),delete n.body),n})(e.toUpperCase(),n),r=d.isNode?p:d.isSurgeLike?i=>new Promise((r,o)=>{$httpClient[e.toLowerCase()](i,(e,t,n)=>{e?(e={name:e.name||e,message:e.message||e,stack:e.stack||e,config:i,response:y(t)},o(e)):(t.config=i,t.body=n,r(t))})}):r=>new Promise((n,t)=>{$task.fetch(r).then(e=>{e=y(e,r);var t=h(e,r);if(t)return Promise.reject(t);n(e)}).catch(e=>{e={name:e.message||e.error,message:e.message||e.error,stack:e.error,config:r,response:e.response?y(e.response):null};t(e)})});let o;var t=n;try{v=[],b=[],m.request.forEach(e=>{"function"==typeof e.runWhen&&!1===e.runWhen(t)||(S=S&&e.synchronous,v.unshift(e.fulfilled,e.rejected))}),m.response.forEach(e=>{b.push(e.fulfilled,e.rejected)})}catch(e){g.error(`Failed to register interceptors: ${e}.`)}var i=[N,void 0],s=[E,void 0];if(S){for(g.debug("Interceptors are executed in synchronous mode"),Array.prototype.unshift.apply(v,i),v=v.concat([N,void 0]);v.length;){var a=v.shift(),l=v.shift();try{"function"==typeof a&&g.debug("Executing request fulfilled "+a.name),n=a(n)}catch(e){"function"==typeof l&&g.debug("Executing request rejected "+l.name),l(e);break}}try{o=(!d.isNode&&n.timeout?c:r)(n)}catch(e){return Promise.reject(e)}for(Array.prototype.unshift.apply(b,s);b.length;)o=o.then(b.shift(),b.shift());return o}{g.debug("Interceptors are executed in asynchronous mode");let t=[r,void 0];for(Array.prototype.unshift.apply(t,i),Array.prototype.unshift.apply(t,v),t=(t=t.concat(s)).concat(b),o=Promise.resolve(n);t.length;)try{let e=t.shift();var u=t.shift();"function"==typeof(e=!d.isNode&&n.timeout&&e===r?c:e)&&g.debug("Executing request fulfilled "+e.name),"function"==typeof u&&g.debug("Executing request rejected "+u.name),o=o.then(e,u)}catch(e){g.error("request exception: "+e)}return o}function c(n){try{var e=new Promise((e,t)=>{setTimeout(()=>{var e={message:`timeout of ${n.timeout}ms exceeded.`,config:n};t(e)},n.timeout)});return Promise.race([r(n),e])}catch(e){g.error(`Request Timeout exception: ${e}.`)}}};return{request:n,interceptors:m,convertHeadersToLowerCase:n=>Object.keys(n).reduce((e,t)=>(e[t.toLowerCase()]=n[t],e),{}),convertHeadersToCamelCase:n=>Object.keys(n).reduce((e,t)=>{return e[t.split("-").map(e=>e[0].toUpperCase()+e.slice(1)).join("-")]=n[t],e},{}),modifyResponse:y,get:e=>n("GET",e),post:e=>n("POST",e),put:e=>n("PUT",e),patch:e=>n("PATCH",e),delete:e=>n("DELETE",e),head:e=>n("HEAD",e),options:e=>n("OPTIONS",e)}}function MagicData(d,g){let p={fs:void 0,data:{}};if(d.isNode){p.fs=require("fs");try{p.fs.accessSync("./magic.json",p.fs.constants.R_OK|p.fs.constants.W_OK)}catch(e){p.fs.writeFileSync("./magic.json","{}",{encoding:"utf8"})}p.data=require("./magic.json")}const s=(e,t)=>"object"!=typeof t&&e===t,a=e=>"true"===e||"false"!==e&&(void 0===e?null:e),l=(e,t,n,r)=>{if(n)try{e=!0===(e="string"==typeof e?JSON.parse(e):e).magic_session?e[n]:null}catch{e=null}if("string"==typeof e&&"null"!==e)try{e=JSON.parse(e)}catch{}return null==(e=!1===r&&e&&!0===e.magic_session?null:e)&&null!=t&&(e=t),e=a(e)},f=t=>{if("string"!=typeof t)return t instanceof Array||null==t||t!=t||"boolean"==typeof t?{}:t;{let e={};try{var n=typeof(e=JSON.parse(t));("object"!=n||e instanceof Array||"bool"==n||null===e)&&(e={})}catch{}return e}},u=(e,t=null,n="",r=!1,o=null)=>{let i="";return i=o||d.isNode?((e,t=null,n="",r=!1,o=null)=>{o=o||p.data;return val=o&&void 0!==o[e]&&null!==o[e]?o[e]:n?{}:null,val=l(val,t,n,r)})(e,t,n,r,o):(d.isSurgeLike?i=$persistentStore.read(e):d.isQuanX&&(i=$prefs.valueForKey(e)),l(i,t,n,r)),g.debug(`READ DATA [${e}]${n?`[${n}]`:""} <${typeof i}>`+"\n"+JSON.stringify(i)),i},c=(e,t,n="",r=null)=>{if(void 0===t||t!=t)return!1;d.isNode||"boolean"!=typeof t&&"number"!=typeof t||(t=String(t));let o="";var i,s,a,l,u,c;if(r||d.isNode?o=([i,s,a="",l=null]=[e,t,n,r],c=l||p.data,c=f(c),a?((u=f(c[i])).magic_session=!0,u[a]=s,c[i]=u):c[i]=s,null!==l&&(l=c),c):n?(d.isSurgeLike?o=$persistentStore.read(e)?$persistentStore.read(e):o:d.isQuanX&&(o=$prefs.valueForKey(e)?$prefs.valueForKey(e):o),(o=f(o)).magic_session=!0,o[n]=t):o=t,o&&"object"==typeof o&&(o=JSON.stringify(o,null,4)),g.debug(`WRITE DATA [${e}]${n?`[${n}]`:""} <${typeof t}>`+"\n"+JSON.stringify(t)),!r){if(d.isSurgeLike)return $persistentStore.write(o,e);if(d.isQuanX)return $prefs.setValueForKey(o,e);if(d.isNode)try{p.fs.writeFileSync("./magic.json",o)}catch(e){return g.error(e),!1}}return!0};return{read:u,write:c,del:(e,t="",n=null)=>{let r={};if(n||d.isNode)r=(o=e,i=t,s=n||p.data,s=f(s),i?(delete(obj=f(s[o]))[i],s[o]=obj):delete s[o],s),n?n=r:p.fs.writeFileSync("./magic.json",JSON.stringify(r,null,4));else if(t){d.isSurgeLike?r=$persistentStore.read(e):d.isQuanX&&(r=$prefs.valueForKey(e)),delete(r=f(r))[t];i=JSON.stringify(r,null,4);c(e,i)}else{if(d.isStorm)return $persistentStore.remove(e);if(d.isSurgeLike)return $persistentStore.write(null,e);if(d.isQuanX)return $prefs.removeValueForKey(e)}var o,i,s;g.debug(`DELETE KEY [${e}]`+(t?`[${t}]`:""))},update:(e,t,n,r=s,o=null)=>{var i;return t=a(t),!0!==r(u(e,null,n,!1,o),t)&&(i=c(e,t,n,o),e=u(e,null,n,!1,o),r===s&&"object"==typeof e?i:r(t,e))},allSessions:(e,t=null)=>{let n={};t=u(e,null,null,!0,t);return!0===(t=f(t)).magic_session&&delete(n={...t}).magic_session,g.debug(`READ ALL SESSIONS [${e}] <${typeof n}>`+"\n"+JSON.stringify(n,null,4)),n},allSessionNames:(e,t=null)=>{let n=[];t=u(e,null,null,!0,t),t=f(t);return n=!0!==t.magic_session?[]:Object.keys(t).filter(e=>"magic_session"!==e),g.debug(`READ ALL SESSIONS [${e}] <${typeof n}>`+"\n"+JSON.stringify(n,null,4)),n},defaultValueComparator:s,convertToObject:f}}function MagicNotification(i,o,s,a){let l=null,u=null,c=[];function d(e=i,t="",n="",r=""){r=(t=>{try{let e={};var n;return"string"==typeof t?0<t.length&&(o.isLoon?e={openUrl:t}:o.isQuanX?e={"open-url":t}:o.isSurge&&(e={url:t})):"object"==typeof t&&(o.isLoon?(e.openUrl=t["open-url"]||"",e.mediaUrl=t["media-url"]||""):o.isQuanX?e=t["open-url"]||t["media-url"]?t:{}:o.isSurge&&(n=t["open-url"]||t.openUrl,e=n?{url:n}:{})),e}catch(e){s.error("通知选项转换失败"+e)}return t})(r),1===arguments.length&&(e=i,t="",n=arguments[0]),s.notify("\ntitle:"+e+"\nsubTitle:"+t+"\nbody:"+n+"\noptions:"+("object"==typeof r?JSON.stringify(r):r)),o.isSurge?$notification.post(e,t,n,r):o.isLoon?r?$notification.post(e,t,n,r):$notification.post(e,t,n):o.isQuanX&&$notify(e,t,n,r),l&&u&&g(e,t,n)}function g(e=i,t="",n="",r){if(void 0===a||void 0===a.post)throw"Bark notification needs to import MagicHttp module.";e={url:l,headers:{"content-type":"application/json; charset=utf-8"},body:{title:e,body:t?t+"\n"+n:n,device_key:u}};a.post(e).catch(e=>{s.error("Bark notify error: "+e)})}return{post:d,debug:function(e=i,t="",n="",r=""){"DEBUG"===s.getLevel()&&(1===arguments.length&&(e=i,t="",n=arguments[0]),this.post(e,t,n,r))},bark:g,setBark:e=>{try{var t=e.replace(/\/+$/g,"");l=/^https?:\/\/([^/]*)/.exec(t)[0]+"/push",u=/\/([^\/]+)\/?$/.exec(t)[1]}catch(e){s.error(`Bark url error: ${e}.`)}},appendNotifyInfo:function(e,t){1==t?c=e:c.push(e)},prependNotifyInfo:function(e){c.splice(0,0,e)},msg:function(e,t,n,r){var o={};n&&(o["open-url"]=n),r&&(o["media-url"]=r),(t=t&&0!=t.length?t:Array.isArray(c)?c.join("\n"):c)&&0<t.length&&d(i,"",t,o)}}}function MagicUtils(r,u){const e=(e,t="yyyy-MM-dd hh:mm:ss")=>{var n,r={"M+":e.getMonth()+1,"d+":e.getDate(),"h+":e.getHours(),"m+":e.getMinutes(),"s+":e.getSeconds(),"q+":Math.floor((e.getMonth()+3)/3),S:e.getMilliseconds()};for(n in/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(e.getFullYear()+"").substr(4-RegExp.$1.length))),r)new RegExp("("+n+")").test(t)&&(t=t.replace(RegExp.$1,1===RegExp.$1.length?r[n]:("00"+r[n]).substr((""+r[n]).length)));return t};return{retry:(i,s=5,a=0,l=null)=>(...e)=>new Promise((n,r)=>{function o(...t){Promise.resolve().then(()=>i.apply(this,t)).then(e=>{"function"==typeof l?Promise.resolve().then(()=>l(e)).then(()=>{n(e)}).catch(e=>{1<=s?0<a?setTimeout(()=>o.apply(this,t),a):o.apply(this,t):r(e),s--}):n(e)}).catch(e=>{u.error(e),1<=s&&0<a?setTimeout(()=>o.apply(this,t),a):1<=s?o.apply(this,t):r(e),s--})}o.apply(this,e)}),formatTime:e,now:()=>e(new Date,"yyyy-MM-dd hh:mm:ss"),today:()=>e(new Date,"yyyy-MM-dd"),sleep:t=>new Promise(e=>setTimeout(e,t)),assert:(e,t=null)=>{var n;r.isNode?(n=require("assert"),t?n(e,t):n(e)):!0!==e&&u.error("AssertionError: "+(t||"The expression evaluated to a falsy value."))}}}function MagicQingLong(e,a,o){let i="",s="",l="",u="",c="",t="";const d="magic.json",g=MagicHttp(e,o);async function n(){return l=l||a.read("magic_qlclient"),u=u||a.read("magic_qlsecrt"),s=s||a.read("magic_qlname"),c=c||a.read("magic_qlpwd"),i&&l&&u?(o.info("Get token from QingLong Panel"),await g.get({url:"/open/auth/token",headers:{"content-type":"application/json"},params:{client_id:l,client_secret:u}}).then(e=>{if(!(0<Object.keys(e.body).length&&e.body.data&&e.body.data.token))throw new Error("Get QingLong Panel token failed.");o.info("Successfully logged in to QingLong Panel"),t=e.body.data.token,a.write("magic_qltoken",t)}).catch(e=>{o.error("Error logging in to QingLong Panel.\n"+(e.message||e))})):i&&s&&c&&await g.post({url:"/api/user/login",headers:{"content-type":"application/json"},body:{username:s,password:c}}).then(e=>{o.info("Successfully logged in to QingLong Panel"),t=e.body.data.token,a.write("magic_qltoken",t)}).catch(e=>{o.error("Error logging in to QingLong Panel.\n"+(e.message||e))}),t}async function p(e){let t=[];return await g.post({url:"/api/envs",headers:{"content-type":"application/json"},body:e}).then(e=>{200===e.body.code?e.body.data.forEach(e=>{o.debug(`QINGLONG ADD ENV ${e.name} <${typeof e.value}> (${e.id})`+"\n"+JSON.stringify(e)),t.push(e.id)}):o.error("Error adding environments variable from QingLong Panel.\n"+JSON.stringify(e))}).catch(e=>{o.error("Error adding environments variable from QingLong Panel.\n"+(e.message||e))}),t}async function r(r=null,e="",t){let o=[];return await g.get({url:"/api/envs",headers:{"content-type":"application/json"},params:{searchValue:e}}).then(e=>{if(200!==e.body.code)throw new Error("Error reading environment variable from QingLong Panel.\n"+JSON.stringify(e));e=e.body.data;if(r){var t=[];for(const n of e)n.name===r&&o.push(n);o=t}o=e}).catch(e=>{throw new Error("Error reading environments variable from QingLong Panel.\n"+(e.message||e))}),o}async function f(e,t=""){let n="";return await g.get({url:"/api/scripts/"+e,params:{path:t}}).then(e=>{if(200!==e.body.code)throw new Error("Error reading data from QingLong Panel.\n"+JSON.stringify(e));n=e.body.data}).catch(e=>{throw new Error("Error reading data from QingLong Panel.\n"+(e.message||e))}),n}async function y(e,t="",n=""){let r=!1;return await g.put({url:"/api/scripts",headers:{"content-type":"application/json"},body:{filename:e,path:t,content:n}}).then(e=>{200===e.body.code?r=!0:o.error("Error reading data from QingLong Panel.\n"+JSON.stringify(e))}).catch(e=>{o.error("Error reading data from QingLong Panel.\n"+(e.message||e))}),r}return g.interceptors.request.use(function(e){return i=i||a.read("magic_qlurl"),e.url.indexOf(i)<0&&(e.url=""+i+e.url),{...e,timeout:3e3}},void 0),g.interceptors.request.use(function(e){return(l=l||a.read("magic_qlclient"))&&(e.url=e.url.replace("/api/","/open/")),e},void 0,{runWhen:e=>e.url.indexOf("api/user/login")<0&&e.url.indexOf("open/auth/token")<0}),g.interceptors.request.use(async function(e){return(t=t||a.read("magic_qltoken",""))||await n(),e.headers.authorization="Bearer "+t,e},void 0,{runWhen:e=>e.url.indexOf("api/user/login")<0&&e.url.indexOf("open/auth/token")<0}),g.interceptors.request.use(function(e){return e.params={...e.params,t:Date.now()},e},void 0,{runWhen:e=>e.url.indexOf("open/auth/token")<0}),g.interceptors.request.use(function(e){return i=i||a.read("magic_qlurl"),t=t||a.read("magic_qltoken"),o.debug("QingLong url: "+i+"\nQingLong token: "+t),e},void 0),g.interceptors.response.use(void 0,async function(e){try{var t=e.message||e.error||JSON.stringify(e);return(0<=t.indexOf("NSURLErrorDomain")&&0<=t.indexOf("-1012")||e.response&&401===e.response.status)&&e.config&&!0!==e.config.refreshToken?(o.warning("QingLong Panel token has expired"),o.info("Refreshing the QingLong Panel token"),await n(),e.config.refreshToken=!0,o.info("Call the previous method again"),await g.request(e.config.method,e.config)):Promise.reject(e)}catch(e){return Promise.reject(e)}}),{url:i||a.read("magic_qlurl"),init:(e,t,n,r,o)=>{i=e,l=t,u=n,s=r,c=o},getToken:n,setEnv:async function(t,n,r=null){if(i=i||a.read("magic_qlurl"),null===r){var e=await p([{name:t,value:n}]);if(e&&1===e.length)return e[0]}else await g.put({url:"/api/envs",headers:{"content-type":"application/json"},body:{name:t,value:n,id:r}}).then(e=>{if(200===e.body.code)return o.debug(`QINGLONG UPDATE ENV ${t} <${typeof n}> (${r})`+"\n"+JSON.stringify(n)),!0;o.error("Error adding environment variable from QingLong Panel.\n"+JSON.stringify(e))}).catch(e=>(o.error("Error adding environment variable from QingLong Panel.\n"+(e.message||e)),!1))},setEnvs:p,getEnv:async function(e){let t=null;for(const n of await r())if(n.id===e){t=n;break}return t},getEnvs:r,delEnvs:async function(t){return g.delete({url:"/api/envs",headers:{accept:"application/json","accept-language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",connection:"keep-alive","content-type":"application/json;charset=UTF-8","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:t}).then(e=>200===e.body.code?(o.debug("QINGLONG DELETE ENV IDS: "+t),!0):(o.error("Error deleting environments variable from QingLong Panel.\n"+JSON.stringify(e)),!1)).catch(e=>{o.error("Error deleting environments variable from QingLong Panel.\n"+(e.message||e))})},disableEnvs:async function(t){let n=!1;return await g.put({url:"/api/envs/disable",headers:{accept:"application/json","accept-Language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",connection:"keep-alive","content-type":"application/json;charset=UTF-8","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:t}).then(e=>{200===e.body.code?(o.debug("QINGLONG DISABLED ENV IDS: "+t),n=!0):o.error("Error disabling environments variable from QingLong Panel.\n"+JSON.stringify(e))}).catch(e=>{o.error("Error disabling environments variable from QingLong Panel.\n"+(e.message||e))}),n},enableEnvs:async function(t){let n=!1;return await g.put({url:"/api/envs/enable",headers:{accept:"application/json","accept-language":"zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",connection:"keep-alive","content-type":"application/json;charset=UTF-8","user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.63 Safari/537.36 Edg/102.0.1245.30"},body:t}).then(e=>{200===e.body.code?(o.debug("QINGLONG ENABLED ENV IDS: "+t),n=!0):o.error("Error enabling environments variable from Qilong panel.\n"+JSON.stringify(e))}).catch(e=>{o.error("Error enabling environments variable from Qilong panel.\n"+(e.message||e))}),n},addScript:async function(e,t="",n=""){let r=!1;return await g.post({url:"/api/scripts",headers:{"content-type":"application/json"},body:{filename:e,path:t,content:n}}).then(e=>{200===e.body.code?r=!0:o.error("Error reading data from QingLong Panel.\n"+JSON.stringify(e))}).catch(e=>{o.error("Error reading data from QingLong Panel.\n"+(e.message||e))}),r},getScript:f,editScript:y,delScript:async function(e,t=""){let n=!1;return await g.delete({url:"/api/scripts",headers:{"content-type":"application/json"},body:{filename:e,path:t}}).then(e=>{200===e.body.code?n=!0:o.error("Error reading data from QingLong Panel.\n"+JSON.stringify(e))}).catch(e=>{o.error("Error reading data from QingLong Panel.\n"+(e.message||e))}),n},write:async function(e,t,n=""){var r=await f(d,""),o=a.convertToObject(r),e=a.write(e,t,n,o),r=JSON.stringify(o,null,4);return await y(d,"",r)&&e},read:async function(e,t,n="",r=!1){var o=await f(d,""),o=a.convertToObject(o);return a.read(e,t,n,r,o)},del:async function(e,t=""){var n=await f(d,""),r=a.convertToObject(n),e=a.del(e,t,r),n=JSON.stringify(r,null,4),t=await y(d,"",n);return e&&t},update:async function(e,t,n,r=a.defaultValueComparator){var o=await f(d,""),i=a.convertToObject(o),e=a.update(e,t,n,r,i);let s=!1;return!0===e&&(o=JSON.stringify(i,null,4),s=await y(d,"",o)),e&&s},batchWrite:async function(...e){var t,n=await f(d,""),r=a.convertToObject(n);for(t of e)a.write(t[0],t[1],void 0!==t[2]?t[2]:"",r);return n=JSON.stringify(r,null,4),y(d,"",n)},batchRead:async function(...e){var t,n=await f(d,""),r=a.convertToObject(n),o=[];for(t of e){var i=a.read(t[0],t[1],void 0!==t[2]?t[2]:"","boolean"==typeof t[3]&&t[3],r);o.push(i)}return o},batchUpdate:async function(...e){var t,n=await f(d,""),r=a.convertToObject(n);for(t of e)a.update(t[0],t[1],void 0!==t[2]?t[2]:"",void 0!==t[3]?t.comparator:a.defaultValueComparator,r);return n=JSON.stringify(r,null,4),y(d,"",n)},batchDel:async function(...e){var t,n=await f(d,""),r=a.convertToObject(n);for(t of e)a.del(t[0],void 0!==t[1]?t[1]:"",r);return n=JSON.stringify(r,null,4),y(d,"",n)},allSessions:async function(e){var t=await f(d,""),t=a.convertToObject(t);return a.allSessions(e,t)},allSessionNames:async function(e){var t=await f(d,""),t=a.convertToObject(t);return a.allSessionNames(e,t)}}}
  1289. //---SyncByPyScript---MagicJS3-end
  1290. //---SyncByPyScript---md5-start
  1291. !function(n){"use strict";function d(n,t){var r=(65535&n)+(65535&t);return(n>>16)+(t>>16)+(r>>16)<<16|65535&r}function f(n,t,r,e,o,u){return d((u=d(d(t,n),d(e,u)))<<o|u>>>32-o,r)}function l(n,t,r,e,o,u,c){return f(t&r|~t&e,n,t,o,u,c)}function g(n,t,r,e,o,u,c){return f(t&e|r&~e,n,t,o,u,c)}function v(n,t,r,e,o,u,c){return f(t^r^e,n,t,o,u,c)}function m(n,t,r,e,o,u,c){return f(r^(t|~e),n,t,o,u,c)}function c(n,t){var r,e,o,u;n[t>>5]|=128<<t%32,n[14+(t+64>>>9<<4)]=t;for(var c=1732584193,f=-271733879,i=-1732584194,a=271733878,h=0;h<n.length;h+=16)c=l(r=c,e=f,o=i,u=a,n[h],7,-680876936),a=l(a,c,f,i,n[h+1],12,-389564586),i=l(i,a,c,f,n[h+2],17,606105819),f=l(f,i,a,c,n[h+3],22,-1044525330),c=l(c,f,i,a,n[h+4],7,-176418897),a=l(a,c,f,i,n[h+5],12,1200080426),i=l(i,a,c,f,n[h+6],17,-1473231341),f=l(f,i,a,c,n[h+7],22,-45705983),c=l(c,f,i,a,n[h+8],7,1770035416),a=l(a,c,f,i,n[h+9],12,-1958414417),i=l(i,a,c,f,n[h+10],17,-42063),f=l(f,i,a,c,n[h+11],22,-1990404162),c=l(c,f,i,a,n[h+12],7,1804603682),a=l(a,c,f,i,n[h+13],12,-40341101),i=l(i,a,c,f,n[h+14],17,-1502002290),c=g(c,f=l(f,i,a,c,n[h+15],22,1236535329),i,a,n[h+1],5,-165796510),a=g(a,c,f,i,n[h+6],9,-1069501632),i=g(i,a,c,f,n[h+11],14,643717713),f=g(f,i,a,c,n[h],20,-373897302),c=g(c,f,i,a,n[h+5],5,-701558691),a=g(a,c,f,i,n[h+10],9,38016083),i=g(i,a,c,f,n[h+15],14,-660478335),f=g(f,i,a,c,n[h+4],20,-405537848),c=g(c,f,i,a,n[h+9],5,568446438),a=g(a,c,f,i,n[h+14],9,-1019803690),i=g(i,a,c,f,n[h+3],14,-187363961),f=g(f,i,a,c,n[h+8],20,1163531501),c=g(c,f,i,a,n[h+13],5,-1444681467),a=g(a,c,f,i,n[h+2],9,-51403784),i=g(i,a,c,f,n[h+7],14,1735328473),c=v(c,f=g(f,i,a,c,n[h+12],20,-1926607734),i,a,n[h+5],4,-378558),a=v(a,c,f,i,n[h+8],11,-2022574463),i=v(i,a,c,f,n[h+11],16,1839030562),f=v(f,i,a,c,n[h+14],23,-35309556),c=v(c,f,i,a,n[h+1],4,-1530992060),a=v(a,c,f,i,n[h+4],11,1272893353),i=v(i,a,c,f,n[h+7],16,-155497632),f=v(f,i,a,c,n[h+10],23,-1094730640),c=v(c,f,i,a,n[h+13],4,681279174),a=v(a,c,f,i,n[h],11,-358537222),i=v(i,a,c,f,n[h+3],16,-722521979),f=v(f,i,a,c,n[h+6],23,76029189),c=v(c,f,i,a,n[h+9],4,-640364487),a=v(a,c,f,i,n[h+12],11,-421815835),i=v(i,a,c,f,n[h+15],16,530742520),c=m(c,f=v(f,i,a,c,n[h+2],23,-995338651),i,a,n[h],6,-198630844),a=m(a,c,f,i,n[h+7],10,1126891415),i=m(i,a,c,f,n[h+14],15,-1416354905),f=m(f,i,a,c,n[h+5],21,-57434055),c=m(c,f,i,a,n[h+12],6,1700485571),a=m(a,c,f,i,n[h+3],10,-1894986606),i=m(i,a,c,f,n[h+10],15,-1051523),f=m(f,i,a,c,n[h+1],21,-2054922799),c=m(c,f,i,a,n[h+8],6,1873313359),a=m(a,c,f,i,n[h+15],10,-30611744),i=m(i,a,c,f,n[h+6],15,-1560198380),f=m(f,i,a,c,n[h+13],21,1309151649),c=m(c,f,i,a,n[h+4],6,-145523070),a=m(a,c,f,i,n[h+11],10,-1120210379),i=m(i,a,c,f,n[h+2],15,718787259),f=m(f,i,a,c,n[h+9],21,-343485551),c=d(c,r),f=d(f,e),i=d(i,o),a=d(a,u);return[c,f,i,a]}function i(n){for(var t="",r=32*n.length,e=0;e<r;e+=8)t+=String.fromCharCode(n[e>>5]>>>e%32&255);return t}function a(n){var t=[];for(t[(n.length>>2)-1]=void 0,e=0;e<t.length;e+=1)t[e]=0;for(var r=8*n.length,e=0;e<r;e+=8)t[e>>5]|=(255&n.charCodeAt(e/8))<<e%32;return t}function e(n){for(var t,r="0123456789abcdef",e="",o=0;o<n.length;o+=1)t=n.charCodeAt(o),e+=r.charAt(t>>>4&15)+r.charAt(15&t);return e}function r(n){return unescape(encodeURIComponent(n))}function o(n){return i(c(a(n=r(n)),8*n.length))}function u(n,t){return function(n,t){var r,e=a(n),o=[],u=[];for(o[15]=u[15]=void 0,16<e.length&&(e=c(e,8*n.length)),r=0;r<16;r+=1)o[r]=909522486^e[r],u[r]=1549556828^e[r];return t=c(o.concat(a(t)),512+8*t.length),i(c(u.concat(t),640))}(r(n),r(t))}function t(n,t,r){return t?r?u(t,n):e(u(t,n)):r?o(n):e(o(n))}"function"==typeof define&&define.amd?define(function(){return t}):"object"==typeof module&&module.exports?module.exports=t:n.md5=t}(this);
  1292. //---SyncByPyScript---md5-end