github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/pkg/spyglass/lenses/links/links.ts (about) 1 // https://stackoverflow.com/a/49121680 2 3 const copyMessage = (val: string) => { 4 const selBox = document.createElement('textarea'); 5 selBox.style.position = 'fixed'; 6 selBox.style.left = '0'; 7 selBox.style.top = '0'; 8 selBox.style.opacity = '0'; 9 selBox.value = val; 10 document.body.appendChild(selBox); 11 selBox.focus(); 12 selBox.select(); 13 document.execCommand('copy'); 14 document.body.removeChild(selBox); 15 }; 16 17 /* eslint-disable @typescript-eslint/require-await */ 18 const handleCopy = async function(this: HTMLButtonElement) { 19 copyMessage(this.dataset.link || ""); 20 }; 21 22 const addLinksExpanders = (): void => { 23 const expanders = document.querySelectorAll<HTMLTableRowElement>('tr.links-expander'); 24 for (const expander of Array.from(expanders)) { 25 expander.onclick = () => { 26 const tbody = expander.parentElement.nextElementSibling; 27 const icon = expander.querySelector('i')!; 28 if (tbody.classList.contains('hidden-links')) { 29 tbody.classList.remove('hidden-links'); 30 icon.innerText = 'expand_less'; 31 } else { 32 tbody.classList.add('hidden-links'); 33 icon.innerText = 'expand_more'; 34 } 35 spyglass.contentUpdated(); 36 }; 37 } 38 }; 39 40 window.addEventListener('load', () => { 41 for (const button of Array.from(document.querySelectorAll<HTMLButtonElement>("button.copy"))) { 42 button.addEventListener('click', handleCopy); 43 } 44 }); 45 46 window.addEventListener('DOMContentLoaded', addLinksExpanders);