-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcustom.js
More file actions
63 lines (52 loc) · 1.74 KB
/
custom.js
File metadata and controls
63 lines (52 loc) · 1.74 KB
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
54
55
56
57
58
59
60
61
62
63
(function hideDefaultGrayLabels() {
// We include default values in OpenAPI endpoints. Hide the "default:" label on the API page; it should only appear in the playground.
const classSelector = '.text-gray-400.dark\\:text-gray-500';
function elementHasExactDefaultText(element) {
return typeof element.textContent === 'string' && element.textContent.trim() === 'default:';
}
function hideMatchingElementsInTree(rootNode) {
if (!rootNode) return;
const elementsToCheck = [];
if (rootNode.nodeType === 1 && rootNode.matches && rootNode.matches(classSelector)) {
elementsToCheck.push(rootNode);
}
if (rootNode.querySelectorAll) {
elementsToCheck.push(...rootNode.querySelectorAll(classSelector));
}
elementsToCheck.forEach((element) => {
if (elementHasExactDefaultText(element)) {
const parent = element.parentElement;
if (parent) {
parent.style.display = 'none';
}
}
});
}
function runInitialHide() {
hideMatchingElementsInTree(document);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', runInitialHide);
} else {
runInitialHide();
}
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((addedNode) => {
if (addedNode && addedNode.nodeType === 1) {
hideMatchingElementsInTree(addedNode);
}
});
});
});
function startObserving() {
if (document.body) {
observer.observe(document.body, { childList: true, subtree: true });
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', startObserving);
} else {
startObserving();
}
})();