精修 WebUI 第十九轮:sticky elevation + toggle switch + 步进按钮
- sectionTitle sticky 真贴顶时(IntersectionObserver + sentinel rootMargin -65px)加 .isStuck 类,浮起 0 6px 12px 阴影 - 关键开关升级为 toggle switch:.check.isToggle 把 input[type=checkbox] 渲染成 32×18 滑块(slider 配 14×14 圆点 + 0.18 阴影);3 个总控开关接入:infinite_loop_enabled / yanghao_enabled / yanghao_enable_actions / yanghao_only - fmtDuration 改 mono 格式:HH:MM:SS / MM:SS(padStart),适配 tabular-nums - 自绘 number stepper:所有 .input[type=number] 自动包 .numStepperWrap,hover/focus 时右侧浮现 ▲▼ 微按钮(18×12 双按钮组),调用 stepUp/stepDown + 派发 input/change;inline2 内不加避免连体冲突 - cache-bust v21 → v22
This commit is contained in:
1 parent
f16eadbd75
commit
cea5f1df45
3 files changed
+190
-9
No files matched your search
+61
-3
@@ -555,6 +555,23 @@ function initShotFullscreen() {
|
||||
});
|
||||
}
|
||||
|
||||
function initStickySectionShadow() {
|
||||
// 当 .sectionTitle 真正贴住 sticky top 时加 .isStuck 类
|
||||
const titles = Array.from(document.querySelectorAll(".sectionTitle"))
|
||||
.filter((el) => !el.matches(".cardTitle, summary, summary *"));
|
||||
if (!titles.length || !("IntersectionObserver" in window)) return;
|
||||
const io = new IntersectionObserver(
|
||||
(entries) => {
|
||||
for (const e of entries) {
|
||||
// intersectionRatio < 1 && top 已到达 sentinel:贴住状态
|
||||
e.target.classList.toggle("isStuck", e.intersectionRatio < 1 && e.boundingClientRect.top <= 65);
|
||||
}
|
||||
},
|
||||
{ threshold: [1], rootMargin: "-65px 0px 0px 0px" }
|
||||
);
|
||||
titles.forEach((t) => io.observe(t));
|
||||
}
|
||||
|
||||
function initShortcutsHelp() {
|
||||
const isMac = /Mac|iPhone|iPad|iPod/i.test(navigator.platform || navigator.userAgent || "");
|
||||
const mod = isMac ? "⌘" : "Ctrl";
|
||||
@@ -843,6 +860,44 @@ function renderActionsLog() {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
|
||||
function attachNumberSteppers() {
|
||||
// 给所有 .input[type=number] 包裹 .numStepperWrap + 添加 +/- 按钮
|
||||
const SVG_UP = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 15 12 9 18 15"/></svg>';
|
||||
const SVG_DOWN = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"/></svg>';
|
||||
document.querySelectorAll('input.input[type="number"]').forEach((input) => {
|
||||
if (input.dataset.stepperBound === "1") return;
|
||||
if (input.closest(".inline2")) return; // inline2 内不加,避免连体边框冲突
|
||||
input.dataset.stepperBound = "1";
|
||||
const wrap = document.createElement("div");
|
||||
wrap.className = "numStepperWrap";
|
||||
input.parentNode.insertBefore(wrap, input);
|
||||
wrap.appendChild(input);
|
||||
const btns = document.createElement("span");
|
||||
btns.className = "numStepperBtns";
|
||||
const up = document.createElement("button");
|
||||
up.type = "button";
|
||||
up.tabIndex = -1;
|
||||
up.className = "numStepperBtn";
|
||||
up.setAttribute("aria-label", "增加");
|
||||
up.innerHTML = SVG_UP;
|
||||
const down = document.createElement("button");
|
||||
down.type = "button";
|
||||
down.tabIndex = -1;
|
||||
down.className = "numStepperBtn";
|
||||
down.setAttribute("aria-label", "减少");
|
||||
down.innerHTML = SVG_DOWN;
|
||||
btns.append(up, down);
|
||||
wrap.appendChild(btns);
|
||||
const fire = (dir) => {
|
||||
try { dir > 0 ? input.stepUp() : input.stepDown(); } catch (_) {}
|
||||
input.dispatchEvent(new Event("input", { bubbles: true }));
|
||||
input.dispatchEvent(new Event("change", { bubbles: true }));
|
||||
};
|
||||
up.addEventListener("click", (e) => { e.preventDefault(); fire(1); });
|
||||
down.addEventListener("click", (e) => { e.preventDefault(); fire(-1); });
|
||||
});
|
||||
}
|
||||
|
||||
function fmtTime(ts) {
|
||||
if (!ts) return "-";
|
||||
try {
|
||||
@@ -857,9 +912,10 @@ function fmtDuration(seconds) {
|
||||
const h = Math.floor(s / 3600);
|
||||
const m = Math.floor((s % 3600) / 60);
|
||||
const sec = s % 60;
|
||||
if (h > 0) return `${h}小时${m}分${sec}秒`;
|
||||
if (m > 0) return `${m}分${sec}秒`;
|
||||
return `${sec}秒`;
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
// mono 格式:HH:MM:SS(>1h)/ MM:SS(其他),方便 tabular-nums 对齐
|
||||
if (h > 0) return `${pad(h)}:${pad(m)}:${pad(sec)}`;
|
||||
return `${pad(m)}:${pad(sec)}`;
|
||||
}
|
||||
|
||||
function pollShot() {
|
||||
@@ -2266,6 +2322,8 @@ window.addEventListener("DOMContentLoaded", async () => {
|
||||
initHeaderScroll();
|
||||
initKeyboardShortcuts();
|
||||
initShortcutsHelp();
|
||||
initStickySectionShadow();
|
||||
attachNumberSteppers();
|
||||
startReservationsCountdownTick();
|
||||
// 首屏统计数字加骨架,待第一次 pollStats 成功后移除
|
||||
document.querySelectorAll(".stat .statValue").forEach((el) => {
|
||||
|
||||
+6
-6
@@ -15,7 +15,7 @@
|
||||
} catch (e) {}
|
||||
})();
|
||||
</script>
|
||||
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v21" />
|
||||
<link rel="stylesheet" href="styles.css?v=console-20260520-theme-v22" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="app">
|
||||
@@ -253,7 +253,7 @@
|
||||
<label class="label">允许切换直播间(needswitch)</label>
|
||||
<div class="row">
|
||||
<label class="label">无限循环模式</label>
|
||||
<label class="check">
|
||||
<label class="check isToggle">
|
||||
<input id="infinite_loop_enabled" type="checkbox" data-key="infinite_loop_enabled" data-type="bool" />
|
||||
<span>启用后启动时 wait_minutes 按 0 处理</span>
|
||||
</label>
|
||||
@@ -693,14 +693,14 @@
|
||||
<div class="row grid2">
|
||||
<div>
|
||||
<label class="label">养号总开关(关闭=不跑推荐页养号)</label>
|
||||
<label class="check">
|
||||
<label class="check isToggle">
|
||||
<input id="yanghao_enabled" type="checkbox" data-key="yanghao_enabled" data-type="bool" checked />
|
||||
<span>启用</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<label class="label">养号动作开关(爱心/收藏/评论)</label>
|
||||
<label class="check">
|
||||
<label class="check isToggle">
|
||||
<input id="yanghao_enable_actions" type="checkbox" data-key="yanghao_enable_actions" data-type="bool" checked />
|
||||
<span>启用</span>
|
||||
</label>
|
||||
@@ -708,7 +708,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="label">只执行推荐页养号流程</label>
|
||||
<label class="check">
|
||||
<label class="check isToggle">
|
||||
<input id="yanghao_only" type="checkbox" data-key="yanghao_only" data-type="bool" />
|
||||
<span>启动后只养号,不抢福袋</span>
|
||||
</label>
|
||||
@@ -1259,6 +1259,6 @@
|
||||
<svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m18 15-6-6-6 6"/></svg>
|
||||
</button>
|
||||
|
||||
<script src="app.js?v=console-20260520-theme-v21"></script>
|
||||
<script src="app.js?v=console-20260520-theme-v22"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1248,6 +1248,23 @@ svg {
|
||||
z-index: 4;
|
||||
background: linear-gradient(180deg, var(--surface) 70%, color-mix(in oklab, var(--surface) 0%, transparent));
|
||||
backdrop-filter: blur(6px);
|
||||
transition: box-shadow var(--motion-fast);
|
||||
}
|
||||
|
||||
/* When sticky-pinned (top:64px is reached), elevate with a subtle shadow */
|
||||
.sectionTitle:not(.cardTitle):not(summary) {
|
||||
/* Use scroll-aware shadow via @supports trick: sticky elements show shadow when stuck */
|
||||
box-shadow: 0 0 0 0 transparent;
|
||||
}
|
||||
|
||||
@supports (position: sticky) {
|
||||
.sectionTitle.isStuck {
|
||||
box-shadow: 0 6px 12px -8px rgba(0, 0, 0, 0.12), 0 1px 0 var(--border);
|
||||
}
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] .sectionTitle.isStuck {
|
||||
box-shadow: 0 6px 12px -8px rgba(0, 0, 0, 0.5), 0 1px 0 var(--border);
|
||||
}
|
||||
|
||||
.cardTitle.sectionTitle,
|
||||
@@ -1434,6 +1451,66 @@ input[type="number"]::-webkit-outer-spin-button {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Custom number stepper: wraps an input with .numStepperWrap, +/- buttons appear on hover/focus */
|
||||
.numStepperWrap {
|
||||
position: relative;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.numStepperWrap > input[type="number"] {
|
||||
padding-right: 32px;
|
||||
}
|
||||
|
||||
.numStepperBtns {
|
||||
position: absolute;
|
||||
right: 4px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
gap: 1px;
|
||||
opacity: 0;
|
||||
transition: opacity var(--motion-fast);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.numStepperWrap:hover .numStepperBtns,
|
||||
.numStepperWrap:focus-within .numStepperBtns {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.numStepperBtn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 18px;
|
||||
height: 12px;
|
||||
padding: 0;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 3px;
|
||||
color: var(--muted);
|
||||
background: var(--surface);
|
||||
cursor: pointer;
|
||||
transition: color var(--motion-fast), border-color var(--motion-fast), background var(--motion-fast);
|
||||
}
|
||||
|
||||
.numStepperBtn:hover {
|
||||
color: var(--text);
|
||||
border-color: var(--hover-border);
|
||||
background: var(--surface-muted);
|
||||
}
|
||||
|
||||
.numStepperBtn:active {
|
||||
background: var(--primary-soft);
|
||||
color: var(--primary-accent-text);
|
||||
}
|
||||
|
||||
.numStepperBtn svg {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
}
|
||||
|
||||
.textarea {
|
||||
min-height: 96px;
|
||||
padding: 9px 10px;
|
||||
@@ -1475,6 +1552,52 @@ input[type="number"]::-webkit-outer-spin-button {
|
||||
accent-color: var(--primary);
|
||||
}
|
||||
|
||||
/* Toggle switch variant: add class .check.isToggle, the checkbox renders as a sliding switch.
|
||||
Apply by toggling .isToggle on existing .check labels. */
|
||||
.check.isToggle {
|
||||
cursor: pointer;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.check.isToggle input[type="checkbox"] {
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
position: relative;
|
||||
flex: 0 0 32px;
|
||||
width: 32px;
|
||||
height: 18px;
|
||||
border-radius: 999px;
|
||||
background: var(--border-strong);
|
||||
cursor: pointer;
|
||||
transition: background var(--motion-fast);
|
||||
}
|
||||
|
||||
.check.isToggle input[type="checkbox"]::after {
|
||||
position: absolute;
|
||||
left: 2px;
|
||||
top: 2px;
|
||||
content: "";
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 50%;
|
||||
background: var(--surface);
|
||||
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
|
||||
transition: transform var(--motion-fast), background var(--motion-fast);
|
||||
}
|
||||
|
||||
.check.isToggle input[type="checkbox"]:checked {
|
||||
background: var(--primary);
|
||||
}
|
||||
|
||||
.check.isToggle input[type="checkbox"]:checked::after {
|
||||
transform: translateX(14px);
|
||||
}
|
||||
|
||||
.check.isToggle input[type="checkbox"]:focus-visible {
|
||||
outline: none;
|
||||
box-shadow: 0 0 0 3px var(--focus-ring, rgba(94, 106, 210, 0.18));
|
||||
}
|
||||
|
||||
.check span {
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
|
||||
Reference in new issue
Block a user