import os import re base_dir = r'z:\source\forgejo\spotnotes.app\static\assets\js' index_path = os.path.join(base_dir, 'index.js') with open(index_path, 'r', encoding='utf-8') as f: content = f.read() # Remove the blocks that were moved to map.js and sidebar.js # initMap content = re.sub(r'function initMap\(\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # initSidebar content = re.sub(r'function initSidebar\(\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # renderMapMarkers content = re.sub(r'function renderMapMarkers\(\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # stopTracking content = re.sub(r'function stopTracking\(\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # updateTrackingUI content = re.sub(r'function updateTrackingUI\(\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # renderNotepadList content = re.sub(r'function renderNotepadList\(pads, containerId, isFavorite\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # setupPublicToggle content = re.sub(r'function setupPublicToggle\(\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # toggleSection content = re.sub(r'function toggleSection\(event\).*?^}', '', content, flags=re.MULTILINE | re.DOTALL) # Now, wrap the whole thing or replace globals # It's easier to rewrite index.js using a structured output or targeted regexes. # Let's replace the variable declarations: globals_to_replace = [ 'map', 'activeNotes', 'userLocation', 'activePadName', 'activePadId', 'activePadIsPublic', 'activePadOwnerId', 'activePadCanWrite', 'currentUser', 'isTracking', 'userMarker', 'notifiedNoteIds', 'isLoggedIn', 'currentMarkers', 'topZIndex' ] # Remove the var declarations for var in globals_to_replace: content = re.sub(r'let\s+' + var + r'\s*=[^;]+;\n?', '', content) # Prepend window.SpotNotes. to usages for var in globals_to_replace: # Use negative lookbehind/lookahead to avoid matching substring or properties if any content = re.sub(r'(?