-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
55 lines (49 loc) · 1.97 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!doctype html><html style="color-scheme: light dark"><head></head><body>
<button class="copytext">copy text</button>
<button class="copyinputfocus">copy input focus</button>
<button class="copytextareafocus">copy textarea focus</button>
<button class="copysvg">copy svg</button>
<button class="copyimg">copy image</button>
<input/>
<textarea rows="1"></textarea>
<pre></pre>
<script type="module">
import {clippie} from "./dist/index.js";
const pre = document.querySelector("pre");
async function copy(content) {
try {
const success = await clippie(content, {reject: true});
pre.textContent += `${success}\n`;
} catch (err) {
pre.textContent += `${err.message}\n`;
}
}
document.querySelector(".copytext").addEventListener("click", async () => {
await copy("sometext", {reject: true});
});
document.querySelector(".copytextareafocus").addEventListener("click", async () => {
document.querySelector("textarea").focus();
document.querySelector("textarea").selectionStart = 0;
await new Promise(resolve => setTimeout(resolve, 200));
await copy("sometext", {reject: true});
});
document.querySelector(".copyinputfocus").addEventListener("click", async () => {
document.querySelector("input").focus();
document.querySelector("input").selectionStart = 0;
await new Promise(resolve => setTimeout(resolve, 200));
await copy("sometext", {reject: true});
});
document.querySelector(".copysvg").addEventListener("click", async () => {
await copy(
new Blob([`<svg width="10" height="10"/>`], {type: "image/svg+xml"}),
`<svg width="20" height="20"/>`,
);
});
document.querySelector(".copyimg").addEventListener("click", async () => {
const blob = await (await fetch("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAADUlEQVQIHQECAP3/AAAAAgABzePRKwAAAABJRU5ErkJggg==")).blob();
await copy(
blob,
`image description`,
);
});
</script></body></html>