From 84104a4238cdf61855dd04e53f125a0dd04b9b77 Mon Sep 17 00:00:00 2001 From: maxpozdeev Date: Fri, 8 Sep 2023 15:18:46 +0300 Subject: [PATCH] * do not change browser history when switching between tabs --- src/content/mytinytodo.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/content/mytinytodo.js b/src/content/mytinytodo.js index 6211e24..c3b67ad 100644 --- a/src/content/mytinytodo.js +++ b/src/content/mytinytodo.js @@ -1186,15 +1186,10 @@ function loadTasks(opts) function prepareListHtml(list, isSelected) { - const selected = isSelected ? ' mtt-tab-selected' : ''; - let opentag = ''; - if (list.id == -1) { - opentag = '
  • '; - } - else { - opentag = '
  • '; - } - return opentag + + const classSelected = isSelected ? 'mtt-tab-selected' : ''; + const classHidden = list.hidden ? 'mtt-tab-hidden' : ''; + const liId = list.id == -1 ? 'list_all' : 'list_' + list.id; + return `
  • ` + ''+ '
    '+ '' + list.name + '
    ' + @@ -1575,12 +1570,12 @@ function toggleAllNotes(show, event) function tabSelect(elementOrId) { - var id; + let id; if (typeof elementOrId == 'number') id = elementOrId; else if(typeof elementOrId == 'string') id = parseInt(elementOrId); else { id = $(elementOrId).attr('id'); - if (!id ) return; + if (!id) return; id = id.split('_', 2)[1]; if (id === 'all') id = -1; } @@ -1602,7 +1597,7 @@ function tabSelect(elementOrId) $('#lists .mtt-tab-selected').removeClass('mtt-tab-selected'); - if(id == -1) { + if (id == -1) { $('#list_all').addClass('mtt-tab-selected').removeClass('mtt-tab-hidden'); $('#listmenucontainer .mtt-need-real-list').addClass('mtt-item-hidden'); } @@ -1617,9 +1612,9 @@ function tabSelect(elementOrId) if (filter.search != '') liveSearchToggle(0, 1); mytinytodo.doAction('listSelected', tabLists.get(id)); } - var newTitle = curList.name + ' - ' + _mtt.options.title; - var isFirstLoad = flag.firstLoad; - updateHistoryState( { list:id }, _mtt.urlForList(curList), newTitle ); + const newTitle = curList.name + ' - ' + _mtt.options.title; + const isFirstLoad = flag.firstLoad; + replaceHistoryState( { list:id }, _mtt.urlForList(curList), newTitle ); if (!flag.readOnly) { setLocalStorageItem('lastList', ''+id); } @@ -3150,6 +3145,20 @@ function updateHistoryState(state, url, title) document.title = title; } +function replaceHistoryState(_state, url, title) +{ + if (!_mtt.options.history) { + document.title = title; + return; + } + const state = window.history.state; + if (state && state.list) { + window.history.replaceState(_state, title, url); + } + else { + updateHistoryState(_state, url, title); + } +} function historyOnPopState(event) {