File size: 1,412 Bytes
457bc51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import base64
from io import StringIO

def get_clipboard_html():
    with open("clipboard.html", "r") as f:
        content = f.read()
        b64 = base64.b64encode(content.encode()).decode()
        return f"data:text/html;base64,{b64}"

def main():
    st.title("Clipboard Monitor")

    st.write("Paste your data in the input box below:")

    clipboard_data = st.empty()
    data_type = st.empty()
    data_contents = st.empty()

    st.write(f'<iframe src="{get_clipboard_html()}" width="100%" height="300" style="border:none"></iframe>', unsafe_allow_html=True)

    event = st.experimental_get_query_params().get("event", [None])[0]
    if event == "clipboard-update":
        st.experimental_set_query_params(event="")
        clipboard_text = st.experimental_get_query_params().get("data", [""])[0]
        clipboard_text = base64.urlsafe_b64decode(clipboard_text).decode(errors="ignore")
        clipboard_data.write(f"Clipboard Data: {clipboard_text}")

        if clipboard_text.startswith("{") and clipboard_text.endswith("}"):
            data_type.write("Data Type: JSON")
        elif clipboard_text.startswith("<") and clipboard_text.endswith(">"):
            data_type.write("Data Type: XML/HTML")
        else:
            data_type.write("Data Type: Plain Text")

        data_contents.write(f"Data Contents: {clipboard_text}")

if __name__ == "__main__":
    main()