moved JS code to JS file
This commit is contained in:
parent
cfbf54410c
commit
45ee4acfdc
33
js/user.js
Normal file
33
js/user.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
async function setuser() {
|
||||||
|
let user = await (await fetch("/api/getuser")).json();
|
||||||
|
let username
|
||||||
|
let bio
|
||||||
|
username = user["username"];
|
||||||
|
bio = user["bio"]
|
||||||
|
if(user["error"])username=user["error"];
|
||||||
|
if(user["error"])bio=user["error"];
|
||||||
|
if(!bio)bio="wow such empty"
|
||||||
|
document.getElementById("user").innerText = `User: ${username}`;
|
||||||
|
document.getElementById("bio").placeholder = decodeURIComponent(atob(bio));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function bioChanger() {
|
||||||
|
document.getElementById("bio").disabled = !document.getElementById("bio").disabled
|
||||||
|
document.getElementById("changeBio").innerText = (document.getElementById("bio").disabled && "Change Bio") || "Submit"
|
||||||
|
if(document.getElementById("bio").disabled) {
|
||||||
|
document.querySelector('style').innerHTML = '::placeholder {color: white;} #bio {border: 0px solid black}'
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
document.querySelector('style').innerHTML = '::placeholder {color: black;} #bio {border: 2px solid gray}'
|
||||||
|
}
|
||||||
|
if(document.getElementById("bio").disabled) {
|
||||||
|
let response = await sendBio(document.getElementById("bio").value)
|
||||||
|
console.log(response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendBio(str) {
|
||||||
|
return await post("/api/setBio",{"Bio":str})
|
||||||
|
}
|
@ -8,6 +8,7 @@
|
|||||||
<link rel="stylesheet" href="/css/style.css">
|
<link rel="stylesheet" href="/css/style.css">
|
||||||
<link rel="stylesheet" href="/css/global.css">
|
<link rel="stylesheet" href="/css/global.css">
|
||||||
<script src="/js/httppost.js" charset="utf-8"></script>
|
<script src="/js/httppost.js" charset="utf-8"></script>
|
||||||
|
<script src="/js/user.js" charset="utf-8"></script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="setuser()">
|
<body onload="setuser()">
|
||||||
<ul class="navbar">
|
<ul class="navbar">
|
||||||
@ -30,41 +31,5 @@
|
|||||||
<button onclick="location.assign('/posts')">Want to chat with some cool fellas?</button>
|
<button onclick="location.assign('/posts')">Want to chat with some cool fellas?</button>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<script>
|
|
||||||
async function setuser() {
|
|
||||||
let user = await (await fetch("/api/getuser")).json();
|
|
||||||
let username
|
|
||||||
let bio
|
|
||||||
username = user["username"];
|
|
||||||
bio = user["bio"]
|
|
||||||
if(user["error"])username=user["error"];
|
|
||||||
if(user["error"])bio=user["error"];
|
|
||||||
if(!bio)bio="wow such empty"
|
|
||||||
document.getElementById("user").innerText = `User: ${username}`;
|
|
||||||
document.getElementById("bio").placeholder = decodeURIComponent(atob(bio));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
async function bioChanger() {
|
|
||||||
document.getElementById("bio").disabled = !document.getElementById("bio").disabled
|
|
||||||
document.getElementById("changeBio").innerText = (document.getElementById("bio").disabled && "Change Bio") || "Submit"
|
|
||||||
if(document.getElementById("bio").disabled) {
|
|
||||||
document.querySelector('style').innerHTML = '::placeholder {color: white;} #bio {border: 0px solid black}'
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
document.querySelector('style').innerHTML = '::placeholder {color: black;} #bio {border: 2px solid gray}'
|
|
||||||
}
|
|
||||||
if(document.getElementById("bio").disabled) {
|
|
||||||
let response = await sendBio(document.getElementById("bio").value)
|
|
||||||
console.log(response);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function sendBio(str) {
|
|
||||||
return await post("/api/setBio",{"Bio":str})
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user