sunny
bedtime
volume_up
volume_off
delete_forever
Username Generator
Loading Python...
import random
from js import document, navigator, setTimeout
from pyodide.ffi import create_once_callable
from pyodide.http import open_url
# LOADING SCREEN
document.getElementById("loading-message").style.display = "none"
# LOADING WORDS
def words(file):
text = open_url(file).read()
return [line.strip().capitalize() for line in text.splitlines() if line.strip()]
adjectives = words("data/english-adjectives.txt")
nouns = words("data/english-nouns.txt")
# USERNAME GENERATOR
def generate(event=None):
adj = random.choice(adjectives)
noun = random.choice(nouns)
username = f"{adj}{noun}"
document.getElementById("username").value = username
# COPY TO CLIPBOARD
def copy(event=None):
username = document.getElementById("username").value
if username:
try:
navigator.clipboard.writeText(username)
msg = document.getElementById("copy-message")
msg.textContent = "Copied!"
except Exception as e:
msg = document.getElementById("copy-message")
msg.textContent = "Copy failed."
print(f"Clipboard error: {e}")
clear = create_once_callable(lambda: setattr(msg, "textContent", ""))
setTimeout(clear, 1500)
# BUTTONS
document.getElementById("generate-btn").onclick = generate
document.getElementById("copy-btn").onclick = copy