diff --git a/chat/static/chat.js b/chat/static/chat.js index c4b8ab9..50e9e1b 100644 --- a/chat/static/chat.js +++ b/chat/static/chat.js @@ -33,8 +33,7 @@ function selectChannel(channel_id) { } selected_channel_id = channel_id - - window.history.replaceState({}, null, `#channel-${channel['id']}`) + localStorage.setItem('chat.last-channel-id', channel_id) let channelTitle = document.getElementById('channel-title') channelTitle.innerText = channel['name'] @@ -74,13 +73,9 @@ function setChannels(new_channels) { addChannel(channel, categoryLists) if (new_channels && (!selected_channel_id || !channels[selected_channel_id])) { - if (window.location.hash) { - let channel_id = parseInt(window.location.hash.substring(9)) - if (channels[channel_id]) - selectChannel(channel_id) - else - selectChannel(Object.keys(channels)[0]) - } + let last_channel_id = parseInt(localStorage.getItem('chat.last-channel-id')) + if (last_channel_id && channels[last_channel_id]) + selectChannel(last_channel_id) else selectChannel(Object.keys(channels)[0]) } @@ -387,12 +382,12 @@ function toggleFullscreen() { if (!chatContainer.getAttribute('data-fullscreen')) { chatContainer.setAttribute('data-fullscreen', 'true') chatContainer.classList.add('position-absolute', 'top-0', 'start-0', 'vh-100', 'z-3') - window.history.replaceState({}, null, `?fullscreen=1#channel-${selected_channel_id}`) + window.history.replaceState({}, null, `?fullscreen=1`) } else { chatContainer.removeAttribute('data-fullscreen') chatContainer.classList.remove('position-absolute', 'top-0', 'start-0', 'vh-100', 'z-3') - window.history.replaceState({}, null, `?fullscreen=0#channel-${selected_channel_id}`) + window.history.replaceState({}, null, `?fullscreen=0`) } }