[feature] use url query to set username

Signed-off-by: zhangtianli2006 <zhangtianli2006@163.com>
This commit is contained in:
zhangtianli2006 2021-08-25 20:25:55 +08:00
parent 2c68db82b3
commit 580118bac2

View File

@ -204,8 +204,25 @@ function open_prompt(title) {
return res; return res;
} }
async function get_url_query(query_name) {
return new Promise(resolve => {
var reg = new RegExp("(^|&)" + query_name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
var context = "";
if (r != null)
context = r[2];
reg = null;
r = null;
resolve(context == null || context == "" || context == "undefined" ? "" : context);
});
}
async function login_name() { async function login_name() {
username = await open_prompt('[Login] Input your name'); username = await get_url_query("name")
if (username === undefined || username.length == 0) {
username = await open_prompt('[Login] Input your name');
}
} }
async function send() { async function send() {
@ -259,7 +276,7 @@ document.addEventListener('keydown', async function (key_event) {
} }
}); });
document.addEventListener("visibilitychange", function() { document.addEventListener("visibilitychange", function () {
if (document.visibilityState === 'visible') { unread_message = 0; } if (document.visibilityState === 'visible') { unread_message = 0; }
$('title').text(`WebSocket Chat Room`); $('title').text(`WebSocket Chat Room`);
}); });