Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 70 additions & 6 deletions js/tkm-onload.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,77 @@ window.onload = function () {
Tkm.log = document.getElementById('log-view').contentWindow;
}

document.getElementById('login-button').onclick = function () {
var uid = document.getElementById('login-input-uid').value;
Tkm.view.loginName = uid;
var setupLoginForm = function () {
var loginLeft = document.getElementById('login-left');
var uidInput = document.getElementById('login-input-uid');
var loginButton = document.getElementById('login-button');

if (!loginLeft || !uidInput || !loginButton) { return; }

uidInput.placeholder = '名前(半角英数12字以内)';
uidInput.setAttribute('autocomplete', 'nickname');

var tripInput = document.getElementById('login-input-trip-key');
var form = document.getElementById('login-form');

if (!form) {
form = document.createElement('form');
form.id = 'login-form';
form.setAttribute('autocomplete', 'off');
loginLeft.insertBefore(form, uidInput);

var nameLabel = document.createElement('label');
nameLabel.htmlFor = 'login-input-uid';
nameLabel.innerHTML = '<span>名前</span>';
nameLabel.appendChild(uidInput);
form.appendChild(nameLabel);

var tripLabel = document.createElement('label');
tripLabel.htmlFor = 'login-input-trip-key';
tripLabel.innerHTML = '<span>トリップキー</span>';

tripInput = document.createElement('input');
tripInput.id = 'login-input-trip-key';
tripInput.type = 'password';
tripInput.placeholder = '任意。本人確認用の合言葉';
tripInput.setAttribute('autocomplete', 'current-password');
tripLabel.appendChild(tripInput);
form.appendChild(tripLabel);

form.appendChild(loginButton);

var description = document.createElement('div');
description.id = 'login-description';
description.innerHTML = 'トリップキーを入れると、名前の後ろに本人確認用の印が付きます。空欄でも入室できます。以前の「名前#キー」形式も当面そのまま使えます。';
form.appendChild(description);
}

var submitLogin = function () {
var uid = uidInput.value.replace(/^\s+|\s+$/g, '');
var tripKey = tripInput ? tripInput.value : '';
var payload;

if (uid === '') { return false; }

if (uid !== '') { Tkm.send('b' + uid); }
if (uid.indexOf('#') !== -1) {
payload = uid;
} else if (tripKey !== '') {
payload = uid + '#' + tripKey;
} else {
payload = uid;
}

Tkm.view.loginName = payload;
Tkm.send('b' + payload);
return false;
}

form.onsubmit = submitLogin;
loginButton.onclick = submitLogin;
}

setupLoginForm();

document.getElementById('play-input-chat').onkeypress = function (event) {
if (
this.value !== ''
Expand Down Expand Up @@ -154,7 +218,7 @@ window.onload = function () {
}

if(document.getElementById('isAuth')) {
document.getElementById('isAuth').innerHTML = `<h3>認証卓の使い方</h3><ol><li>[ユーザー名#password]の形でログインしてください。</li><li>ログイン後チャットに[/grant]と入力して管理者権限を取得してください。</li><li>他のユーザーは管理者と同じパスワードを使ってログインできます。</li></ol>`
document.getElementById('isAuth').innerHTML = `<h3>認証卓の使い方</h3><ol><li>名前欄にユーザー名、トリップキー欄に合言葉を入力してログインしてください。</li><li>ログイン後チャットに[/grant]と入力して管理者権限を取得してください。</li><li>他のユーザーは管理者と同じトリップキーを使ってログインできます。</li></ol>`
}

document.getElementById('play-select-volume').selectedIndex = 2;
Expand Down Expand Up @@ -287,4 +351,4 @@ window.onload = function () {
Tkm.ws.send(String.fromCharCode(200));
}, 5000
);
}
}