Skip to content

Commit e468d4b

Browse files
Copilotsimonw
andauthored
Add image URL display with copy button to alt text extractor (#106)
* Initial plan * Add image URL display with copy button to alt text extractor Co-authored-by: simonw <9599+simonw@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: simonw <9599+simonw@users.noreply.github.com>
1 parent 3171e9b commit e468d4b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

alt-text-extractor.html

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,28 @@
9999
font-style: italic;
100100
}
101101

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+
102124
.copy-button {
103125
background-color: #007bff;
104126
color: white;
@@ -242,8 +264,30 @@ <h1>Alt text extractor</h1>
242264
altSection.appendChild(altDisplay);
243265
altSection.appendChild(copyButton);
244266

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+
245288
itemDiv.appendChild(imageContainer);
246289
itemDiv.appendChild(altSection);
290+
itemDiv.appendChild(urlSection);
247291

248292
results.appendChild(itemDiv);
249293
}
@@ -287,6 +331,43 @@ <h1>Alt text extractor</h1>
287331
}
288332
}
289333

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+
290371
function clearAll() {
291372
pasteArea.innerHTML = '';
292373
results.innerHTML = '';

0 commit comments

Comments
 (0)