From 54bd8c098701143fd1a2ea15fca782ea825f8a94 Mon Sep 17 00:00:00 2001 From: Pierre Dubouilh Date: Sat, 26 Jan 2019 17:23:06 +0100 Subject: [PATCH] really fix history --- src/script.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/script.js b/src/script.js index 6c97add..722f098 100755 --- a/src/script.js +++ b/src/script.js @@ -51,7 +51,7 @@ function browseTo (href) { if (document.head.querySelectorAll('title')[0].innerText !== title) { document.head.querySelectorAll('title')[0].innerText = title document.body.querySelectorAll('h1')[0].innerText = '.' + title - history.pushState({}, '', encodeURI(title)) + history.replaceState({}, '', encodeURI(title)) } init() @@ -70,8 +70,8 @@ window.onClickLink = e => { } const refresh = () => browseTo(location.href) || okBageFlicker() -const prevPage = () => picsOff() || browseTo(location.href + '../') -window.onpopstate = prevPage +const prevPage = (url) => picsOff() || browseTo(url || (location.href + '../')) +window.onpopstate = () => prevPage(location.href) // RPC function rpcFs (call, args, cb) { @@ -326,16 +326,12 @@ const isPic = src => src && picTypes.find(type => src.toLocaleLowerCase().includ const isPicMode = () => pics.style.display === 'flex' window.picsNav = () => picsNav(true) -function setImage (first) { +function setImage () { const src = allImgs[imgsIndex] picsHolder.src = src storeLastArrowSrc(src) restoreCursorPos() - if (first) { - history.pushState({}, '', encodeURI(src.split('/').pop())) - } else { - history.replaceState({}, '', encodeURI(src.split('/').pop())) - } + history.replaceState({}, '', encodeURI(src.split('/').pop())) } function picsOn (ifImgSelected, href) { @@ -349,7 +345,7 @@ function picsOn (ifImgSelected, href) { imgsIndex = allImgs.findIndex(el => el.includes(href)) } - setImage(true) + setImage() pics.style.display = 'flex' return true }