-
Notifications
You must be signed in to change notification settings - Fork 1
/
index copy.html
82 lines (81 loc) · 2.61 KB
/
index copy.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<!-- <h1>Discoverthreejs.com - Nothing to see here yet :)</h1> -->
<div id="w" style="height: 120px">
<div id="bb">2023-12-12</div>
<div>测试测试测试测试测试测试</div>
<div id="bb">2023-12-12</div>
<div>测试测试测试测试测试测试</div>
</div>
<div contenteditable="" style="height: 150px"></div>
<!-- <div id="scene-container">
</div> -->
<!-- <script type="module" src="./main.js"></script> -->
<script>
const w = document.querySelector("#w");
w.addEventListener("copy", (event) => {
setTimeout(() => {
const selection = document.getSelection();
var clipboardData = window.clipboardData;
getClipboardContents();
}, 100);
});
async function getClipboardContents() {
try {
let arr = [];
const clipboardItems = await navigator.clipboard.read();
for (const clipboardItem of clipboardItems) {
for (const type of clipboardItem.types) {
if (type === "text/html") {
const blob = await clipboardItem.getType(type);
console.log(blob);
const res = await blob.text();
let str = res;
str = str.replace(/<div id="bb"[\d\D]+?>[\d\D]+?<\/div>/g, "");
console.log("res2", res);
arr.push(str);
} else {
const blob = await clipboardItem.getType(type);
console.log(blob);
const res = await blob.text();
let str = res;
str = str.replace(/2023-12-12/g, "");
console.log("res1", str);
arr.push(str);
}
}
}
console.log("arr", arr);
bbc(arr);
} catch (err) {
console.error(err.name, err.message);
}
}
async function bbc(arr) {
try {
const text = new Blob([arr[0]], {
type: "text/plain",
});
const html = new Blob([arr[1]], {
type: "text/html",
});
await navigator.clipboard.write([
new ClipboardItem({
"text/plain": text,
"text/html": html,
}),
]);
console.log("Image copied.");
} catch (err) {
console.error(err.name, err.message);
}
}
</script>
</body>
</html>