Skip to content

Commit 6dbf4e0

Browse files
fix: Flags and components dropdowns (#113)
This PR fixes the currently (totally) broken flags and components dropdowns. It seems GH made a change to the dom here recently and it broke our manipulations. With the fix I've also just simplified the process a good bit.
1 parent 2a8c742 commit 6dbf4e0

File tree

2 files changed

+6
-23
lines changed

2 files changed

+6
-23
lines changed

src/content/github/file/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ function createCoverageButton() {
298298
});
299299
const textNode = codecovButton.querySelector('[data-component="text"]')!;
300300
textNode.innerHTML = "Coverage: ...";
301-
rawButton.parentNode?.parentNode?.prepend(codecovButton);
301+
rawButton.parentNode?.parentNode?.parentNode?.prepend(codecovButton);
302302
return codecovButton;
303303
}
304304

src/content/github/file/utils/dropdown.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,12 @@ export async function createDropdown({
1717
previousElement: HTMLElement;
1818
selectedOptions: string[];
1919
}) {
20-
// Build the button out of the Raw/copy/download button group
21-
const rawButton = document
22-
.querySelector('[data-testid="download-raw-button"]')!
23-
.closest("div");
24-
if (!rawButton) throw new Error("Could not find raw button group");
20+
const rawButton = document.querySelector('[data-testid="raw-button"]');
21+
if (!rawButton) {
22+
throw new Error("Raw button not found");
23+
}
2524
const dropdownButton = rawButton.cloneNode(true) as HTMLElement;
26-
// Remove copy button
27-
const copyButton = dropdownButton.querySelector(
28-
'[data-testid="copy-raw-button"]'
29-
);
30-
if (!copyButton) throw new Error("Could not find copy button");
31-
dropdownButton.removeChild(copyButton);
32-
// Replace download button with dropdown button
33-
const downloadButton = dropdownButton.querySelector(
34-
'[data-testid="download-raw-button"]'
35-
);
36-
if (!downloadButton || !downloadButton.firstChild)
37-
throw new Error("Could not find download button or it is missing children");
38-
const triangleDownSvg = document.querySelector(".octicon-triangle-down");
39-
if (!triangleDownSvg) throw new Error("Could not find triangle down svg");
40-
downloadButton.replaceChild(triangleDownSvg, downloadButton.firstChild);
41-
42-
const textNode = dropdownButton.querySelector('[data-testid="raw-button"]');
25+
const textNode = dropdownButton.querySelector('[data-component="text"]');
4326
if (!textNode || !textNode.parentElement)
4427
throw new Error("Could not find textNode");
4528
textNode.innerHTML = "";

0 commit comments

Comments
 (0)