* Copies text; in-app browsers without the async clipboard (WeChat and the like) fall back to a selection copy. Rejects when neither copies. /
// Source: https://github.com/KKKKhazix/AIHOT | License: MIT | Copyright 2026 数字生命卡兹克
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Copies text; in-app browsers without the async clipboard (WeChat and the like) fall back to a selection
* copy. Rejects when neither copies.
*/
export async function copyText(text: string): Promise<void> {
try {
await navigator.clipboard.writeText(text);
} catch {
const ta = document.createElement("textarea");
ta.value = text;
document.body.appendChild(ta);
ta.select();
const copied = document.execCommand("copy");
ta.remove();
if (!copied) throw new Error("copy failed");
}
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key