-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
clipboard-viewer.html
133 lines (120 loc) · 4.26 KB
/
clipboard-viewer.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clipboard Format Viewer</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f0f0f0;
}
h1 {
text-align: center;
color: #333;
}
#paste-area {
width: 100%;
height: 100px;
margin-bottom: 20px;
padding: 10px;
border: 2px dashed #aaa;
border-radius: 5px;
resize: vertical;
}
#output {
background-color: white;
border: 1px solid #ddd;
border-radius: 5px;
padding: 20px;
max-height: 70vh;
overflow-y: auto;
}
.format {
margin-bottom: 20px;
border-bottom: 1px solid #eee;
padding-bottom: 10px;
}
.format h2 {
color: #0066cc;
margin-bottom: 10px;
}
.format-content {
max-height: 200px;
overflow-y: auto;
background-color: #f5f5f5;
border: 1px solid #ddd;
border-radius: 3px;
padding: 10px;
}
pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<h1>Clipboard Format Viewer</h1>
<textarea id="paste-area" placeholder="Paste here or anywhere on the page"></textarea>
<div id="output"></div>
<script>
const pasteArea = document.getElementById('paste-area');
const output = document.getElementById('output');
function handlePaste(event) {
event.preventDefault();
const clipboardData = event.clipboardData || window.clipboardData;
output.innerHTML = '';
// Get available formats
const formats = clipboardData.types;
formats.forEach(format => {
const formatDiv = document.createElement('div');
formatDiv.className = 'format';
const formatTitle = document.createElement('h2');
formatTitle.textContent = format;
formatDiv.appendChild(formatTitle);
const formatContentWrapper = document.createElement('div');
formatContentWrapper.className = 'format-content';
const formatContent = document.createElement('pre');
let content = clipboardData.getData(format);
// Special handling for certain formats
if (format === 'text/html') {
const tempElement = document.createElement('div');
tempElement.innerHTML = content;
content = tempElement.innerHTML;
} else if (format === 'Files') {
const files = clipboardData.files;
content = Array.from(files).map(file => `${file.name} (${file.type}, ${file.size} bytes)`).join('\n');
}
formatContent.textContent = content;
formatContentWrapper.appendChild(formatContent);
formatDiv.appendChild(formatContentWrapper);
output.appendChild(formatDiv);
});
// Additional information about the clipboard event
const eventInfo = document.createElement('div');
eventInfo.className = 'format';
eventInfo.innerHTML = `
<h2>Clipboard Event Information</h2>
<div class="format-content">
<pre>
Event type: ${event.type}
Formats available: ${formats.join(', ')}
</pre>
</div>
`;
output.appendChild(eventInfo);
}
// Listen for paste events on the textarea
pasteArea.addEventListener('paste', handlePaste);
// Listen for paste events on the entire document
document.addEventListener('paste', handlePaste);
</script>
</body>
</html>