(menu: HTMLUListElement)
| 8 | import observe from '../helpers/selector-observer.js'; |
| 9 | |
| 10 | function add(menu: HTMLUListElement): void { |
| 11 | const downloadUrl = new URL('https://download-directory.github.io/'); |
| 12 | downloadUrl.searchParams.set('url', location.href); |
| 13 | |
| 14 | const item = menu.firstElementChild!.cloneNode(true); |
| 15 | item.role = 'none'; |
| 16 | item.removeAttribute('tabindex'); |
| 17 | item.removeAttribute('id'); |
| 18 | item.removeAttribute('aria-keyshortcuts'); |
| 19 | item.removeAttribute('aria-labelledby'); |
| 20 | |
| 21 | const link = item.firstElementChild instanceof HTMLAnchorElement |
| 22 | ? item.firstElementChild |
| 23 | // Not a link on permalinks and archived repos |
| 24 | : replaceElementTypeInPlace(item.firstElementChild!, 'a'); |
| 25 | link.href = downloadUrl.href; |
| 26 | link.classList.add('no-underline', 'fgColor-inherit'); |
| 27 | link.setAttribute('aria-keyshortcuts', 'c'); |
| 28 | |
| 29 | // Missing on permalinks and archived repos |
| 30 | $optional('svg', link)?.replaceWith(<DownloadIcon />); |
| 31 | |
| 32 | // Only on permalinks and archived repos |
| 33 | $optional('[id$="--trailing-visual"]', link)?.remove(); |
| 34 | |
| 35 | $('[id$="--label"]', link).textContent = 'Download directory'; |
| 36 | |
| 37 | menu.prepend(item); |
| 38 | } |
| 39 | |
| 40 | function init(signal: AbortSignal): void { |
| 41 | observe('ul[role="menu"]:has([aria-keyshortcuts="c"])', add, {signal}); |
nothing calls this directly
no test coverage detected