6 changed files with 267 additions and 3 deletions
@ -0,0 +1,113 @@
@@ -0,0 +1,113 @@
|
||||
/* DSH PRO - overlay.css : 页面右下角浮动面板样式 */ |
||||
|
||||
.dshmem-panel { |
||||
position: fixed; |
||||
right: 18px; |
||||
bottom: 18px; |
||||
width: 320px; |
||||
max-height: 70vh; |
||||
z-index: 2147483646; |
||||
background: rgba(24, 26, 31, 0.92); |
||||
color: #e8eaed; |
||||
border: 1px solid rgba(255, 255, 255, 0.14); |
||||
border-radius: 12px; |
||||
font: 12px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif; |
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45); |
||||
backdrop-filter: blur(8px); |
||||
display: flex; |
||||
flex-direction: column; |
||||
overflow: hidden; |
||||
} |
||||
.dshmem-panel.dshmem-min { max-height: none; } |
||||
|
||||
.dshmem-head { |
||||
display: flex; |
||||
align-items: center; |
||||
gap: 8px; |
||||
padding: 8px 12px; |
||||
background: rgba(255, 255, 255, 0.06); |
||||
cursor: pointer; |
||||
user-select: none; |
||||
} |
||||
.dshmem-dot { |
||||
width: 9px; height: 9px; border-radius: 50%; |
||||
background: #666; flex: none; |
||||
} |
||||
.dshmem-dot.ok { background: #34c759; } |
||||
.dshmem-dot.err { background: #ff5f57; } |
||||
.dshmem-dot.busy { background: #ffcc00; animation: dshmem-blink 1s infinite; } |
||||
@keyframes dshmem-blink { 50% { opacity: 0.35; } } |
||||
|
||||
.dshmem-title { font-weight: 600; letter-spacing: 0.4px; } |
||||
.dshmem-phase { color: #9aa0a6; font-size: 11px; } |
||||
.dshmem-toggle { margin-left: auto; color: #9aa0a6; cursor: pointer; } |
||||
|
||||
.dshmem-body { padding: 8px 12px 12px; overflow-y: auto; } |
||||
.dshmem-min .dshmem-body { display: none; } |
||||
|
||||
.dshmem-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; } |
||||
.dshmem-btn { |
||||
flex: 1 1 auto; |
||||
padding: 5px 10px; |
||||
border: 1px solid rgba(255,255,255,0.18); |
||||
border-radius: 8px; |
||||
background: rgba(255,255,255,0.08); |
||||
color: inherit; |
||||
cursor: pointer; |
||||
font: inherit; |
||||
white-space: nowrap; |
||||
} |
||||
.dshmem-btn:hover { background: rgba(255,255,255,0.16); } |
||||
.dshmem-btn.primary { background: #2f81f7; border-color: #2f81f7; } |
||||
.dshmem-btn.primary:hover { background: #4a93ff; } |
||||
.dshmem-btn.danger { background: #b62324; border-color: #b62324; } |
||||
.dshmem-btn:disabled { opacity: 0.45; cursor: not-allowed; } |
||||
|
||||
.dshmem-select, .dshmem-input { |
||||
width: 100%; |
||||
box-sizing: border-box; |
||||
padding: 5px 8px; |
||||
border-radius: 8px; |
||||
border: 1px solid rgba(255,255,255,0.18); |
||||
background: rgba(0,0,0,0.3); |
||||
color: inherit; |
||||
font: inherit; |
||||
} |
||||
|
||||
.dshmem-log { |
||||
margin-top: 8px; |
||||
padding: 6px 8px; |
||||
background: rgba(0,0,0,0.35); |
||||
border-radius: 8px; |
||||
max-height: 140px; |
||||
overflow-y: auto; |
||||
font: 11px/1.5 Consolas, monospace; |
||||
color: #b9bbbe; |
||||
white-space: pre-wrap; |
||||
word-break: break-all; |
||||
} |
||||
|
||||
.dshmem-preview { |
||||
margin-top: 8px; |
||||
padding: 6px 8px; |
||||
background: rgba(255, 204, 0, 0.08); |
||||
border: 1px dashed rgba(255, 204, 0, 0.5); |
||||
border-radius: 8px; |
||||
font: 11px/1.5 Consolas, monospace; |
||||
max-height: 120px; |
||||
overflow-y: auto; |
||||
white-space: pre-wrap; |
||||
word-break: break-all; |
||||
} |
||||
.dshmem-confirm-box { |
||||
margin-top: 8px; |
||||
padding: 8px; |
||||
background: rgba(255, 95, 87, 0.12); |
||||
border: 1px solid rgba(255, 95, 87, 0.5); |
||||
border-radius: 8px; |
||||
} |
||||
.dshmem-confirm-title { font-weight: 600; color: #ff8780; } |
||||
|
||||
.dshmem-settings { margin-top: 8px; border-top: 1px solid rgba(255,255,255,0.12); padding-top: 8px; } |
||||
.dshmem-settings .dshmem-input { margin-top: 4px; } |
||||
.dshmem-label { color: #9aa0a6; font-size: 11px; margin-top: 6px; } |
||||
@ -0,0 +1,133 @@
@@ -0,0 +1,133 @@
|
||||
'use strict'; |
||||
(function () { |
||||
var UI_ID = 'dshmem-panel'; |
||||
var LOG_CAP = 60; |
||||
var state = { |
||||
phase: 'off', |
||||
connected: false, |
||||
loopsLeft: 0, loopsMax: 0, |
||||
dailyCount: 0, dailyMax: 0, |
||||
resetCbs: [], stopCbs: [], saveCbs: [] |
||||
}; |
||||
var el = {}; |
||||
function byId(id) { return document.getElementById(id); } |
||||
function mk(tag, cls, txt) { |
||||
var n = document.createElement(tag); |
||||
if (cls) n.className = cls; |
||||
if (txt !== undefined) n.textContent = txt; |
||||
return n; |
||||
} |
||||
function build() { |
||||
if (byId(UI_ID)) return; |
||||
var root = mk('div', 'dshmem-panel'); |
||||
root.id = UI_ID; |
||||
var head = mk('div', 'dshmem-head'); |
||||
el.dot = mk('span', 'dshmem-dot'); |
||||
el.dot.id = 'dshmem-dot'; |
||||
var title = mk('span', 'dshmem-title', 'DSH Memory'); |
||||
el.phase = mk('span', 'dshmem-phase', 'Off'); |
||||
el.phase.id = 'dshmem-phase'; |
||||
el.toggle = mk('span', 'dshmem-toggle', '-'); |
||||
head.appendChild(el.dot); head.appendChild(title); head.appendChild(el.phase); head.appendChild(el.toggle); |
||||
el.body = mk('div', 'dshmem-body'); |
||||
root.appendChild(head); root.appendChild(el.body); |
||||
var row1 = mk('div', 'dshmem-row'); |
||||
el.reset = mk('button', 'dshmem-btn', 'Reset loops'); |
||||
el.stop = mk('button', 'dshmem-btn danger', 'Stop'); |
||||
row1.appendChild(el.reset); row1.appendChild(el.stop); |
||||
el.body.appendChild(row1); |
||||
el.loops = mk('div', 'dshmem-label', 'loops: 0/0'); |
||||
el.daily = mk('div', 'dshmem-label', 'daily: 0/0'); |
||||
el.body.appendChild(el.loops); el.body.appendChild(el.daily); |
||||
var set = mk('div', 'dshmem-settings'); |
||||
var lbl = mk('div', 'dshmem-label', 'Token (save, then reload page)'); |
||||
el.token = mk('input', 'dshmem-input'); |
||||
el.token.type = 'password'; |
||||
el.token.placeholder = 'dshmem-bridge-token'; |
||||
var row2 = mk('div', 'dshmem-row'); |
||||
el.save = mk('button', 'dshmem-btn primary', 'Save'); |
||||
el.health = mk('button', 'dshmem-btn', 'Health'); |
||||
row2.appendChild(el.save); row2.appendChild(el.health); |
||||
set.appendChild(lbl); set.appendChild(el.token); set.appendChild(row2); |
||||
el.body.appendChild(set); |
||||
el.log = mk('div', 'dshmem-log'); |
||||
el.log.id = 'dshmem-log'; |
||||
el.body.appendChild(el.log); |
||||
el.preview = mk('div', 'dshmem-preview'); |
||||
el.preview.style.display = 'none'; |
||||
el.body.appendChild(el.preview); |
||||
el.confirm = mk('div', 'dshmem-confirm-box'); |
||||
el.confirm.style.display = 'none'; |
||||
el.body.appendChild(el.confirm); |
||||
document.body.appendChild(root); |
||||
} |
||||
function wire() { |
||||
el.toggle.addEventListener('click', function () { |
||||
el.body.style.display = el.body.style.display === 'none' ? '' : 'none'; |
||||
}); |
||||
el.reset.addEventListener('click', function () { state.resetCbs.forEach(function (cb) { try { cb(); } catch (e) {} }); }); |
||||
el.stop.addEventListener('click', function () { state.stopCbs.forEach(function (cb) { try { cb(); } catch (e) {} }); }); |
||||
el.save.addEventListener('click', function () { var v = el.token.value || ''; state.saveCbs.forEach(function (cb) { try { cb(v); } catch (e) {} }); }); |
||||
el.health.addEventListener('click', function () { |
||||
try { globalThis.DSH_BRIDGE.health().then(function (r) { |
||||
if (r && r.ok) { API.setConnected(true); API.setPhase('Ready'); API.log('health ok'); } |
||||
else { API.setConnected(false); API.log('health fail: ' + ((r && r.error && r.error.message) || '?')); } |
||||
}); } catch (e) { API.log('health throw: ' + String(e)); } |
||||
}); |
||||
} |
||||
var API = { |
||||
setPhase: function (p) { state.phase = p; if (el.phase) el.phase.textContent = p; }, |
||||
setConnected: function (b) { state.connected = !!b; if (el.dot) el.dot.className = 'dshmem-dot ' + (b ? 'ok' : 'err'); }, |
||||
log: function (m) { |
||||
if (!el.log) return; |
||||
var t = new Date().toLocaleTimeString(); |
||||
var line = '[' + t + '] ' + m; |
||||
var txt = (line + String.fromCharCode(10) + (el.log.textContent || '')).split(String.fromCharCode(10)).slice(0, LOG_CAP).join(String.fromCharCode(10)); |
||||
el.log.textContent = txt; |
||||
}, |
||||
setLoops: function (left, max) { state.loopsLeft = left; state.loopsMax = max; if (el.loops) el.loops.textContent = 'loops: ' + left + '/' + max; }, |
||||
setDaily: function (c, m) { state.dailyCount = c; state.dailyMax = m; if (el.daily) el.daily.textContent = 'daily: ' + c + '/' + m; }, |
||||
onResetLoops: function (cb) { state.resetCbs.push(cb); }, |
||||
onStop: function (cb) { state.stopCbs.push(cb); }, |
||||
onSaveToken: function (cb) { state.saveCbs.push(cb); }, |
||||
getToken: function () { return el.token ? el.token.value : ''; }, |
||||
setToken: function (v) { if (el.token) el.token.value = v || ''; }, |
||||
showConfirm: function (opt) { |
||||
if (!el.confirm) return; |
||||
opt = opt || {}; |
||||
el.confirm.textContent = ''; |
||||
el.confirm.appendChild(mk('div', 'dshmem-confirm-title', opt.title || 'Confirm')); |
||||
el.confirm.appendChild(mk('div', 'dshmem-label', opt.detail || '')); |
||||
var r = mk('div', 'dshmem-row'); |
||||
var ok = mk('button', 'dshmem-btn primary', 'Allow'); |
||||
var no = mk('button', 'dshmem-btn danger', 'Deny'); |
||||
ok.addEventListener('click', function () { API.hideConfirm(); if (opt.onAllow) opt.onAllow(); }); |
||||
no.addEventListener('click', function () { API.hideConfirm(); if (opt.onDeny) opt.onDeny(); }); |
||||
r.appendChild(ok); r.appendChild(no); el.confirm.appendChild(r); |
||||
el.confirm.style.display = 'block'; |
||||
}, |
||||
hideConfirm: function () { if (el.confirm) el.confirm.style.display = 'none'; }, |
||||
showPreview: function (opt) { |
||||
if (!el.preview) return; |
||||
opt = opt || {}; |
||||
var sec = opt.seconds || 2; |
||||
var text = opt.text || ''; |
||||
var cancelled = false; |
||||
el.preview.style.display = 'block'; |
||||
var render = function () { el.preview.textContent = 'Sending in ' + sec + 's (click to cancel):' + String.fromCharCode(10) + text.slice(0, 500); }; |
||||
render(); |
||||
var iv = setInterval(function () { |
||||
sec--; |
||||
if (sec <= 0) { clearInterval(iv); el.preview.style.display = 'none'; el.preview.onclick = null; if (!cancelled && opt.onSend) opt.onSend(); } |
||||
else render(); |
||||
}, 1000); |
||||
el.preview.onclick = function () { cancelled = true; clearInterval(iv); el.preview.style.display = 'none'; el.preview.onclick = null; if (opt.onCancel) opt.onCancel(); }; |
||||
}, |
||||
hidePreview: function () { if (el.preview) el.preview.style.display = 'none'; }, |
||||
init: function () { build(); wire(); } |
||||
}; |
||||
globalThis.DSHMEM = API; |
||||
if (document.readyState === 'loading') { |
||||
document.addEventListener('DOMContentLoaded', function () { API.init(); }); |
||||
} else { API.init(); } |
||||
})(); |
||||
Loading…
Reference in new issue