diff --git a/js/tkm-onload.js b/js/tkm-onload.js index 082ef9b..219c3e8 100644 --- a/js/tkm-onload.js +++ b/js/tkm-onload.js @@ -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 = '名前'; + nameLabel.appendChild(uidInput); + form.appendChild(nameLabel); + + var tripLabel = document.createElement('label'); + tripLabel.htmlFor = 'login-input-trip-key'; + tripLabel.innerHTML = 'トリップキー'; + + 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 !== '' @@ -154,7 +218,7 @@ window.onload = function () { } if(document.getElementById('isAuth')) { - document.getElementById('isAuth').innerHTML = `

認証卓の使い方

  1. [ユーザー名#password]の形でログインしてください。
  2. ログイン後チャットに[/grant]と入力して管理者権限を取得してください。
  3. 他のユーザーは管理者と同じパスワードを使ってログインできます。
` + document.getElementById('isAuth').innerHTML = `

認証卓の使い方

  1. 名前欄にユーザー名、トリップキー欄に合言葉を入力してログインしてください。
  2. ログイン後チャットに[/grant]と入力して管理者権限を取得してください。
  3. 他のユーザーは管理者と同じトリップキーを使ってログインできます。
` } document.getElementById('play-select-volume').selectedIndex = 2; @@ -287,4 +351,4 @@ window.onload = function () { Tkm.ws.send(String.fromCharCode(200)); }, 5000 ); -} \ No newline at end of file +}