File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed
Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff 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
4059const isLanding = document . getElementById ( 'landing_logo_id' ) !== null ;
You can’t perform that action at this time.
0 commit comments