MCPcopy
hub / github.com/refined-github/refined-github / add

Function add

source/features/download-folder-button.tsx:10–38  ·  view source on GitHub ↗
(menu: HTMLUListElement)

Source from the content-addressed store, hash-verified

8import observe from '../helpers/selector-observer.js';
9
10function 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
40function init(signal: AbortSignal): void {
41 observe('ul[role="menu"]:has([aria-keyshortcuts="c"])', add, {signal});

Callers

nothing calls this directly

Calls 5

setMethod · 0.80
cloneNodeMethod · 0.80
removeMethod · 0.80
prependMethod · 0.80

Tested by

no test coverage detected