|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Extract URLs</title> |
| 7 | + <style> |
| 8 | + * { |
| 9 | + box-sizing: border-box; |
| 10 | + } |
| 11 | + body { |
| 12 | + font-family: Arial, sans-serif; |
| 13 | + max-width: 800px; |
| 14 | + margin: 0 auto; |
| 15 | + padding: 20px; |
| 16 | + } |
| 17 | + #input { |
| 18 | + width: 100%; |
| 19 | + max-width: 100%; |
| 20 | + height: 100px; |
| 21 | + margin-bottom: 10px; |
| 22 | + border: 1px solid #ccc; |
| 23 | + padding: 10px; |
| 24 | + background-color: #f0f0f0; |
| 25 | + } |
| 26 | + #output-container { |
| 27 | + display: none; |
| 28 | + } |
| 29 | + #output { |
| 30 | + width: 100%; |
| 31 | + max-width: 100%; |
| 32 | + height: 150px; |
| 33 | + margin-bottom: 10px; |
| 34 | + border: 1px solid #ccc; |
| 35 | + padding: 10px; |
| 36 | + background-color: #fff; |
| 37 | + } |
| 38 | + #copy-button { |
| 39 | + padding: 5px 10px; |
| 40 | + cursor: pointer; |
| 41 | + } |
| 42 | + @media (max-width: 600px) { |
| 43 | + body { |
| 44 | + padding: 10px; |
| 45 | + } |
| 46 | + #input, #output { |
| 47 | + height: 120px; |
| 48 | + } |
| 49 | + } |
| 50 | + </style> |
| 51 | +</head> |
| 52 | +<body> |
| 53 | + <h1>Extract URLs</h1> |
| 54 | + <p>Copy content from a web page and paste here to extract linked URLs:</p> |
| 55 | + <div id="input" contenteditable="true"></div> |
| 56 | + <div id="output-container"> |
| 57 | + <h2>Extracted</h2> |
| 58 | + <textarea id="output" readonly></textarea> |
| 59 | + <button id="copy-button">Copy to clipboard</button> |
| 60 | + </div> |
| 61 | + |
| 62 | + <script> |
| 63 | + const input = document.getElementById('input'); |
| 64 | + const outputContainer = document.getElementById('output-container'); |
| 65 | + const output = document.getElementById('output'); |
| 66 | + const copyButton = document.getElementById('copy-button'); |
| 67 | + |
| 68 | + input.addEventListener('paste', function(e) { |
| 69 | + e.preventDefault(); |
| 70 | + |
| 71 | + const clipboardData = e.clipboardData || window.clipboardData; |
| 72 | + const pastedData = clipboardData.getData('text/html'); |
| 73 | + |
| 74 | + const temp = document.createElement('div'); |
| 75 | + temp.innerHTML = pastedData; |
| 76 | + |
| 77 | + const links = temp.getElementsByTagName('a'); |
| 78 | + const urls = Array.from(links) |
| 79 | + .map(link => link.href) |
| 80 | + .filter(url => url.startsWith('http')); |
| 81 | + |
| 82 | + if (urls.length > 0) { |
| 83 | + output.value = urls.join('\n'); |
| 84 | + outputContainer.style.display = 'block'; |
| 85 | + } else { |
| 86 | + outputContainer.style.display = 'none'; |
| 87 | + } |
| 88 | + |
| 89 | + input.textContent = 'Content pasted. URLs extracted.'; |
| 90 | + }); |
| 91 | + |
| 92 | + input.addEventListener('focus', function() { |
| 93 | + if (input.textContent === 'Content pasted. URLs extracted.') { |
| 94 | + input.textContent = ''; |
| 95 | + } |
| 96 | + }); |
| 97 | + |
| 98 | + copyButton.addEventListener('click', function() { |
| 99 | + output.select(); |
| 100 | + document.execCommand('copy'); |
| 101 | + |
| 102 | + const originalText = copyButton.textContent; |
| 103 | + copyButton.textContent = 'Copied!'; |
| 104 | + |
| 105 | + setTimeout(() => { |
| 106 | + copyButton.textContent = originalText; |
| 107 | + }, 1500); |
| 108 | + }); |
| 109 | + </script> |
| 110 | +</body> |
| 111 | +</html> |
0 commit comments