-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurlcp.html
More file actions
376 lines (325 loc) · 11.4 KB
/
urlcp.html
File metadata and controls
376 lines (325 loc) · 11.4 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL解析与复制工具</title>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
color: #333;
min-height: 100vh;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.container {
width: 100%;
max-width: 800px;
background-color: rgba(255, 255, 255, 0.95);
border-radius: 12px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
padding: 30px;
margin: 20px;
}
h1 {
text-align: center;
color: #1a2a6c;
margin-bottom: 25px;
font-size: 2.5rem;
position: relative;
padding-bottom: 15px;
}
h1:after {
content: '';
position: absolute;
bottom: 0;
left: 50%;
transform: translateX(-50%);
width: 80px;
height: 4px;
background: linear-gradient(to right, #1a2a6c, #b21f1f);
border-radius: 2px;
}
.description {
text-align: center;
margin-bottom: 25px;
color: #555;
line-height: 1.6;
}
.input-section {
margin-bottom: 30px;
}
textarea {
width: 100%;
min-height: 150px;
padding: 15px;
border: 2px solid #ddd;
border-radius: 8px;
font-size: 16px;
resize: vertical;
transition: border-color 0.3s;
}
textarea:focus {
border-color: #1a2a6c;
outline: none;
box-shadow: 0 0 0 3px rgba(26, 42, 108, 0.2);
}
.button-group {
display: flex;
gap: 15px;
margin-top: 15px;
flex-wrap: wrap;
}
button {
flex: 1;
min-width: 150px;
padding: 14px 20px;
font-size: 16px;
font-weight: 600;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
#pasteBtn {
background-color: #4CAF50;
color: white;
}
#parseBtn {
background-color: #1a2a6c;
color: white;
}
#clearBtn {
background-color: #f44336;
color: white;
}
button:hover {
transform: translateY(-3px);
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
}
button:active {
transform: translateY(0);
}
#pasteBtn:hover {
background-color: #388E3C;
}
#parseBtn:hover {
background-color: #0f1c55;
}
#clearBtn:hover {
background-color: #d32f2f;
}
.output-section {
margin-top: 30px;
}
.url-list {
list-style: none;
margin-top: 15px;
max-height: 400px;
overflow-y: auto;
border: 2px solid #eee;
border-radius: 8px;
padding: 10px;
background-color: #f9f9f9;
}
.url-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 12px 15px;
border-bottom: 1px solid #eee;
transition: background-color 0.2s;
}
.url-item:last-child {
border-bottom: none;
}
.url-item:hover {
background-color: #f0f0f0;
}
.url-text {
flex: 1;
word-break: break-all;
padding-right: 15px;
color: #1a2a6c;
font-weight: 500;
}
.url-actions {
display: flex;
gap: 10px;
}
.copy-btn {
padding: 8px 15px;
background-color: #2196F3;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
transition: background-color 0.2s;
}
.copy-btn:hover {
background-color: #0b7dda;
}
.copy-btn.copied {
background-color: #4CAF50;
}
.no-urls {
text-align: center;
padding: 30px;
color: #777;
}
.notification {
position: fixed;
top: 20px;
right: 20px;
padding: 15px 25px;
background-color: #4CAF50;
color: white;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
transform: translateX(150%);
transition: transform 0.5s ease;
z-index: 1000;
}
.notification.show {
transform: translateX(0);
}
@media (max-width: 768px) {
.button-group {
flex-direction: column;
}
button {
width: 100%;
}
}
</style>
</head>
<body>
<div class="container">
<h1>URL解析与复制工具</h1>
<p class="description">粘贴任意文本到下方文本框,点击"解析URL"按钮提取所有URL地址,然后点击单个URL旁边的复制按钮</p>
<div class="input-section">
<textarea id="inputText" placeholder="在此粘贴包含URL的文本..."></textarea>
<div class="button-group">
<button id="pasteBtn">粘贴文本</button>
<button id="parseBtn">解析URL</button>
<button id="clearBtn">清除内容</button>
</div>
</div>
<div class="output-section">
<h2>提取的URL列表:</h2>
<ul id="urlList" class="url-list">
<li class="no-urls">尚未解析任何URL</li>
</ul>
</div>
</div>
<div id="notification" class="notification">URL已复制到剪贴板!</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// 获取DOM元素
const inputText = document.getElementById('inputText');
const pasteBtn = document.getElementById('pasteBtn');
const parseBtn = document.getElementById('parseBtn');
const clearBtn = document.getElementById('clearBtn');
const urlList = document.getElementById('urlList');
const notification = document.getElementById('notification');
// 粘贴按钮事件
pasteBtn.addEventListener('click', async function() {
try {
const text = await navigator.clipboard.readText();
inputText.value = text;
} catch (err) {
alert('无法访问剪贴板内容,请手动粘贴文本');
}
});
// 解析按钮事件
parseBtn.addEventListener('click', function() {
const text = inputText.value.trim();
if (!text) {
alert('请输入文本内容');
return;
}
// 使用正则表达式提取URL
const urlRegex = /(https?:\/\/[^\s]+)/g;
const urls = text.match(urlRegex) || [];
// 清空URL列表
urlList.innerHTML = '';
if (urls.length === 0) {
urlList.innerHTML = '<li class="no-urls">未找到URL</li>';
return;
}
// 去重并添加URL项
const uniqueUrls = [...new Set(urls)];
uniqueUrls.forEach(url => {
const li = document.createElement('li');
li.className = 'url-item';
li.innerHTML = `
<span class="url-text">${url}</span>
<div class="url-actions">
<button class="copy-btn" data-url="${url}">复制</button>
</div>
`;
urlList.appendChild(li);
});
// 为所有复制按钮添加事件
document.querySelectorAll('.copy-btn').forEach(btn => {
btn.addEventListener('click', function() {
const url = this.getAttribute('data-url');
copyToClipboard(url);
// 显示通知
notification.classList.add('show');
setTimeout(() => {
notification.classList.remove('show');
}, 2000);
// 添加复制成功样式
this.classList.add('copied');
this.textContent = '已复制';
setTimeout(() => {
this.classList.remove('copied');
this.textContent = '复制';
}, 2000);
});
});
});
// 清除按钮事件
clearBtn.addEventListener('click', function() {
inputText.value = '';
urlList.innerHTML = '<li class="no-urls">尚未解析任何URL</li>';
});
// 复制到剪贴板函数
function copyToClipboard(text) {
try {
// 使用Clipboard API(现代方法)
navigator.clipboard.writeText(text);
} catch (err) {
// 如果不支持Clipboard API,使用旧方法
const textArea = document.createElement('textarea');
textArea.value = text;
textArea.style.position = 'fixed';
textArea.style.top = 0;
textArea.style.left = 0;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
} catch (copyErr) {
console.error('无法复制文本: ', copyErr);
alert('无法复制文本,请手动复制');
}
document.body.removeChild(textArea);
}
}
});
</script>
</body>
</html>