Skip to content

Commit

Permalink
fix url with hashes
Browse files Browse the repository at this point in the history
closes #76
  • Loading branch information
pldubouilh committed Jul 8, 2023
1 parent a342c79 commit 9de04f2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ui/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const prependPath = a => a.startsWith('/') ? a : decodeURI(location.pathname) +
const prevent = e => e.preventDefault()
const flicker = w => w.classList.remove('runFade') || void w.offsetWidth || w.classList.add('runFade')

const encodeURIHash = e => encodeURI(e).replaceAll("#", "%23")

// Manual upload
manualUpload.addEventListener('change', () => Array.from(manualUpload.files).forEach(f => isDupe(f.name) || postFile(f, '/' + f.name)), false)

Expand All @@ -56,7 +58,8 @@ async function browseTo (href, flickerDone, skipHistory) {
// check if is current path - if so skip following
if (pageTitle.innerText !== title) {
if (!skipHistory) {
history.pushState({}, '', encodeURI(window.extraPath + title))
const escaped = encodeURIHash(window.extraPath + title)
history.pushState({}, '', escaped)
}
pageTitle.innerText = title
pageH1.innerText = '.' + title
Expand Down Expand Up @@ -113,7 +116,7 @@ let softStatePushed
function pushSoftState (d) {
if (softStatePushed) { return }
softStatePushed = true
history.pushState({}, '', encodeURI(d))
history.pushState({}, '', encodeURIHash(d))
}

const refresh = () => browseTo(location.href, true)
Expand Down Expand Up @@ -228,7 +231,7 @@ window.titleClick = function (e) {
const p = Array.from(document.querySelector('h1').childNodes).map(k => k.innerText)
const i = p.findIndex(s => s === e.target.innerText)
const dst = p.slice(0, i + 1).join('').slice(1)
const target = location.origin + window.extraPath + encodeURI(dst)
const target = location.origin + window.extraPath + encodeURIHash(dst)
browseTo(target, false)
}

Expand Down Expand Up @@ -522,7 +525,7 @@ function setImage () {
picsHolder.src = src
const name = src.split('/').pop()
setCursorTo(decodeURI(name))
history.replaceState({}, '', encodeURI(name))
history.replaceState({}, '', encodeURIHash(name))
}

function picsOn (href) {
Expand Down

0 comments on commit 9de04f2

Please sign in to comment.