|
99 | 99 | font-style: italic; |
100 | 100 | } |
101 | 101 |
|
| 102 | +.url-section { |
| 103 | + margin-top: 15px; |
| 104 | +} |
| 105 | + |
| 106 | +.url-label { |
| 107 | + font-weight: bold; |
| 108 | + color: #333; |
| 109 | + margin-bottom: 8px; |
| 110 | +} |
| 111 | + |
| 112 | +.url-display { |
| 113 | + background-color: #f8f9fa; |
| 114 | + border: 1px solid #e9ecef; |
| 115 | + border-radius: 4px; |
| 116 | + padding: 10px; |
| 117 | + font-size: 14px; |
| 118 | + color: #495057; |
| 119 | + margin-bottom: 10px; |
| 120 | + word-wrap: break-word; |
| 121 | + word-break: break-all; |
| 122 | +} |
| 123 | + |
102 | 124 | .copy-button { |
103 | 125 | background-color: #007bff; |
104 | 126 | color: white; |
@@ -242,8 +264,30 @@ <h1>Alt text extractor</h1> |
242 | 264 | altSection.appendChild(altDisplay); |
243 | 265 | altSection.appendChild(copyButton); |
244 | 266 |
|
| 267 | + // Create URL section |
| 268 | + const urlSection = document.createElement('div'); |
| 269 | + urlSection.className = 'url-section'; |
| 270 | + |
| 271 | + const urlLabel = document.createElement('div'); |
| 272 | + urlLabel.className = 'url-label'; |
| 273 | + urlLabel.textContent = 'Image URL:'; |
| 274 | + |
| 275 | + const urlDisplay = document.createElement('div'); |
| 276 | + urlDisplay.className = 'url-display'; |
| 277 | + urlDisplay.textContent = src; |
| 278 | + |
| 279 | + const urlCopyButton = document.createElement('button'); |
| 280 | + urlCopyButton.className = 'copy-button'; |
| 281 | + urlCopyButton.textContent = 'Copy URL'; |
| 282 | + urlCopyButton.addEventListener('click', () => copyUrl(src, urlCopyButton)); |
| 283 | + |
| 284 | + urlSection.appendChild(urlLabel); |
| 285 | + urlSection.appendChild(urlDisplay); |
| 286 | + urlSection.appendChild(urlCopyButton); |
| 287 | + |
245 | 288 | itemDiv.appendChild(imageContainer); |
246 | 289 | itemDiv.appendChild(altSection); |
| 290 | + itemDiv.appendChild(urlSection); |
247 | 291 |
|
248 | 292 | results.appendChild(itemDiv); |
249 | 293 | } |
@@ -287,6 +331,43 @@ <h1>Alt text extractor</h1> |
287 | 331 | } |
288 | 332 | } |
289 | 333 |
|
| 334 | +async function copyUrl(url, button) { |
| 335 | + try { |
| 336 | + await navigator.clipboard.writeText(url); |
| 337 | + |
| 338 | + const originalText = button.textContent; |
| 339 | + button.textContent = 'Copied!'; |
| 340 | + button.classList.add('copy-success'); |
| 341 | + |
| 342 | + setTimeout(() => { |
| 343 | + button.textContent = originalText; |
| 344 | + button.classList.remove('copy-success'); |
| 345 | + }, 2000); |
| 346 | + |
| 347 | + } catch (err) { |
| 348 | + console.error('Failed to copy URL: ', err); |
| 349 | + |
| 350 | + // Fallback for older browsers |
| 351 | + const textArea = document.createElement('textarea'); |
| 352 | + textArea.value = url; |
| 353 | + document.body.appendChild(textArea); |
| 354 | + textArea.select(); |
| 355 | + try { |
| 356 | + document.execCommand('copy'); |
| 357 | + button.textContent = 'Copied!'; |
| 358 | + button.classList.add('copy-success'); |
| 359 | + |
| 360 | + setTimeout(() => { |
| 361 | + button.textContent = 'Copy URL'; |
| 362 | + button.classList.remove('copy-success'); |
| 363 | + }, 2000); |
| 364 | + } catch (fallbackErr) { |
| 365 | + console.error('Fallback copy failed: ', fallbackErr); |
| 366 | + } |
| 367 | + document.body.removeChild(textArea); |
| 368 | + } |
| 369 | +} |
| 370 | + |
290 | 371 | function clearAll() { |
291 | 372 | pasteArea.innerHTML = ''; |
292 | 373 | results.innerHTML = ''; |
|
0 commit comments