Skip to content

Commit 70d51d6

Browse files
committed
fix
1 parent 3516b6d commit 70d51d6

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

footer.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,28 @@ const addLinks = () => {
2323
document.getElementById('main-navbar').appendChild(links);
2424
}
2525

26-
// All the `search` scripts start working only after window.onload(). Postponing search box adjustments
27-
window.onload = function (event) {
26+
function waitForElm(selector) {
27+
return new Promise(resolve => {
28+
if (document.querySelector(selector)) {
29+
return resolve(document.querySelector(selector));
30+
}
31+
32+
const observer = new MutationObserver(mutations => {
33+
if (document.querySelector(selector)) {
34+
observer.disconnect();
35+
resolve(document.querySelector(selector));
36+
}
37+
});
38+
39+
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
40+
observer.observe(document.body, {
41+
childList: true,
42+
subtree: true
43+
});
44+
});
45+
}
46+
47+
waitForElm('#MSearchField').then((elm) => {
2848
setTimeout(() => {
2949
init_all_results_button();
3050
init_search_hotkey();
@@ -34,7 +54,6 @@ window.onload = function (event) {
3454

3555
addLinks();
3656
changeTelegramChannelLanguageForRussianSpeakingUser();
37-
}, 1);
3857
};
3958

4059
const isLanding = document.getElementById('landing_logo_id') !== null;

0 commit comments

Comments
 (0)