虎牙人工兑换改用本机浏览器并新增扩展自动注入登录态
移除服务器浏览器方案(容器/Xvfb/noVNC/CDP 会话管理),后端仅下发 兑换材料;新增内置 Chrome/Edge 扩展一键写入 huya.com 登录态, 未安装扩展时回退控制台脚本手动注入,兑换始终由用户手动完成。
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// 内容脚本:在所有页面标记扩展存在,并把后台页面派发的兑换材料转发给 service worker。
|
||||
// 后台页面通过 documentElement.dataset.huyaExchangeHelper === '1' 检测扩展是否可用。
|
||||
document.documentElement.dataset.huyaExchangeHelper = '1';
|
||||
|
||||
window.addEventListener('huya-exchange-kit', (event) => {
|
||||
const detail = event.detail;
|
||||
if (typeof detail !== 'string') return;
|
||||
try {
|
||||
const kit = JSON.parse(detail);
|
||||
if (kit && kit.target_url && Array.isArray(kit.cookies)) {
|
||||
const sending = chrome.runtime.sendMessage({ type: 'inject', kit });
|
||||
if (sending && typeof sending.catch === 'function') {
|
||||
sending.catch(() => { /* 扩展上下文失效等场景忽略 */ });
|
||||
}
|
||||
}
|
||||
} catch (e) { /* 忽略非法消息 */ }
|
||||
}, true);
|
||||
Reference in New Issue
Block a user