Files
live-hub-py/web/frontend/src/utils/clipboard.ts
T
yml2213 230d6c1918 虎牙人工兑换改用本机浏览器并新增扩展自动注入登录态
移除服务器浏览器方案(容器/Xvfb/noVNC/CDP 会话管理),后端仅下发
兑换材料;新增内置 Chrome/Edge 扩展一键写入 huya.com 登录态,
未安装扩展时回退控制台脚本手动注入,兑换始终由用户手动完成。
2026-09-05 17:55:31 +08:00

28 lines
843 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 复制文本到剪贴板,兼容非安全上下文(http:// 非 localhost) */
export function copyTextToClipboard(text: string): Promise<void> {
if (navigator.clipboard?.writeText) {
return navigator.clipboard.writeText(text);
}
// fallback:利用 textarea + execCommand,兼容 http 远程访问
return new Promise((resolve, reject) => {
const ta = document.createElement('textarea');
ta.value = text;
ta.style.position = 'fixed';
ta.style.left = '-9999px';
document.body.appendChild(ta);
ta.select();
try {
const ok = document.execCommand('copy');
document.body.removeChild(ta);
if (ok) {
resolve();
} else {
reject(new Error('copy failed'));
}
} catch (err) {
document.body.removeChild(ta);
reject(err as Error);
}
});
}