-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
80 lines (70 loc) · 1.88 KB
/
script.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* make top-nav external links target="_blank"
*/
function convertHttpLinkstoExternal() {
var external = document.querySelectorAll('[target="_self"][to*="https://"]');
external.forEach(function (el) {
el.href = el.getAttribute("to");
el.target = "_blank";
});
}
/**
* Exclude the playground from fullstory.
*/
function excludePlayergroundFromAnalytics() {
var playground = document.getElementById("ReferencePlayground");
if (playground) {
playground.classList.add("fs-exclude");
playground.setAttribute("data-heap-redact-text", "");
}
}
/**
* Registers a MutationObserver to the first object with the specified value of the ID attribute.
* @param {string} elementId String that specifies the ID value.
*/
function registerObserverById(elementId) {
/**
* Get element to observe
*/
const targetNode = document.getElementById(elementId);
if (targetNode) {
/**
* Options for the observer (which mutations to observe).
*/
const config = { childList: true, subtree: true };
/**
* Callback function to execute when mutations are observed.
*/
const callback = () => {
observableChanges();
};
/**
* Create an observer instance linked to the callback function.
*/
const observer = new MutationObserver(callback);
/**
* Start observing the target node for configured mutations.
*/
observer.observe(targetNode, config);
}
}
/**
* Changes once the page has initialized.
*/
function launchChanges() {
convertHttpLinkstoExternal();
excludePlayergroundFromAnalytics();
console.clear();
}
/**
* Changes that run when #Explorer mutations are observed.
*/
function observableChanges() {
convertHttpLinkstoExternal();
excludePlayergroundFromAnalytics();
}
window.onload = function () {
// Initial page changes.
launchChanges();
registerObserverById("ssr-main"); // body by ID
};