-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·50 lines (44 loc) · 1.37 KB
/
build.sh
File metadata and controls
executable file
·50 lines (44 loc) · 1.37 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
if [ -f "build/index.html" ]; then
python3 << 'EOF'
with open('build/index.html', 'r') as f:
content = f.read()
script = '''
<script>
(function() {
function scrollToTop() {
window.addEventListener('click', function(e) {
const btn = e.target.closest('button[aria-label="Scroll to top"]');
if (!btn) return;
e.stopImmediatePropagation();
e.preventDefault();
const scrollContainer = [...document.querySelectorAll('*')].find(el => {
const s = getComputedStyle(el);
return el.scrollTop > 0 ||
((s.overflow === 'auto' || s.overflow === 'scroll' ||
s.overflowY === 'auto' || s.overflowY === 'scroll') &&
el.scrollHeight > el.clientHeight && !el.className);
});
if (scrollContainer) {
scrollContainer.scrollTo({ top: 0, behavior: 'smooth' });
} else {
window.scrollTo({ top: 0, behavior: 'smooth' });
}
}, true);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', scrollToTop);
} else {
scrollToTop();
}
})();
</script>
'''
if '</body>' in content:
content = content.replace('</body>', script + '\n</body>')
with open('build/index.html', 'w') as f:
f.write(content)
print("Smooth scroll script injected successfully")
else:
print("Warning: </body> tag not found in index.html")
EOF
fi