diff --git a/app/static/js/script.js b/app/static/js/script.js index 093ffd4c..adb9d6c9 100644 --- a/app/static/js/script.js +++ b/app/static/js/script.js @@ -854,44 +854,62 @@ async function ban() { // var text_val = str.substring(0, beg) + str.substring(end, len); // $(id_textarea).text(text_val); // } + +function initializeHistory() { + if (!localStorage.getItem('history')) { + localStorage.setItem('history', JSON.stringify(['/login', '/login', '/login'])); + } +} + function createHistory() { - if(localStorage.getItem('history') === null) { - let get_history_array = ['login', 'login','login']; - localStorage.setItem('history', JSON.stringify(get_history_array)); - } + const history = JSON.parse(localStorage.getItem('history')); + const currentPath = window.location.pathname.replace(/\/$/, ""); + const historyContainer = $('#browse_history'); + + const removeDuplicates = (arr) => { + const seen = {}; + return arr.filter(item => { + const normalized = item.replace(/\/$/, ""); + return seen.hasOwnProperty(normalized) ? false : (seen[normalized] = true); + }); + }; + + if (!history.some(path => path.replace(/\/$/, "") === currentPath)) { + let updatedHistory = [...history, currentPath]; + updatedHistory = removeDuplicates(updatedHistory); + + updatedHistory = updatedHistory.slice(-3); + + localStorage.setItem('history', JSON.stringify(updatedHistory)); + } + + historyContainer.empty(); + + const menuLinks = {}; + + $('.menu li ul li a').each(function() { + const path = $(this).attr('href').replace(/\/$/, ""); + menuLinks[path] = { + title: $(this).attr('title'), + text: $(this).text() + }; + }); + + JSON.parse(localStorage.getItem('history')).forEach(path => { + const cleanPath = path.replace(/\/$/, ""); + if (menuLinks[cleanPath]) { + const link = menuLinks[cleanPath]; + historyContainer.append( + `