为 Chromium 浏览器加入书签和持久历史
This commit is contained in:
1 parent
c27ad52dab
commit
ae04cc9494
9 files changed
+200
-6
No files matched your search
@@ -5,6 +5,34 @@ const status = document.querySelector('#status')
|
||||
const button = (action) => document.querySelector(`[data-action="${action}"]`)
|
||||
let current
|
||||
|
||||
function renderEntries(selector, entries, removable) {
|
||||
const container = document.querySelector(selector)
|
||||
const rows = entries.map((entry) => {
|
||||
const row = document.createElement('li')
|
||||
const open = document.createElement('button')
|
||||
const title = document.createElement('strong')
|
||||
const url = document.createElement('span')
|
||||
title.textContent = entry.title || entry.url
|
||||
url.textContent = entry.url
|
||||
open.append(title, url)
|
||||
open.onclick = () => void command('openEntry', entry.id)
|
||||
row.append(open)
|
||||
if (removable) {
|
||||
const remove = document.createElement('button')
|
||||
remove.textContent = '移除'
|
||||
remove.onclick = () => void command('removeBookmark', entry.id)
|
||||
row.append(remove)
|
||||
}
|
||||
return row
|
||||
})
|
||||
if (!rows.length) {
|
||||
const empty = document.createElement('li')
|
||||
empty.textContent = removable ? '暂无书签' : '暂无历史记录'
|
||||
rows.push(empty)
|
||||
}
|
||||
container.replaceChildren(...rows)
|
||||
}
|
||||
|
||||
function render(state) {
|
||||
current = state
|
||||
tabs.replaceChildren(...state.tabs.map((tab) => {
|
||||
@@ -28,6 +56,16 @@ function render(state) {
|
||||
button('reload').setAttribute('aria-label', state.loading ? '停止加载' : '刷新')
|
||||
for (const action of ['copy', 'external', 'zoomIn', 'zoomOut']) button(action).disabled = !state.url
|
||||
document.querySelector('#mode').textContent = state.privateMode ? '隐私窗口' : ''
|
||||
button('bookmark').hidden = state.privateMode
|
||||
button('bookmark').disabled = !state.url
|
||||
button('bookmark').textContent = state.bookmarked ? '取消书签' : '添加书签'
|
||||
button('library').hidden = state.privateMode
|
||||
button('library').setAttribute('aria-pressed', String(state.libraryMode))
|
||||
document.querySelector('#library').hidden = !state.libraryMode
|
||||
if (state.libraryMode) {
|
||||
renderEntries('#bookmarks', state.bookmarks, true)
|
||||
renderEntries('#history', state.history, false)
|
||||
}
|
||||
status.textContent = state.error
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user