diff options
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -32,7 +32,6 @@ const copy = modal.querySelector('#copy') | |||
32 | const link = modal.querySelector('#link a') | 32 | const link = modal.querySelector('#link a') |
33 | link.onclick = e => e.stopPropagation() | 33 | link.onclick = e => e.stopPropagation() |
34 | function modalForLink (a) { | 34 | function modalForLink (a) { |
35 | console.log('modal') | ||
36 | const url = a.href | 35 | const url = a.href |
37 | qrcode.innerHTML = '' | 36 | qrcode.innerHTML = '' |
38 | new QRCode(qrcode, url) | 37 | new QRCode(qrcode, url) |
@@ -43,7 +42,7 @@ function modalForLink (a) { | |||
43 | modal.showModal() | 42 | modal.showModal() |
44 | } | 43 | } |
45 | const copyLink = (ele) => { | 44 | const copyLink = (ele) => { |
46 | navigator.clipboard.writeText(link.href) | 45 | window.navigator.clipboard.writeText(link.href) |
47 | ele.textContent = '👌COPIED' | 46 | ele.textContent = '👌COPIED' |
48 | } | 47 | } |
49 | 48 | ||
@@ -167,7 +166,7 @@ detailsList.forEach(details => { | |||
167 | details.setAttribute('style', '') | 166 | details.setAttribute('style', '') |
168 | }) | 167 | }) |
169 | // }}} | 168 | // }}} |
170 | // Find content by hash {{{ | 169 | // Scroll to content by window.location {{{ |
171 | new window.MutationObserver(ms => { | 170 | new window.MutationObserver(ms => { |
172 | const target = ms[0].target | 171 | const target = ms[0].target |
173 | const details = target.closest('details') | 172 | const details = target.closest('details') |
@@ -188,16 +187,26 @@ new window.MutationObserver(ms => { | |||
188 | attributeFilter: ['focus'], | 187 | attributeFilter: ['focus'], |
189 | subtree: true, | 188 | subtree: true, |
190 | }) | 189 | }) |
190 | const path = decodeURIComponent(window.location.pathname.split('/')[1]) | ||
191 | const subject = path | ||
192 | ? [ | ||
193 | ...document.querySelectorAll('a'), | ||
194 | ...document.querySelectorAll('li'), | ||
195 | ...document.querySelectorAll('details'), | ||
196 | ] | ||
197 | .find(e => inlineText(e).includes(path)) | ||
198 | : null | ||
191 | const hash = decodeURIComponent(window.location.hash.replace(/^#/, '')) | 199 | const hash = decodeURIComponent(window.location.hash.replace(/^#/, '')) |
192 | if (hash) { | 200 | let moveTo |
193 | const target = [ | 201 | moveTo = hash |
194 | ...document.querySelectorAll('a'), | 202 | ? [ |
195 | ...document.querySelectorAll('li'), | 203 | ...(subject ?? document.body).querySelectorAll('a'), |
196 | ...document.querySelectorAll('details'), | 204 | ...(subject ?? document.body).querySelectorAll('li'), |
197 | ] | 205 | ...(subject ?? document.body).querySelectorAll('details'), |
198 | .find(e => inlineText(e).includes(hash) || e.title.includes(hash)) | 206 | ] |
199 | ?.setAttribute('focus', true) | 207 | .find(e => inlineText(e).includes(hash) || e.title.includes(hash)) |
200 | } | 208 | : subject |
209 | moveTo?.setAttribute('focus', true) | ||
201 | // }}} | 210 | // }}} |
202 | 211 | ||
203 | // vim:sw=2 ts=2 sts=2 expandtab foldmethod=marker foldtext&vim | 212 | // vim:sw=2 ts=2 sts=2 expandtab foldmethod=marker foldtext&vim |