import streamlit as st import streamlit_ace as ace import base64 import os import time def get_clipboard_html(): script_path = os.path.abspath(__file__) script_dir = os.path.dirname(script_path) clipboard_path = os.path.join(script_dir, "clipboard.html") with open(clipboard_path, "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'', unsafe_allow_html=True) # Set up session state if "last_clipboard" not in st.session_state: st.session_state.last_clipboard = "" while 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") if clipboard_text != st.session_state.last_clipboard: st.session_state.last_clipboard = clipboard_text 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}") time.sleep(1) st.experimental_rerun() if __name__ == "__main__": main()