File size: 1,208 Bytes
ad710e4
305d870
5492f08
ed64977
ad710e4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7b1d1b
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
from flask import Flask, request, redirect, url_for

app = Flask(__name__)

# In-memory storage for chat messages
messages = []

# --- Home page ---
@app.route('/', methods=['GET', 'POST'])
def index():
    global messages
    html = "<html><body>"
    html += "<h2>Simple Chat Share</h2>"

    if request.method == 'POST':
        text = request.form.get('text')
        if text:
            messages.append(text)
        return redirect(url_for('index'))

    # Chat input form
    html += "<form method='POST'>"
    html += "Message:<br>"
    html += "<input type='text' name='text' style='width:300px'>"
    html += "<input type='submit' value='Send'>"
    html += "</form><hr>"

    # Display messages with copy button
    html += "<h3>Messages:</h3>"
    for i, msg in enumerate(messages[::-1], 1):  # newest first
        # Using simple input box to allow easy copy/paste
        html += f"<p>{i}: <input type='text' value='{msg}' readonly style='width:300px'> <button onclick='this.previousElementSibling.select();document.execCommand(\"copy\");'>Copy</button></p>"

    html += "</body></html>"
    return html

# --- Run the app ---
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=7860)