Add "server" query parameter

This commit is contained in:
Simon Ser 2020-06-07 12:31:01 +02:00
parent 3612dd3e63
commit deb82c7abe
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
2 changed files with 25 additions and 4 deletions

View file

@ -330,6 +330,19 @@ function setConnectFormDisabled(disabled) {
});
}
function parseQueryString() {
var query = window.location.search.substring(1);
var params = {};
query.split('&').forEach(function(s) {
if (!s) {
return;
}
var pair = s.split('=');
params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || "");
});
return params;
}
connectFormElt.onsubmit = function(event) {
event.preventDefault();
setConnectFormDisabled(true);
@ -374,4 +387,10 @@ if (localStorage && localStorage.getItem("server")) {
connectFormElt.elements["remember-me"].checked = true;
setConnectFormDisabled(true);
connect();
} else {
var params = parseQueryString();
if (params.server) {
connectFormElt.elements.url.value = params.server;
document.querySelector("#connect-url-container").style.display = "none";
}
}

View file

@ -26,9 +26,11 @@
<form>
<h2>Connect to IRC</h2>
<label for="connect-url">Server URL:</label><br/>
<input type="url" name="url" id="connect-url" value="ws://localhost:8080"/>
<br/><br/>
<div id="connect-url-container">
<label for="connect-url">Server URL:</label><br/>
<input type="url" name="url" id="connect-url" value="ws://localhost:8080"/>
<br/><br/>
</div>
<label for="connect-nick">Nickname:</label><br/>
<input type="username" name="nick" id="connect-nick" autofocus required/>
@ -43,7 +45,7 @@
<br/><br/>
<details>
<summary>More options</summary>
<summary>Advanced options</summary>
<br/>