交付双端基础、实时联系人和隔离浏览器

This commit is contained in:
xhgit committed 2026-11-13 18:03:32 +08:00
1 parent 43687d5e7e
commit 67fef3ff87
59 files changed
+5094 -1

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>XHChat 浏览器</title>
<link rel="stylesheet" href="/browser/style.css">
<script defer src="/browser/ui.js"></script>
</head>
<body>
<header>
<div class="tabs"><div id="tabs" aria-label="标签页"></div><button data-action="new" aria-label="新建标签页">+</button><span id="mode"></span></div>
<form id="address-form">
<button type="button" data-action="back" aria-label="后退">←</button>
<button type="button" data-action="forward" aria-label="前进">→</button>
<button type="button" data-action="reload" aria-label="刷新">↻</button>
<input id="address" aria-label="网址或搜索关键词" placeholder="输入网址或搜索关键词" autocomplete="off" maxlength="4096">
<button>打开</button>
<button type="button" data-action="copy" aria-label="复制网址">复制</button>
<button type="button" data-action="external" aria-label="系统浏览器打开">↗</button>
<button type="button" data-action="zoomOut" aria-label="缩小">−</button>
<button type="button" data-action="zoomIn" aria-label="放大">+</button>
<button type="button" data-action="fullscreen" aria-label="全屏">⛶</button>
<button type="button" data-action="private">隐私窗口</button>
<button type="button" data-action="clear">清除数据</button>
</form>
<div id="status" role="status"></div>
</header>
</body>
</html>
+19
View File
@@ -0,0 +1,19 @@
* { box-sizing: border-box; }
:root { color-scheme: light dark; font: 13px/1.4 system-ui, "Microsoft YaHei UI", sans-serif; }
body { margin: 0; background: Canvas; color: CanvasText; }
header { height: 102px; background: light-dark(#f0f5f2,#1e2924); }
.tabs, #tabs, form { display: flex; align-items: center; gap: 5px; min-width: 0; }
.tabs { padding: 5px 8px 0; height: 34px; }
#tabs { overflow-x: auto; scrollbar-width: thin; }
.tab { display: flex; align-items: center; border-radius: 6px; background: light-dark(#e2ebe5,#293d33); }
.tab.active { background: light-dark(#cde4d6,#3f6050); }
.tab button:first-child { max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
button, input { font: inherit; color: inherit; border: 1px solid light-dark(#cbd8d0,#4a6154); border-radius: 6px; background: Canvas; padding: 4px 7px; }
button { cursor: pointer; white-space: nowrap; }
button:disabled { opacity: .5; cursor: default; }
.tab button { border: 0; background: transparent; }
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; }
@media (max-width: 750px) { form [data-action="zoomIn"], form [data-action="zoomOut"] { display: none; } }
+57
View File
@@ -0,0 +1,57 @@
const api = window.xhchatBrowser
const tabs = document.querySelector('#tabs')
const address = document.querySelector('#address')
const status = document.querySelector('#status')
const button = (action) => document.querySelector(`[data-action="${action}"]`)
let current
function render(state) {
current = state
tabs.replaceChildren(...state.tabs.map((tab) => {
const element = document.createElement('span')
element.className = tab.id === state.active ? 'tab active' : 'tab'
const title = document.createElement('button')
title.textContent = tab.title
title.setAttribute('aria-pressed', String(tab.id === state.active))
title.onclick = () => { address.blur(); void command('activate', tab.id) }
const close = document.createElement('button')
close.textContent = '×'
close.setAttribute('aria-label', '关闭 ' + tab.title)
close.onclick = () => void command('close', tab.id)
element.append(title, close)
return element
}))
if (document.activeElement !== address) address.value = state.url
button('back').disabled = !state.back
button('forward').disabled = !state.forward
button('reload').textContent = state.loading ? '×' : '↻'
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 ? '隐私窗口' : ''
status.textContent = state.error
}
async function command(action, value) {
try {
render(await api.command(action, value))
} catch (error) {
status.textContent = error.message
}
}
for (const element of document.querySelectorAll('[data-action]')) {
element.onclick = () => {
const action = element.dataset.action
void command(action === 'reload' && current?.loading ? 'stop' : action)
}
}
document.querySelector('#address-form').onsubmit = (event) => {
event.preventDefault()
const value = address.value
address.blur()
void command('go', value)
}
api.onState(render)
void command('state')