v1.7.0: 新增私信评论区用户(wbi签名+永久按mid去重+2~4分钟间隔)、安装统计上报、有新版本提示
This commit is contained in:
1 parent
38b90c1448
commit
0cce6cc2bb
5 files changed
+344
-9
No files matched your search
+41
-1
@@ -29,6 +29,41 @@ async function ensureDownloadHeadersRule() {
|
||||
}
|
||||
ensureDownloadHeadersRule();
|
||||
|
||||
// ============ 安装统计(CardAuth installations:只上报机器码+版本,不碰B站账号) ============
|
||||
// 用 check-update 接口登记(服务端会写 installations 表并返回 install_id),
|
||||
// 顺带拿到 latest_version → 面板可提示「有新版本」
|
||||
let installReported = false;
|
||||
async function reportInstall(force) {
|
||||
if (installReported && !force) return;
|
||||
try {
|
||||
const machine = await getMachineId();
|
||||
const ver = chrome.runtime.getManifest().version;
|
||||
const ua = (typeof navigator !== "undefined" && navigator.userAgent) || "";
|
||||
const m = ua.match(/(Chrome|Edg)\/[\d.]+/);
|
||||
const r = await authFetch("/public/installations/check-update", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", "X-Api-Key": CARD_API_KEY },
|
||||
body: JSON.stringify({
|
||||
project_id: PROJECT_ID,
|
||||
machine_id: machine,
|
||||
client_version: ver,
|
||||
device_info: (m ? m[0] : "chrome-extension")
|
||||
})
|
||||
}, 8000);
|
||||
if (r && r.code === 200 && r.data) {
|
||||
installReported = true;
|
||||
await chrome.storage.local.set({
|
||||
updateAvailable: !!r.data.update_available,
|
||||
latestVersion: String(r.data.latest_version || "")
|
||||
});
|
||||
}
|
||||
} catch (e) { /* 统计失败不影响任何功能,也不阻塞用户 */ }
|
||||
}
|
||||
if (chrome.runtime.onInstalled) {
|
||||
chrome.runtime.onInstalled.addListener(() => reportInstall(true));
|
||||
}
|
||||
reportInstall(false); // SW 启动即登记一次(同一浏览器只记一条)
|
||||
|
||||
// ============ 授权(CardAuth: auth.88531.cn,项目=B站评论插件) ============
|
||||
|
||||
const AUTH_BASE = "https://auth.88531.cn/api";
|
||||
@@ -517,7 +552,12 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
|
||||
const license = await checkLicense();
|
||||
let announcements = [];
|
||||
try { announcements = await getAnnouncements(); } catch (e) { announcements = []; }
|
||||
sendResponse({ ok: true, license: license, announcements: announcements });
|
||||
const st = await chrome.storage.local.get(["updateAvailable", "latestVersion"]);
|
||||
reportInstall(false); // 面板打开时补一次登记(SW 冷启动后 onInstalled 不会再触发)
|
||||
sendResponse({
|
||||
ok: true, license: license, announcements: announcements,
|
||||
update: { available: !!st.updateAvailable, latest: String(st.latestVersion || ""), current: chrome.runtime.getManifest().version }
|
||||
});
|
||||
})();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user