浏览器兑换独立成页面并按斗鱼模式优化导入

新增 /huya/browser-exchange 页面(精英宝典下方),支持导入账号与
执行兑换,客服仅见已分配账号;账号管理页移除该功能。导入弹窗对齐
斗鱼操作台:服务端分页筛选、可搜索标签、无 CK 不展示、导入本页/
一键导入全部/导入选中;新增 /accounts/ids 接口与 workbench
browser_exchange scope。
This commit is contained in:
yml2213
2026-09-05 18:30:29 +08:00
parent 230d6c1918
commit 178eba1eea
11 changed files with 493 additions and 130 deletions
+32
View File
@@ -0,0 +1,32 @@
/** 虎牙浏览器兑换:与内置扩展(web/extension/huya-exchange-helper)的通信桥。 */
import type { HuyaBrowserExchangeKit } from '../api/modules';
/** 解析后端 Cookie 字符串为 [name, value] 数组,供兑换扩展注入 */
export function parseCookieString(cookieString: string): [string, string][] {
return cookieString
.split(';')
.map((part) => part.trim())
.filter((part) => part.includes('='))
.map((part) => {
const idx = part.indexOf('=');
return [part.slice(0, idx), part.slice(idx + 1)];
});
}
/** 内置扩展的内容脚本会在所有页面打上此标记 */
export function huyaExchangeHelperReady(): boolean {
return document.documentElement.dataset.huyaExchangeHelper === '1';
}
/** 请求内置扩展自动注入登录态;同时留存到 window 供扩展图标点击兜底读取 */
export function requestExtensionInject(kit: HuyaBrowserExchangeKit): void {
const payload = JSON.stringify({ target_url: kit.target_url, cookies: parseCookieString(kit.cookie_string) });
(window as unknown as { __huyaExchangeKit?: string }).__huyaExchangeKit = payload;
window.dispatchEvent(new CustomEvent('huya-exchange-kit', { detail: payload }));
}
/** 在新标签页打开兑换页面(noopener 避免反向标签劫持) */
export function openExchangeTarget(targetUrl: string): void {
window.open(targetUrl, '_blank', 'noopener,noreferrer');
}