Refactor streak modal to overlay native React component on transparent celebration canvas iframe
This commit is contained in:
47
scratch/port_streak_clean.py
Normal file
47
scratch/port_streak_clean.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
def port_html():
|
||||
source_path = r"C:\Users\naman\OneDrive\Desktop\pragativeer-v2\pragativeer-celebration_1.html"
|
||||
dest_path = r"C:\Users\naman\OneDrive\Desktop\pragativeer-v2\public\streak-animation.html"
|
||||
|
||||
with open(source_path, 'r', encoding='utf-8') as f:
|
||||
html = f.read()
|
||||
|
||||
# 1. Inject CSS to make background transparent and hide stage layout
|
||||
hide_css = """
|
||||
body {
|
||||
background: transparent !important;
|
||||
}
|
||||
body.sad {
|
||||
background: transparent !important;
|
||||
}
|
||||
body::after {
|
||||
display: none !important;
|
||||
}
|
||||
#stage, .hint {
|
||||
display: none !important;
|
||||
}
|
||||
"""
|
||||
|
||||
# Insert hide_css inside <style>
|
||||
style_tag = "</style>"
|
||||
html = html.replace(style_tag, hide_css + "\n</style>", 1)
|
||||
|
||||
# 2. Replace parseTarget to read from URL search params
|
||||
parse_target_replacement = """
|
||||
const parseTarget=()=>{
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const s = params.get('streak');
|
||||
const v=parseFloat(s);
|
||||
return isFinite(v)?v:0;
|
||||
};
|
||||
"""
|
||||
html = re.sub(r"const parseTarget=\(\)=>\{.*?\};", parse_target_replacement, html, flags=re.DOTALL)
|
||||
|
||||
with open(dest_path, 'w', encoding='utf-8') as f:
|
||||
f.write(html)
|
||||
print("Ported successfully to public/streak-animation.html")
|
||||
|
||||
if __name__ == "__main__":
|
||||
port_html()
|
||||
Reference in New Issue
Block a user