Spaces:
Sleeping
Sleeping
Download templates/app.html from Arcader7171/InterState: direct link, hf CLI and curl.
- Browser
- Download file 4.24 kB
-
https://huggingface.co/spaces/Arcader7171/InterState/resolve/main/templates/app.html
- Command line
-
hf download hf://spaces/Arcader7171/InterState/templates/app.html
-
curl -L -o app.html https://huggingface.co/spaces/Arcader7171/InterState/resolve/main/templates/app.html
4.24 kB
| <html> | |
| <head> | |
| <title>Inter</title> | |
| <link href="/static/styles/app.css" rel="stylesheet"> | |
| <script src="/static/scripts/app.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script> | |
| </head> | |
| <body> | |
| <div id="page"> | |
| <div id="servers"></div> | |
| <div id="channels"></div> | |
| <div id="chat"> | |
| <div id="zone"> | |
| {% for msg in history %} | |
| {% if msg.local %} | |
| <div class="R-Local MSG-Row"> | |
| <p class="UL-Local UserLabel">{{ msg.user }}</p> | |
| <p class="M-Local Message">{{ msg.message }}</p> | |
| </div> | |
| {% elif not msg.local %} | |
| <div class="MSG-Row"> | |
| <p class="UserLabel">{{ msg.user }}</p> | |
| <p class="Message">{{ msg.message }}</p> | |
| </div> | |
| {% endif %} | |
| {% endfor %} | |
| </div> | |
| <div class="input"> | |
| <input id="inputText" placeholder="Message"/> | |
| </div> | |
| </div> | |
| <div id="users"></div> | |
| </div> | |
| <script type="text/javascript" charset="utf-8"> | |
| let log_events = true; // you can turn this on, it won't change anything, other than log everything in the console. Debugging purposes | |
| let user = "{{ session['username'] }}"; | |
| let latest_msg_id = {{ latestID }}; | |
| let socket = io() | |
| socket.on('connect', function() { | |
| if (log_events == true) { | |
| console.log("Socket connected to server"); | |
| } | |
| }); | |
| socket.on('msg', function(data) { | |
| if (data.author == user) { | |
| return; | |
| } | |
| if (log_events === true) { | |
| console.log("New message received!"); | |
| } | |
| addMsg2View(data); | |
| }) | |
| document.addEventListener("DOMContentLoaded",(event) => { | |
| document.addEventListener("keydown", (event) => { | |
| if (event.key == "Enter") { | |
| let input = document.getElementById("inputText"); | |
| if (input.value == "") { | |
| return; | |
| } | |
| sendMessage(input.value); | |
| } | |
| }) | |
| }) | |
| function checkForMessage(payload) { // I don't trust you losers with something like message data, You just get to check with an api lmao | |
| return; | |
| } | |
| function sendMessage(msgContent) { | |
| let heads = new Headers(); | |
| let creds = window.btoa("{{ session['username'] }}" + ":" + "{{ session['password'] }}"); | |
| heads.append("Authorization", `Basic ${creds}`); | |
| heads.append("Content-Type", "application/json"); | |
| fetch("/api/messages", { | |
| method: "POST", | |
| headers: heads, | |
| body: JSON.stringify({ content: msgContent }) | |
| }) | |
| .then(response => { | |
| if (!response.ok) { | |
| throw new Error("Response did not return ok"); | |
| } | |
| return response.json(); | |
| }) | |
| .then((response) => { | |
| addMsg2View(response); | |
| }) | |
| .catch(error => { | |
| console.error("Error - ", error.message); | |
| }) | |
| } | |
| function addMsg2View(data) { | |
| let author = data.author; | |
| let content = data.content; | |
| let local = data.local; | |
| let id = data.id; | |
| if (id > latest_msg_id) { | |
| latest_msg_id = id; | |
| } | |
| let row = document.createElement("div"); | |
| let authorTxt = document.createElement("p"); | |
| let contentTxt = document.createElement("p"); | |
| let zone = document.getElementById("zone") | |
| row.classList.add("MSG-Row"); | |
| authorTxt.classList.add("UserLabel"); | |
| contentTxt.classList.add("Message"); | |
| if (local == true) { | |
| row.classList.add("R-Local"); | |
| authorTxt.classList.add("UL-Local"); | |
| contentTxt.classList.add("M-Local"); | |
| } | |
| authorTxt.textContent = author; | |
| contentTxt.textContent = content; | |
| row.appendChild(authorTxt); | |
| row.appendChild(contentTxt); | |
| zone.appendChild(row); | |
| } | |
| </script> | |
| </body> | |
| </html> |