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

Function add

source/features/list-prs-for-file.tsx:107–134  ·  view source on GitHub ↗
(anchor: HTMLElement)

Source from the content-addressed store, hash-verified

105});
106
107async function add(anchor: HTMLElement): Promise<false | void> {
108 const path = new GitHubFileUrl(location.href).filePath;
109 const prsByFile = await prsByFileCache.get();
110 let prs = prsByFile[path];
111
112 if (!prs) {
113 return;
114 }
115
116 // Only appears when editing files from PRs
117 const editingPrNumber = new URLSearchParams(location.search).get('pr')?.split('/').slice(-1);
118 if (editingPrNumber) {
119 prs = prs.filter(pr => pr !== Number(editingPrNumber));
120 if (prs.length === 0) {
121 return;
122 }
123 }
124
125 const dropdown = getDropdown(prs);
126 if (anchor.parentElement!.matches('.gap-2')) {
127 // `isSingleFile`
128 anchor.before(dropdown);
129 } else {
130 // `isEditingFile`
131 dropdown.classList.add('mr-2');
132 anchor.parentElement!.prepend(dropdown);
133 }
134}
135
136async function init(signal: AbortSignal): Promise<void> {
137 observe(

Callers

nothing calls this directly

Calls 4

getDropdownFunction · 0.85
getMethod · 0.80
matchesMethod · 0.80
prependMethod · 0.80

Tested by

no test coverage detected