-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
extract-urls.html
111 lines (100 loc) · 3.24 KB
/
extract-urls.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Extract URLs</title>
<style>
* {
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
#input {
width: 100%;
max-width: 100%;
height: 100px;
margin-bottom: 10px;
border: 1px solid #ccc;
padding: 10px;
background-color: #f0f0f0;
}
#output-container {
display: none;
}
#output {
width: 100%;
max-width: 100%;
height: 150px;
margin-bottom: 10px;
border: 1px solid #ccc;
padding: 10px;
background-color: #fff;
}
#copy-button {
padding: 5px 10px;
cursor: pointer;
}
@media (max-width: 600px) {
body {
padding: 10px;
}
#input, #output {
height: 120px;
}
}
</style>
</head>
<body>
<h1>Extract URLs</h1>
<p>Copy content from a web page and paste here to extract linked URLs:</p>
<div id="input" contenteditable="true"></div>
<div id="output-container">
<h2>Extracted</h2>
<textarea id="output" readonly></textarea>
<button id="copy-button">Copy to clipboard</button>
</div>
<script>
const input = document.getElementById('input');
const outputContainer = document.getElementById('output-container');
const output = document.getElementById('output');
const copyButton = document.getElementById('copy-button');
input.addEventListener('paste', function(e) {
e.preventDefault();
const clipboardData = e.clipboardData || window.clipboardData;
const pastedData = clipboardData.getData('text/html');
const temp = document.createElement('div');
temp.innerHTML = pastedData;
const links = temp.getElementsByTagName('a');
const urls = Array.from(links)
.map(link => link.href)
.filter(url => url.startsWith('http'));
if (urls.length > 0) {
output.value = urls.join('\n');
outputContainer.style.display = 'block';
} else {
outputContainer.style.display = 'none';
}
input.textContent = 'Content pasted. URLs extracted.';
});
input.addEventListener('focus', function() {
if (input.textContent === 'Content pasted. URLs extracted.') {
input.textContent = '';
}
});
copyButton.addEventListener('click', function() {
output.select();
document.execCommand('copy');
const originalText = copyButton.textContent;
copyButton.textContent = 'Copied!';
setTimeout(() => {
copyButton.textContent = originalText;
}, 1500);
});
</script>
</body>
</html>