1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
import { curUrl, curDate, _log, $n, fnElChange } from './_base.js';
const ckeObj = { setItem: function (key, value) { const Days = 137; const exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = key + "=" + encodeURIComponent(value) + ";path=/;domain=.bilibili.com;expires=" + exp.toGMTString(); }, getItem: function (key, def = "") { const reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)"); const arr = document.cookie.match(reg); if (arr) { return decodeURIComponent(arr[2]); } return def; } };
const getDateStr = (date) => { const options = { year: 'numeric', month: '2-digit', day: '2-digit' }; return date.toLocaleDateString("zh-CN", options); }
const diffDateDays = (date1, date2) => { const diff = date1.getTime() - date2.getTime(); return diff / (1000 * 60 * 60 * 24); }
(() => { const ckeName = "bilibili-helper-bcoin-nxtDateStr"; const curDateStr = getDateStr(curDate); const nxtDateStr = ckeObj.getItem(ckeName, curDateStr); const bcoinUrl = "https://account.bilibili.com/account/big/myPackage";
_log(`当前日期: ${curDateStr}`); _log(`下次领取: ${nxtDateStr}`);
const notify = (title, body) => { _log(`通知标题: ${title}`); GM_notification({ title: title, text: body, timeout: 0, onclick: () => { GM.openInTab(bcoinUrl, false); } }); }
const fnCheckByDOM = () => { const $bcoin = $n(".bcoin-wrapper"); if ($bcoin && $bcoin.innerText.includes("本次已领")) { const match = $bcoin.innerText.match(/\d{4}\/\d+\/\d+/); if (match && match[0] !== nxtDateStr) { ckeObj.setItem(ckeName, match[0]); _log("已领取过,更新下次领取日期", match[0]); return true; } } else { fnElChange($n("#app"), fnCheckByDOM); } return false; }
const iniDiff = diffDateDays(curDate, new Date(nxtDateStr)); if (iniDiff > 0) { _log(curUrl, "\n", bcoinUrl); if (curUrl.indexOf(bcoinUrl) > -1) { fnCheckByDOM(); } else { notify("B 币领取提醒", "点击查看 B 币领取情况"); } } })();
|