-
Notifications
You must be signed in to change notification settings - Fork 0
/
book.js
784 lines (684 loc) · 23.3 KB
/
book.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
"use strict";
// Fix back button cache problem
window.onunload = function() {};
// Global variable, shared between modules
function playpen_text(playpen) {
let code_block = playpen.querySelector("code");
if (window.ace && code_block.classList.contains("editable")) {
let editor = window.ace.edit(code_block);
return editor.getValue();
} else {
return code_block.textContent;
}
}
(function codeSnippets() {
// Hide Rust code lines prepended with a specific character
var hiding_character = "#";
function fetch_with_timeout(url, options, timeout = 30000) {
return Promise.race([
fetch(url, options),
new Promise((_, reject) =>
setTimeout(() => reject(new Error("timeout")), timeout)
)
]);
}
var playpens = Array.from(document.querySelectorAll(".playpen"));
if (playpens.length > 0) {
fetch_with_timeout("https://play.rust-lang.org/meta/crates", {
headers: {
"Content-Type": "application/json"
},
method: "POST",
mode: "cors"
})
.then(response => response.json())
.then(response => {
// get list of crates available in the rust playground
let playground_crates = response.crates.map(item => item["id"]);
playpens.forEach(block =>
handle_crate_list_update(block, playground_crates)
);
});
}
function handle_crate_list_update(playpen_block, playground_crates) {
// update the play buttons after receiving the response
update_play_button(playpen_block, playground_crates);
// and install on change listener to dynamically update ACE editors
if (window.ace) {
let code_block = playpen_block.querySelector("code");
if (code_block.classList.contains("editable")) {
let editor = window.ace.edit(code_block);
editor.addEventListener("change", function(e) {
update_play_button(playpen_block, playground_crates);
});
}
}
}
// updates the visibility of play button based on `no_run` class and
// used crates vs ones available on http://play.rust-lang.org
function update_play_button(pre_block, playground_crates) {
var play_button = pre_block.querySelector(".play-button");
// skip if code is `no_run`
if (pre_block.querySelector("code").classList.contains("no_run")) {
play_button.classList.add("hidden");
return;
}
// get list of `extern crate`'s from snippet
var txt = playpen_text(pre_block);
var re = /extern\s+crate\s+([a-zA-Z_0-9]+)\s*;/g;
var snippet_crates = [];
var item;
while ((item = re.exec(txt))) {
snippet_crates.push(item[1]);
}
// check if all used crates are available on play.rust-lang.org
var all_available = snippet_crates.every(function(elem) {
return playground_crates.indexOf(elem) > -1;
});
if (all_available) {
play_button.classList.remove("hidden");
} else {
play_button.classList.add("hidden");
}
}
function run_rust_code(code_block) {
var result_block = code_block.querySelector(".result");
if (!result_block) {
result_block = document.createElement("code");
result_block.className = "result hljs language-bash";
code_block.append(result_block);
}
let text = playpen_text(code_block);
let classes = code_block.querySelector("code").classList;
let has_2018 = classes.contains("edition2018");
let edition = has_2018 ? "2018" : "2015";
var params = {
version: "stable",
optimize: "0",
code: text,
edition: edition
};
if (text.indexOf("#![feature") !== -1) {
params.version = "nightly";
}
result_block.innerText = "Running...";
// hijack params
params = new URLSearchParams({
filename: "File.kt",
project: JSON.stringify({
id: "",
name: "",
args: "",
compilerVersion: "1.3.50",
confType: "java",
originUrl: null,
files: [
{
name: "File.kt",
text: text
}
],
readOnlyFileNames: []
})
});
// const searchParams = Object.keys(params)
// .map(key => {
// return encodeURIComponent(key) + "=" + encodeURIComponent(params[key]);
// })
// .join("&");
// 编译错误 {"errors":{"File.kt":[{"interval":{"start":{"line":20,"ch":16},"end":{"line":20,"ch":17}},"message":"Expecting ')'","severity":"ERROR","className":"red_wavy_line"}]}}
// 正常 {"text":"<outStream>0, 1\n</outStream>","exception":null,"errors":{"File.kt":[]}}
// 运行时 异常 {"text":"","exception":{"message":"100","fullName":"java.lang.ArrayIndexOutOfBoundsException","stackTrace":[{"className":"TwoSum","methodName":"twoSum","fileName":"File.kt","lineNumber":12},{"className":"FileKt","methodName":"main","fileName":"File.kt","lineNumber":20},{"className":"FileKt","methodName":"main","fileName":"File.kt","lineNumber":-1}],"cause":null},"errors":{"File.kt":[]}}
function result_handel(response) {
if (response.exception != null) {
return (
JSON.stringify(response.exception, null, 2) + "\n" + response.text
);
}
if (response.errors["File.kt"].length != 0) {
return JSON.stringify(response.errors["File.kt"], null, 2);
}
return response.text.slice(11, -12);
}
fetch_with_timeout(
"https://try.kotlinlang.org/kotlinServer?type=run&runConf=java",
{
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
},
method: "POST",
mode: "cors",
body: params.toString()
}
)
.then(response => response.json())
.then(response => (result_block.innerText = result_handel(response))) // rm <outStream> </outStream>
.catch(
error =>
(result_block.innerText =
"Playground Communication: " + error.message)
);
// fetch_with_timeout("https://play.rust-lang.org/evaluate.json", {
// headers: {
// "Content-Type": "application/json"
// },
// method: "POST",
// mode: "cors",
// body: JSON.stringify(params)
// })
// .then(response => response.json())
// .then(response => (result_block.innerText = response.result))
// .catch(
// error =>
// (result_block.innerText =
// "Playground Communication: " + error.message)
// );
}
// Syntax highlighting Configuration
hljs.configure({
tabReplace: " ", // 4 spaces
languages: [] // Languages used for auto-detection
});
if (window.ace) {
// language-rust class needs to be removed for editable
// blocks or highlightjs will capture events
Array.from(document.querySelectorAll("code.editable")).forEach(function(
block
) {
block.classList.remove("language-rust");
});
Array.from(document.querySelectorAll("code:not(.editable)")).forEach(
function(block) {
hljs.highlightBlock(block);
}
);
} else {
Array.from(document.querySelectorAll("code")).forEach(function(block) {
hljs.highlightBlock(block);
});
}
// Adding the hljs class gives code blocks the color css
// even if highlighting doesn't apply
Array.from(document.querySelectorAll("code")).forEach(function(block) {
block.classList.add("hljs");
});
Array.from(document.querySelectorAll("code.language-rust")).forEach(function(
block
) {
var code_block = block;
var pre_block = block.parentNode;
// hide lines
var lines = code_block.innerHTML.split("\n");
var first_non_hidden_line = false;
var lines_hidden = false;
var trimmed_line = "";
for (var n = 0; n < lines.length; n++) {
trimmed_line = lines[n].trim();
if (
trimmed_line[0] == hiding_character &&
trimmed_line[1] != hiding_character
) {
if (first_non_hidden_line) {
lines[n] =
'<span class="hidden">' +
"\n" +
lines[n].replace(/(\s*)# ?/, "$1") +
"</span>";
} else {
lines[n] =
'<span class="hidden">' +
lines[n].replace(/(\s*)# ?/, "$1") +
"\n" +
"</span>";
}
lines_hidden = true;
} else if (first_non_hidden_line) {
lines[n] = "\n" + lines[n];
} else {
first_non_hidden_line = true;
}
if (
trimmed_line[0] == hiding_character &&
trimmed_line[1] == hiding_character
) {
lines[n] = lines[n].replace("##", "#");
}
}
code_block.innerHTML = lines.join("");
// If no lines were hidden, return
if (!lines_hidden) {
return;
}
var buttons = document.createElement("div");
buttons.className = "buttons";
buttons.innerHTML =
'<button class="fa fa-expand" title="Show hidden lines" aria-label="Show hidden lines"></button>';
// add expand button
pre_block.insertBefore(buttons, pre_block.firstChild);
pre_block.querySelector(".buttons").addEventListener("click", function(e) {
if (e.target.classList.contains("fa-expand")) {
var lines = pre_block.querySelectorAll("span.hidden");
e.target.classList.remove("fa-expand");
e.target.classList.add("fa-compress");
e.target.title = "Hide lines";
e.target.setAttribute("aria-label", e.target.title);
Array.from(lines).forEach(function(line) {
line.classList.remove("hidden");
line.classList.add("unhidden");
});
} else if (e.target.classList.contains("fa-compress")) {
var lines = pre_block.querySelectorAll("span.unhidden");
e.target.classList.remove("fa-compress");
e.target.classList.add("fa-expand");
e.target.title = "Show hidden lines";
e.target.setAttribute("aria-label", e.target.title);
Array.from(lines).forEach(function(line) {
line.classList.remove("unhidden");
line.classList.add("hidden");
});
}
});
});
Array.from(document.querySelectorAll("pre code")).forEach(function(block) {
var parent = block.parentNode;
// console.log(parent);
var playgroundElement = document.createElement("pre");
playgroundElement.className = "playpen";
playgroundElement.appendChild(block);
// parent.removeChild(block)
parent.appendChild(playgroundElement);
});
// Array.from(document.querySelectorAll("pre code")).forEach(function(block) {
// var pre_block = block.parentNode;
// if (!pre_block.classList.contains("playpen")) {
// var buttons = pre_block.querySelector(".buttons");
// if (!buttons) {
// buttons = document.createElement("div");
// buttons.className = "buttons";
// pre_block.insertBefore(buttons, pre_block.firstChild);
// }
// var clipButton = document.createElement("button");
// clipButton.className = "fa fa-copy clip-button";
// clipButton.title = "Copy to clipboard";
// clipButton.setAttribute("aria-label", clipButton.title);
// clipButton.innerHTML = '<i class="tooltiptext"></i>';
// buttons.insertBefore(clipButton, buttons.firstChild);
// }
// });
// Process playpen code blocks
Array.from(document.querySelectorAll(".playpen")).forEach(function(
pre_block
) {
// Add play button
var buttons = pre_block.querySelector(".buttons");
if (!buttons) {
buttons = document.createElement("div");
buttons.className = "buttons";
pre_block.insertBefore(buttons, pre_block.firstChild);
}
var runCodeButton = document.createElement("button");
runCodeButton.className = "fa fa-play play-button";
runCodeButton.hidden = true;
runCodeButton.title = "Run this code";
runCodeButton.setAttribute("aria-label", runCodeButton.title);
var copyCodeClipboardButton = document.createElement("button");
copyCodeClipboardButton.className = "fa fa-copy clip-button";
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
copyCodeClipboardButton.title = "Copy to clipboard";
copyCodeClipboardButton.setAttribute(
"aria-label",
copyCodeClipboardButton.title
);
buttons.insertBefore(runCodeButton, buttons.firstChild);
buttons.insertBefore(copyCodeClipboardButton, buttons.firstChild);
runCodeButton.addEventListener("click", function(e) {
run_rust_code(pre_block);
});
let code_block = pre_block.querySelector("code");
if (window.ace && code_block.classList.contains("editable")) {
var undoChangesButton = document.createElement("button");
undoChangesButton.className = "fa fa-history reset-button";
undoChangesButton.title = "Undo changes";
undoChangesButton.setAttribute("aria-label", undoChangesButton.title);
buttons.insertBefore(undoChangesButton, buttons.firstChild);
undoChangesButton.addEventListener("click", function() {
let editor = window.ace.edit(code_block);
editor.setValue(editor.originalCode);
editor.clearSelection();
});
}
});
})();
(function themes() {
var html = document.querySelector("html");
var themeToggleButton = document.getElementById("theme-toggle");
var themePopup = document.getElementById("theme-list");
var themeColorMetaTag = document.querySelector('meta[name="theme-color"]');
var stylesheets = {
ayuHighlight: document.querySelector("[href$='ayu-highlight.css']"),
tomorrowNight: document.querySelector("[href$='tomorrow-night.css']"),
highlight: document.querySelector("[href$='highlight.css']")
};
function showThemes() {
themePopup.style.display = "block";
themeToggleButton.setAttribute("aria-expanded", true);
themePopup.querySelector("button#" + document.body.className).focus();
}
function hideThemes() {
themePopup.style.display = "none";
themeToggleButton.setAttribute("aria-expanded", false);
themeToggleButton.focus();
}
function set_theme(theme) {
let ace_theme;
if (theme == "coal" || theme == "navy") {
stylesheets.ayuHighlight.disabled = true;
stylesheets.tomorrowNight.disabled = false;
stylesheets.highlight.disabled = true;
ace_theme = "ace/theme/tomorrow_night";
} else if (theme == "ayu") {
stylesheets.ayuHighlight.disabled = false;
stylesheets.tomorrowNight.disabled = true;
stylesheets.highlight.disabled = true;
ace_theme = "ace/theme/tomorrow_night";
} else {
stylesheets.ayuHighlight.disabled = true;
stylesheets.tomorrowNight.disabled = true;
stylesheets.highlight.disabled = false;
ace_theme = "ace/theme/dawn";
}
setTimeout(function() {
themeColorMetaTag.content = getComputedStyle(
document.body
).backgroundColor;
}, 1);
if (window.ace && window.editors) {
window.editors.forEach(function(editor) {
editor.setTheme(ace_theme);
});
}
var previousTheme;
try {
previousTheme = localStorage.getItem("mdbook-theme");
} catch (e) {}
if (previousTheme === null || previousTheme === undefined) {
previousTheme = default_theme;
}
try {
localStorage.setItem("mdbook-theme", theme);
} catch (e) {}
document.body.className = theme;
html.classList.remove(previousTheme);
html.classList.add(theme);
}
// Set theme
var theme;
try {
theme = localStorage.getItem("mdbook-theme");
} catch (e) {}
if (theme === null || theme === undefined) {
theme = default_theme;
}
set_theme(theme);
themeToggleButton.addEventListener("click", function() {
if (themePopup.style.display === "block") {
hideThemes();
} else {
showThemes();
}
});
themePopup.addEventListener("click", function(e) {
var theme = e.target.id || e.target.parentElement.id;
set_theme(theme);
});
themePopup.addEventListener("focusout", function(e) {
// e.relatedTarget is null in Safari and Firefox on macOS (see workaround below)
if (
!!e.relatedTarget &&
!themeToggleButton.contains(e.relatedTarget) &&
!themePopup.contains(e.relatedTarget)
) {
hideThemes();
}
});
// Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang-nursery/mdBook/issues/628
document.addEventListener("click", function(e) {
if (
themePopup.style.display === "block" &&
!themeToggleButton.contains(e.target) &&
!themePopup.contains(e.target)
) {
hideThemes();
}
});
document.addEventListener("keydown", function(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
return;
}
if (!themePopup.contains(e.target)) {
return;
}
switch (e.key) {
case "Escape":
e.preventDefault();
hideThemes();
break;
case "ArrowUp":
e.preventDefault();
var li = document.activeElement.parentElement;
if (li && li.previousElementSibling) {
li.previousElementSibling.querySelector("button").focus();
}
break;
case "ArrowDown":
e.preventDefault();
var li = document.activeElement.parentElement;
if (li && li.nextElementSibling) {
li.nextElementSibling.querySelector("button").focus();
}
break;
case "Home":
e.preventDefault();
themePopup.querySelector("li:first-child button").focus();
break;
case "End":
e.preventDefault();
themePopup.querySelector("li:last-child button").focus();
break;
}
});
})();
(function sidebar() {
var html = document.querySelector("html");
var sidebar = document.getElementById("sidebar");
var sidebarLinks = document.querySelectorAll("#sidebar a");
var sidebarToggleButton = document.getElementById("sidebar-toggle");
var sidebarResizeHandle = document.getElementById("sidebar-resize-handle");
var firstContact = null;
function showSidebar() {
html.classList.remove("sidebar-hidden");
html.classList.add("sidebar-visible");
Array.from(sidebarLinks).forEach(function(link) {
link.setAttribute("tabIndex", 0);
});
sidebarToggleButton.setAttribute("aria-expanded", true);
sidebar.setAttribute("aria-hidden", false);
try {
localStorage.setItem("mdbook-sidebar", "visible");
} catch (e) {}
}
function hideSidebar() {
html.classList.remove("sidebar-visible");
html.classList.add("sidebar-hidden");
Array.from(sidebarLinks).forEach(function(link) {
link.setAttribute("tabIndex", -1);
});
sidebarToggleButton.setAttribute("aria-expanded", false);
sidebar.setAttribute("aria-hidden", true);
try {
localStorage.setItem("mdbook-sidebar", "hidden");
} catch (e) {}
}
// Toggle sidebar
sidebarToggleButton.addEventListener("click", function sidebarToggle() {
if (html.classList.contains("sidebar-hidden")) {
showSidebar();
} else if (html.classList.contains("sidebar-visible")) {
hideSidebar();
} else {
if (getComputedStyle(sidebar)["transform"] === "none") {
hideSidebar();
} else {
showSidebar();
}
}
});
sidebarResizeHandle.addEventListener("mousedown", initResize, false);
function initResize(e) {
window.addEventListener("mousemove", resize, false);
window.addEventListener("mouseup", stopResize, false);
html.classList.add("sidebar-resizing");
}
function resize(e) {
document.documentElement.style.setProperty(
"--sidebar-width",
e.clientX - sidebar.offsetLeft + "px"
);
}
//on mouseup remove windows functions mousemove & mouseup
function stopResize(e) {
html.classList.remove("sidebar-resizing");
window.removeEventListener("mousemove", resize, false);
window.removeEventListener("mouseup", stopResize, false);
}
document.addEventListener(
"touchstart",
function(e) {
firstContact = {
x: e.touches[0].clientX,
time: Date.now()
};
},
{ passive: true }
);
document.addEventListener(
"touchmove",
function(e) {
if (!firstContact) return;
var curX = e.touches[0].clientX;
var xDiff = curX - firstContact.x,
tDiff = Date.now() - firstContact.time;
if (tDiff < 250 && Math.abs(xDiff) >= 150) {
if (
xDiff >= 0 &&
firstContact.x < Math.min(document.body.clientWidth * 0.25, 300)
)
showSidebar();
else if (xDiff < 0 && curX < 300) hideSidebar();
firstContact = null;
}
},
{ passive: true }
);
// Scroll sidebar to current active section
var activeSection = sidebar.querySelector(".active");
if (activeSection) {
sidebar.scrollTop = activeSection.offsetTop;
}
})();
(function chapterNavigation() {
document.addEventListener("keydown", function(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
return;
}
if (window.search && window.search.hasFocus()) {
return;
}
switch (e.key) {
case "ArrowRight":
e.preventDefault();
var nextButton = document.querySelector(".nav-chapters.next");
if (nextButton) {
window.location.href = nextButton.href;
}
break;
case "ArrowLeft":
e.preventDefault();
var previousButton = document.querySelector(".nav-chapters.previous");
if (previousButton) {
window.location.href = previousButton.href;
}
break;
}
});
})();
(function clipboard() {
var clipButtons = document.querySelectorAll(".clip-button");
function hideTooltip(elem) {
elem.firstChild.innerText = "";
elem.className = "fa fa-copy clip-button";
}
function showTooltip(elem, msg) {
elem.firstChild.innerText = msg;
elem.className = "fa fa-copy tooltipped";
}
var clipboardSnippets = new ClipboardJS(".clip-button", {
text: function(trigger) {
hideTooltip(trigger);
let playpen = trigger.closest("pre");
return playpen_text(playpen);
}
});
Array.from(clipButtons).forEach(function(clipButton) {
clipButton.addEventListener("mouseout", function(e) {
hideTooltip(e.currentTarget);
});
});
clipboardSnippets.on("success", function(e) {
e.clearSelection();
showTooltip(e.trigger, "Copied!");
});
clipboardSnippets.on("error", function(e) {
showTooltip(e.trigger, "Clipboard error!");
});
})();
(function scrollToTop() {
var menuTitle = document.querySelector(".menu-title");
menuTitle.addEventListener("click", function() {
document.scrollingElement.scrollTo({ top: 0, behavior: "smooth" });
});
})();
(function autoHideMenu() {
var menu = document.getElementById("menu-bar");
var previousScrollTop = document.scrollingElement.scrollTop;
document.addEventListener(
"scroll",
function() {
if (
menu.classList.contains("folded") &&
document.scrollingElement.scrollTop < previousScrollTop
) {
menu.classList.remove("folded");
} else if (
!menu.classList.contains("folded") &&
document.scrollingElement.scrollTop > previousScrollTop
) {
menu.classList.add("folded");
}
if (
!menu.classList.contains("bordered") &&
document.scrollingElement.scrollTop > 0
) {
menu.classList.add("bordered");
}
if (
menu.classList.contains("bordered") &&
document.scrollingElement.scrollTop === 0
) {
menu.classList.remove("bordered");
}
previousScrollTop = document.scrollingElement.scrollTop;
},
{ passive: true }
);
})();