为 Chromium 浏览器加入书签和持久历史
This commit is contained in:
1 parent
c27ad52dab
commit
ae04cc9494
9 files changed
+200
-6
No files matched your search
@@ -9,7 +9,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<div class="tabs"><div id="tabs" aria-label="标签页"></div><button data-action="new" aria-label="新建标签页">+</button><span id="mode"></span></div>
|
||||
<div class="tabs"><div id="tabs" aria-label="标签页"></div><button data-action="new" aria-label="新建标签页">+</button><span id="mode"></span><button data-action="bookmark">添加书签</button><button data-action="library">书签与历史</button></div>
|
||||
<form id="address-form">
|
||||
<button type="button" data-action="back" aria-label="后退">←</button>
|
||||
<button type="button" data-action="forward" aria-label="前进">→</button>
|
||||
@@ -26,5 +26,9 @@
|
||||
</form>
|
||||
<div id="status" role="status"></div>
|
||||
</header>
|
||||
<main id="library" hidden>
|
||||
<section><h1>书签</h1><ul id="bookmarks"></ul></section>
|
||||
<section><h1>浏览历史</h1><ul id="history"></ul></section>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -16,4 +16,11 @@ form { padding: 6px 8px 2px; }
|
||||
input { flex: 1; min-width: 0; }
|
||||
#status { padding: 0 10px; color: light-dark(#943f42,#ffb3b9); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
|
||||
#mode { margin-left: auto; white-space: nowrap; }
|
||||
#library { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 18px; padding: 18px; }
|
||||
#library[hidden] { display: none; }
|
||||
#library h1 { font-size: 18px; margin: 0 0 10px; }
|
||||
#library ul { list-style: none; margin: 0; padding: 0; }
|
||||
#library li { display: flex; gap: 6px; align-items: start; margin-bottom: 6px; }
|
||||
#library li button:first-child { display: grid; flex: 1; text-align: left; white-space: normal; overflow-wrap: anywhere; }
|
||||
#library li span { font-size: 11px; opacity: .78; }
|
||||
@media (max-width: 750px) { form [data-action="zoomIn"], form [data-action="zoomOut"] { display: none; } }
|
||||
@@ -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