File size: 1,688 Bytes
5c81d48
 
 
 
195a929
 
 
 
 
 
 
 
 
 
 
 
5c81d48
 
 
 
 
 
195a929
 
5c81d48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195a929
5c81d48
 
195a929
 
5c81d48
 
 
195a929
 
5c81d48
 
 
 
195a929
5c81d48
 
 
 
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
# app.py

import streamlit as st

def escape_for_template(text: str) -> str:
    """
    Escape backticks and `${…}` so the content
    bisa dimasukkan mentah ke dalam JS template literal.
    """
    # escape backslash dulu agar hasil replace nggak kacau
    text = text.replace("\\", "\\\\")
    # escape backtick
    text = text.replace("`", "\\`")
    # escape ${ so JS gak nge-evaluate sebagai placeholder
    text = text.replace("${", "\\${")
    return text

st.set_page_config(page_title="CF Worker Escaper")
st.title("🔧 Cloudflare Worker Escaper")

st.markdown(
    """
    Upload **index.html** dan **script.js**,  
    nanti akan keluar:
    ```js
    const html = `...escaped-html...`;
    const script = `...escaped-js...`;
    ```
    siap copy–paste ke `worker.js`.
    """
)

uploaded_html = st.file_uploader("📄 Upload index.html", type=["html","htm"])
uploaded_js   = st.file_uploader("📄 Upload script.js",   type=["js"])

if uploaded_html and uploaded_js:
    try:
        html_text = uploaded_html.read().decode("utf-8")
        js_text   = uploaded_js.read().decode("utf-8")
    except UnicodeDecodeError:
        st.error("Gagal decode file. Pastikan UTF-8.")
        st.stop()

    esc_html = escape_for_template(html_text)
    esc_js   = escape_for_template(js_text)

    st.subheader("▶️ Generated Constants")
    const_block = (
        f"const html = `{esc_html}`;\n\n"
        f"const script = `{esc_js}`;\n"
    )
    st.code(const_block, language="javascript")

    st.download_button(
        "💾 Download as escaped_constants.js",
        const_block,
        file_name="escaped_constants.js",
        mime="application/javascript"
    )