Repository navigation
Expand file tree
/
Copy pathfix_app.py
More file actions
35 lines (31 loc) · 1.42 KB
/
Copy pathfix_app.py
File metadata and controls
35 lines (31 loc) · 1.42 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
import sys
filepath = 'js/app.js'
with open(filepath, 'r') as f:
lines = f.readlines()
# Part 1: DOM elements
for i, line in enumerate(lines):
if "themeMenu: document.getElementById('themeMenu')," in line:
lines.insert(i + 1, " episodesNavBtn: document.querySelector('[data-action=\"scroll-to-episodes\"]'),\n")
lines.insert(i + 2, " episodesSection: document.getElementById('episodesSection'),\n")
break
# Part 2: bindEvents
for i, line in enumerate(lines):
if "if (DOM.heroBtn) DOM.heroBtn.addEventListener('click'" in line:
scroll_listener = [
" // Navbar Episodes Scroll\n",
" if (DOM.episodesNavBtn && DOM.episodesSection) {\n",
" DOM.episodesNavBtn.addEventListener('click', () => {\n",
" DOM.episodesSection.scrollIntoView({ behavior: 'smooth' });\n",
" if (document.body.classList.contains('mobile-nav-active')) {\n",
" document.body.classList.remove('mobile-nav-active');\n",
" if (DOM.menuToggle) DOM.menuToggle.setAttribute('aria-expanded', 'false');\n",
" }\n",
" });\n",
" }\n",
"\n"
]
for idx, new_line in enumerate(scroll_listener):
lines.insert(i + idx, new_line)
break
with open(filepath, 'w') as f:
f.writelines(lines)