summaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'index.js')
-rw-r--r--index.js33
1 files changed, 21 insertions, 12 deletions
diff --git a/index.js b/index.js
index ece19ee..ee4c011 100644
--- a/index.js
+++ b/index.js
@@ -32,7 +32,6 @@ const copy = modal.querySelector('#copy')
32const link = modal.querySelector('#link a') 32const link = modal.querySelector('#link a')
33link.onclick = e => e.stopPropagation() 33link.onclick = e => e.stopPropagation()
34function modalForLink (a) { 34function 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}
45const copyLink = (ele) => { 44const 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 {{{
171new window.MutationObserver(ms => { 170new 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})
190const path = decodeURIComponent(window.location.pathname.split('/')[1])
191const 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
191const hash = decodeURIComponent(window.location.hash.replace(/^#/, '')) 199const hash = decodeURIComponent(window.location.hash.replace(/^#/, ''))
192if (hash) { 200let moveTo
193 const target = [ 201moveTo = 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
209moveTo?.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