generated from kachick/anylang-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub-patcher.ts
53 lines (46 loc) · 1.41 KB
/
github-patcher.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const hide = (element: Element): void => {
element.setAttribute(
// Prefer hidden rather than display:none https://primer.style/css/utilities/layout#the-html-hidden-attribute
'hidden',
// Both `true` and `false` will be interpreted as `true`.
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden
'true',
);
};
chrome.storage.sync.get([
'isHideExploreRepositories',
'isHideSponsors',
]).then((keys): void => {
if (keys.isHideExploreRepositories) {
const exploreRepositoriesComponent = document.querySelector(
"div[aria-label='Explore repositories']",
);
if (exploreRepositoriesComponent) {
hide(exploreRepositoriesComponent);
}
}
if (keys.isHideSponsors) {
const sponsorsH2Node = document.evaluate(
"/html/body//div[@class='Layout-sidebar']//h2[text()='Sponsors']",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null,
).singleNodeValue;
const sponsorsComponent = sponsorsH2Node?.parentElement?.parentElement;
if (sponsorsComponent) {
hide(sponsorsComponent);
}
}
});
const highlightsH2Node = document.evaluate(
"/html/body//div[@class='Layout-sidebar']//h2[text()='Highlights']",
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null,
).singleNodeValue;
const highlightsComponent = highlightsH2Node?.parentElement;
if (highlightsComponent) {
hide(highlightsComponent);
}