diff --git a/js/client-battle.js b/js/client-battle.js index ef582e1ec..5ec16db68 100644 --- a/js/client-battle.js +++ b/js/client-battle.js @@ -98,6 +98,7 @@ if (log.length && log[0].substr(0, 7) === '|title|') { this.title = log[0].substr(7); log.shift(); + app.roomTitleChanged(this); } if (this.battle.activityQueue.length) return; this.battle.activityQueue = log; @@ -150,6 +151,7 @@ } } else if (logLine.substr(0, 7) === '|title|') { this.title = logLine.substr(7); + app.roomTitleChanged(this); } else if (logLine.substr(0, 6) === '|chat|' || logLine.substr(0, 3) === '|c|' || logLine.substr(0, 9) === '|chatmsg|' || logLine.substr(0, 10) === '|inactive|') { this.battle.instantAdd(logLine); } else { diff --git a/js/client-chat.js b/js/client-chat.js index e66d7ffb1..f2b2765f2 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -1105,6 +1105,7 @@ case 'title': this.title = row[1]; + app.roomTitleChanged(this); app.topbar.updateTabbar(); break; diff --git a/js/client.js b/js/client.js index 597469c93..5099c5814 100644 --- a/js/client.js +++ b/js/client.js @@ -859,9 +859,10 @@ if (location.search && window.history) { history.replaceState(null, null, '/'); } - fragment = toRoomid(fragment || ''); + this.fragment = fragment = toRoomid(fragment || ''); if (this.initialFragment === undefined) this.initialFragment = fragment; this.tryJoinRoom(fragment); + this.updateTitle(this.rooms[fragment]); }, /** * Send to sim server @@ -1389,7 +1390,11 @@ } this.curRoom = window.room = room; this.updateLayout(); - if (this.curRoom.id === id) this.navigate(id); + if (this.curRoom.id === id) { + this.fragment = id; + this.navigate(id); + this.updateTitle(this.curRoom); + } } room.focus(); @@ -1530,6 +1535,12 @@ return false; } }, + roomTitleChanged: function (room) { + if (room.id === this.fragment) updateTitle(room); + }, + updateTitle: function (room) { + document.title = room.title ? room.title + " - Showdown!" : "Showdown!"; + }, updateAutojoin: function () { if (Config.server.id !== 'showdown') return; var autojoins = [];