微件:LivestreamCalendarControls
更多操作
<style id="tlc-styles"> .tlc {
--tlc-surface: var(--color-surface-1, #fffafd); --tlc-text: var(--color-base, #5c3b4d); --tlc-muted: var(--color-subtle, #80596f); --tlc-border: var(--border-color-base, #ffd1e6); --tlc-accent: var(--color-progressive, #9f1534); --tlc-active: var(--color-surface-3, #ffe6f2); --tlc-gold: #986716; --tlc-gold: light-dark(#986716, #ffcf6b); --tlc-gold-glow: #e0a72c; margin: 16px 0 24px; border: 1px solid var(--tlc-border); border-radius: 12px; background: var(--tlc-surface); color: var(--tlc-text); font-size: 14px; line-height: 1.5;
} .tlc [hidden], .tlc[hidden] { display: none !important; } .tlc-summary {
display: flex; align-items: center; flex-wrap: wrap; gap: 4px 12px; padding: 12px 16px; cursor: pointer; list-style: none;
} .tlc-summary::-webkit-details-marker { display: none; } .tlc-summary::before {
content: ""; width: 8px; height: 8px; margin-right: 4px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(-45deg);
} .tlc[open] > .tlc-summary::before { transform: translateY(-2px) rotate(45deg); } .tlc-heading, .tlc-label { font-weight: 700; } .tlc-heading { font-size: 16px; } .tlc-status, .tlc-note { color: var(--tlc-muted); } .tlc-status { margin-inline-start: auto; } .tlc-body { padding: 0 16px 16px; } .tlc-body > section { padding-top: 16px; border-top: 1px solid var(--tlc-border); } .tlc-body > section + section { margin-top: 24px; } .tlc-filters, .tlc-options, .tlc-legend, .tlc-series {
display: flex; flex-wrap: wrap; gap: 8px;
} .tlc-filters { margin-top: 8px; } .tlc button, .tlc select {
min-height: 36px; box-sizing: border-box; padding: 4px 12px; border: 1px solid var(--tlc-border); border-radius: 8px; background: var(--tlc-surface); color: inherit; font: inherit;
} .tlc button { cursor: pointer; } .tlc button:hover, .tlc select:hover { border-color: var(--tlc-accent); } .tlc button[aria-pressed="true"] {
border-color: var(--tlc-accent); background: var(--tlc-active); color: var(--tlc-accent); font-weight: 700;
} .tlc :focus-visible { outline: 2px solid var(--tlc-accent); outline-offset: 2px; } .tlc-note { max-width: 42em; margin: 8px 0 0; } .tlc-stat-head {
display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px;
} .tlc-metric { margin-top: 4px; color: var(--tlc-muted); } .tlc-metric strong {
color: var(--tlc-text); font-size: 20px; font-variant-numeric: tabular-nums;
} .tlc-options { align-items: end; gap: 8px 12px; } .tlc-commercial, .tlc-ranking-commercial { min-width: 36px; } .tlc :is(.tlc-commercial, .tlc-ranking-commercial)[aria-pressed="true"] { border-color: var(--tlc-gold); } .tlc-series-controls { margin-top: 16px; } .tlc-series { margin-top: 8px; } .tlc-options label { display: grid; gap: 4px; color: var(--tlc-muted); } .tlc-options select { color: var(--tlc-text); color-scheme: light dark; } .tlc-chart { max-width: 44rem; margin-top: 16px; } .tlc-chart .tlc-breakdown, .tlc-chart .tlc-legend { margin: 0; padding: 0; list-style: none; } .tlc-breakdown { display: grid; gap: 8px; } .tlc-row {
display: grid; grid-template-columns: 5em minmax(0, 1fr) 3em; align-items: center; gap: 8px;
} .tlc-row > :last-child { text-align: end; font-variant-numeric: tabular-nums; } .tlc-track { background: var(--tlc-active); border-radius: 4px; } .tlc-bar { height: 12px; border-radius: inherit; background: var(--tlc-series-color); } .tlc-pie-layout {
display: flex; flex-wrap: wrap; align-items: center; gap: 16px 24px;
} .tlc-pie { width: 144px; aspect-ratio: 1; border-radius: 50%; } .tlc-pie-list { flex: 1; min-width: min(100%, 12em); } .tlc-pie-list .tlc-row { grid-template-columns: auto minmax(0, 1fr) auto; } .tlc-key {
display: inline-block; width: 12px; height: 12px; margin-inline-end: 4px; border-radius: 4px; background: var(--tlc-series-color);
} .tlc-plot-wrap { position: relative; } .tlc-plot { display: block; width: 100%; height: 208px; } .tlc-tooltip {
position: absolute; z-index: 1; box-sizing: border-box; max-width: 100%; padding: 8px 12px; border: 1px solid var(--tlc-border); border-radius: 8px; background: var(--tlc-surface); color: var(--tlc-text); font-size: 12px; line-height: 1.4; pointer-events: none;
} .tlc-tooltip-row { display: flex; justify-content: space-between; gap: 12px; } .tlc-tooltip-row > :last-child { white-space: nowrap; font-variant-numeric: tabular-nums; } .tlc-point, .tlc-gold-series { pointer-events: none; } .tlc-hover-month { fill: transparent; } .tlc-hover-month:focus-visible { outline-offset: -2px; } .tlc-ranking .tlc-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; } .tlc-ranking .tlc-track { grid-column: 1 / -1; } .tlc-ranking .tlc-game-name { overflow-wrap: anywhere; } .tlc-ranking .tlc-rank { margin-inline-end: 8px; color: var(--tlc-muted); } .tlc-ranking .tlc-count { text-align: end; font-variant-numeric: tabular-nums; } .tlc-ranking .tlc-bar { overflow: hidden; } .tlc-commercial-part { display: block; height: 100%; margin-inline-start: auto; background: var(--tlc-gold); } .tlc-tooltip > strong { display: block; margin-bottom: 4px; } .tlc-axis-label { fill: var(--tlc-muted); font-size: 12px; } .tlc-gridline { stroke: var(--tlc-border); stroke-width: 1; } .tlc-line { stroke: var(--tlc-series-color); fill: none; stroke-width: 2; } .tlc-point { fill: var(--tlc-series-color); } .tlc-gold-series .tlc-line { stroke-width: 2.5; } .tlc-gold-glow { stroke: var(--tlc-gold-glow); stroke-width: 7; opacity: .25; fill: none; } .tlc-gold-spark { fill: var(--tlc-gold); } .tlc-gold-mote circle { fill: var(--tlc-gold-glow); stroke: var(--tlc-gold); stroke-width: 1; } @media (prefers-reduced-motion: reduce) {
.tlc-gold-mote { display: none; }
} .tlc-chart .tlc-legend { margin-top: 8px; gap: 4px 12px; } .tlc-data { margin-top: 12px; } .tlc-data summary { cursor: pointer; width: fit-content; } .tlc-scroll { margin-top: 8px; overflow: auto; } .tlc-data table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; } .tlc-data :is(th, td) {
padding: 4px 8px; border-bottom: 1px solid var(--tlc-border); text-align: end; white-space: nowrap;
} .tlc-data th:first-child { text-align: start; } .schedule-grid .tlc-unmatched { filter: grayscale(1); } @media (forced-colors: active) {
.tlc button[aria-pressed="true"] { border: 2px solid Highlight; }
.tlc-bar, .tlc-key { border: 1px solid CanvasText; }
.tlc-pie, .tlc-line, .tlc-point, .tlc-key { forced-color-adjust: none; }
} </style> <details class="tlc" hidden>
<summary class="tlc-summary">
筛选与统计
</summary>
<section aria-label="按标签筛选">
可多选,匹配任一标签即保留原色,其余事件灰显。
</section> <section aria-label="事件统计">
</section>
</details> <script id="tlc-controller"> (() => {
'use strict';
// Same work under different names in the calendar. Keep sequels and distinct mods separate. const gameAliases = new Map([ ['与嘉然联动玩《名将杀》', '名将杀'], ['打麻雀一番街', '麻雀一番街'], ['和雪糕自由魂一起麻雀一番街!', '麻雀一番街'], ['麻雀一番街4.5周年', '麻雀一番街'], ['爱之巢~v0.098~', '爱之巢'], ['鬼武者:剑之道 demo', '鬼武者:剑之道'], ['守望先锋2', '守望先锋'], ['红sc:名为偶像的祭品', '我推的祭品'] ]);
function gameName(node) {
const altTitle = node.querySelector('.event-title-alt')?.textContent.trim();
const title = altTitle || node.querySelector('.event-title-main')?.textContent || ;
let name = title.normalize('NFKC');
// Remove complete parenthetical notes, including nested notes.
while (/\([^()]*\)/.test(name)) name = name.replace(/\([^()]*\)/g, );
name = name.trim().replace(/\s+/g, ' ');
return gameAliases.get(name.toLowerCase()) || name;
}
function init() {
const panel = document.querySelector('.tlc');
const grid = panel?.closest('.mw-parser-output')?.querySelector('.schedule-grid');
if (!grid || !panel.hidden) return;
const months = Array.from({ length: 12 }, () => ({
total: 0, commercial: 0, tags: new Map(), games: new Map()
}));
const annual = { total: 0, tags: new Map() };
const gameTotals = new Map();
const days = [];
let latestMonth = -1;
function count(period, tags) {
period.total++;
for (const tag of tags) period.tags.set(tag, (period.tags.get(tag) || 0) + 1);
}
for (const day of grid.querySelectorAll('.schedule-day')) {
const date = day.querySelector('.schedule-date')?.textContent.trim();
const match = date?.match(/^26\/(\d{2})\/\d{2}\b/);
if (!match) continue;
const month = Number(match[1]) - 1;
if (!months[month]) continue;
const events = [...day.querySelectorAll('.event-container > .event-item')].map(node => {
const tags = new Set((node.querySelector('.event-tag')?.textContent || )
.split(/[//]/).map(tag => tag.trim()).filter(Boolean));
if (!tags.size) tags.add('未标注');
count(annual, tags);
count(months[month], tags);
if (node.classList.contains('event-commercial')) months[month].commercial++;
if (tags.has('游戏')) {
const name = gameName(node);
const game = name.toLowerCase();
if (game) {
for (const totals of [gameTotals, months[month].games]) {
const stats = totals.get(game) || { name, count: 0, commercial: 0 };
stats.count++;
if (node.classList.contains('event-commercial')) stats.commercial++;
totals.set(game, stats);
}
}
}
return { node, tags };
});
if (events.length) {
days.push({ day, events });
latestMonth = Math.max(latestMonth, month);
}
}
if (!annual.total) return;
const seenGames = new Set();
const gameFirstCounts = months.map(({ games }) => {
const before = seenGames.size;
for (const game of games.keys()) seenGames.add(game);
return seenGames.size - before;
});
const sorted = tags => [...tags].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0], 'zh-CN'));
const tags = sorted(annual.tags).map(([tag]) => tag);
const selectedSeries = new Set(tags);
const totalSeries = Symbol('事件总量');
const number = new Intl.NumberFormat('zh-CN');
const percent = new Intl.NumberFormat('zh-CN', { style: 'percent', maximumFractionDigits: 1 });
const summary = panel.querySelector('.tlc-status');
const filters = panel.querySelector('.tlc-filters');
const chart = panel.querySelector('.tlc-chart');
const metric = panel.querySelector('.tlc-metric');
const kind = panel.querySelector('.tlc-chart-kind');
const period = panel.querySelector('.tlc-period');
const series = panel.querySelector('.tlc-series');
const commercial = panel.querySelector('.tlc-commercial');
const rankingCommercial = panel.querySelector('.tlc-ranking-commercial');
const rankingLimit = panel.querySelector('.tlc-ranking-limit');
const gameMode = panel.querySelector('.tlc-game-mode');
const chosen = new Set();
const colors = new Map([
['游戏', '#3b82f6'], ['视听', '#a855f7'], ['3D', '#db447a'],
['休息', '#666666'], ['杂谈', '#e67e22'], ['联动', '#d93a3a'],
['特殊', '#f2cc0d'], ['ASMR', '#93ceec'], ['未标注', '#747484']
]);
const fallback = ['#159947', '#9140dc', '#ad7048', '#747484'];
const tagColor = tag => colors.get(tag) || fallback[tags.indexOf(tag) % fallback.length];
function element(name, className, text) {
const node = document.createElement(name);
if (className) node.className = className;
if (text != null) node.textContent = text;
return node;
}
function filterButton(label, onClick) {
const button = element('button', , label);
button.type = 'button';
button.addEventListener('click', onClick);
filters.append(button);
return button;
}
const clear = filterButton('全部', () => {
chosen.clear();
applyFilter();
});
const buttons = tags.map(tag => filterButton(tag, () => {
if (chosen.has(tag)) chosen.delete(tag);
else chosen.add(tag);
applyFilter();
}));
function applyFilter() {
let matches = 0;
for (const { day, events } of days) {
let dayMatches = 0;
for (const { node, tags: eventTags } of events) {
const match = !chosen.size || [...eventTags].some(tag => chosen.has(tag));
node.classList.toggle('tlc-unmatched', !match);
if (match) dayMatches++;
}
day.classList.toggle('tlc-unmatched', dayMatches === 0);
matches += dayMatches;
}
clear.setAttribute('aria-pressed', String(!chosen.size));
buttons.forEach((button, index) => button.setAttribute('aria-pressed', String(chosen.has(tags[index]))));
summary.textContent = chosen.size
? `匹配 ${number.format(matches)} / ${number.format(annual.total)} 条`
: `2026 年 · ${number.format(annual.total)} 条`;
}
function key(color) {
const node = element('span', 'tlc-key');
node.setAttribute('aria-hidden', 'true');
node.style.setProperty('--tlc-series-color', color);
return node;
}
function breakdown(stats, pie) {
const counts = sorted(stats.tags);
const list = element('ul', 'tlc-breakdown');
if (pie) list.classList.add('tlc-pie-list');
const totalTags = counts.reduce((sum, [, value]) => sum + value, 0);
const slices = [];
let offset = 0;
for (const [tag, value] of counts) {
const row = element('li', 'tlc-row');
const name = element('span', , tag);
if (pie) {
const share = value / totalTags;
row.append(key(tagColor(tag)), name, element('span', , `${number.format(value)} · ${percent.format(share)}`));
const end = offset + 100 * share;
slices.push(`${tagColor(tag)} ${offset}% ${end}%`);
offset = end;
} else {
const track = element('div', 'tlc-track');
const bar = element('div', 'tlc-bar');
track.setAttribute('aria-hidden', 'true');
bar.style.width = `${value / counts[0][1] * 100}%`;
bar.style.setProperty('--tlc-series-color', tagColor(tag));
track.append(bar);
row.append(name, track, element('span', , number.format(value)));
}
list.append(row);
}
if (!pie) return list;
const layout = element('div', 'tlc-pie-layout');
const disc = element('div', 'tlc-pie');
disc.setAttribute('aria-hidden', 'true');
disc.style.backgroundImage = `conic-gradient(${slices.join(',')})`;
layout.append(disc, list);
return layout;
}
function svgElement(name, attributes, text) {
const node = document.createElementNS('http://www.w3.org/2000/svg', name);
for (const [attribute, value] of Object.entries(attributes)) node.setAttribute(attribute, value);
if (text != null) node.textContent = text;
return node;
}
function plot(svg, lines, tooltip) {
const width = Math.max(240, chart.clientWidth);
const left = 32;
const bottom = 184;
const top = 12;
const max = Math.max(1, ...lines.flatMap(line => line.values));
const unit = 10 ** Math.floor(Math.log10(Math.max(1, max / 4)));
const step = [1, 2, 5, 10].map(n => n * unit).find(n => n >= max / 4);
const limit = Math.ceil(max / step) * step;
const x = month => left + month * (width - left - 12) / 11;
const y = count => bottom - count / limit * (bottom - top);
svg.setAttribute('viewBox', `0 0 ${width} 208`);
svg.replaceChildren();
for (let value = 0; value <= limit; value += step) {
svg.append(
svgElement('line', { x1: left, x2: width - 12, y1: y(value), y2: y(value), class: 'tlc-gridline' }),
svgElement('text', { x: left - 8, y: y(value), 'text-anchor': 'end', 'dominant-baseline': 'middle', class: 'tlc-axis-label' }, value)
);
}
months.forEach((_, i) => {
svg.append(svgElement('text', { x: x(i), y: 204, 'text-anchor': 'middle', class: 'tlc-axis-label' }, i + 1));
});
const patterns = [, '6 3', '2 3', '8 3 2 3'];
lines.forEach(({ color, values, gold }, index) => {
const group = svgElement('g', { class: gold ? 'tlc-gold-series' : });
group.style.setProperty('--tlc-series-color', color);
const points = values.map((value, i) => [x(i), y(value)]);
const pointList = points.join(' ');
if (gold) group.append(svgElement('polyline', { points: pointList, class: 'tlc-gold-glow' }));
group.append(svgElement('polyline', {
points: pointList,
class: 'tlc-line',
'stroke-dasharray': gold ? : patterns[index % patterns.length]
}));
for (const [cx, cy] of points) {
group.append(svgElement('circle', { cx, cy, r: 2.5, class: 'tlc-point' }));
}
svg.append(group);
if (gold) goldParticles(group, points, values);
});
tooltip.hidden = true;
const showTooltip = (month, event) => {
tooltip.replaceChildren(element('strong', , `${month + 1} 月`));
for (const { name, values, color, unit } of lines) {
const row = element('div', 'tlc-tooltip-row');
const label = element('span');
label.append(key(color), name);
row.append(label, element('span', , `${number.format(values[month])} ${unit}`));
tooltip.append(row);
}
tooltip.hidden = false;
const bounds = svg.getBoundingClientRect();
const pointer = event.type.startsWith('pointer');
const anchorX = pointer ? event.clientX - bounds.left : x(month) / width * bounds.width;
const anchorY = pointer ? event.clientY - bounds.top : top;
tooltip.style.left = `${Math.max(0, Math.min(anchorX + 12, bounds.width - tooltip.offsetWidth))}px`;
tooltip.style.top = `${Math.max(0, Math.min(anchorY + 12, bounds.height - tooltip.offsetHeight))}px`;
};
const halfMonth = (x(1) - x(0)) / 2;
for (let month = 0; month <= latestMonth; month++) {
const label = lines.map(line => `${line.name} ${number.format(line.values[month])} ${line.unit}`).join(',');
const target = svgElement('rect', {
x: x(month) - halfMonth, y: top - 8, width: halfMonth * 2, height: bottom - top + 16,
class: 'tlc-hover-month', tabindex: 0, role: 'img',
'aria-label': `${month + 1} 月,${label}`
});
target.addEventListener('pointermove', event => showTooltip(month, event));
target.addEventListener('pointerdown', event => showTooltip(month, event));
target.addEventListener('focus', event => showTooltip(month, event));
target.addEventListener('blur', () => { tooltip.hidden = true; });
svg.append(target);
}
svg.onpointerleave = () => { tooltip.hidden = true; };
svg.onkeydown = event => {
if (event.key === 'Escape') tooltip.hidden = true;
};
}
function goldParticles(group, points, values) {
points.forEach(([x, y], i) => {
if (!values[i]) return;
const offset = i % 2 ? 1 : -1;
group.append(
svgElement('circle', { cx: x + offset * 4, cy: y - 6, r: 1.5, class: 'tlc-gold-spark' }),
svgElement('circle', { cx: x - offset * 5, cy: y + 5, r: 1, class: 'tlc-gold-spark' })
);
});
if (points.length < 2 || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
for (const [index, duration] of [2400, 2900, 3400].entries()) {
const mote = svgElement('g', { class: 'tlc-gold-mote', opacity: 0 });
if (typeof mote.animate !== 'function') return;
mote.append(svgElement('circle', { cy: -3 - 2 * index, r: 2 + index / 2 }));
group.append(mote);
const start = Math.min(index, points.length - 2);
mote.animate(points.slice(start).map(([x, y]) => ({
transform: `translate(${x}px, ${y}px)`
})), duration);
mote.animate([
{ opacity: 0 }, { opacity: 1, offset: .12 },
{ opacity: 1, offset: .72 }, { opacity: 0 }
], duration);
}
}
function trendTable(lines, label) {
const table = element('table');
const header = table.createTHead().insertRow();
for (const heading of ['月份', ...lines.map(line => line.name)]) {
const cell = element('th', , heading);
cell.scope = 'col';
header.append(cell);
}
const body = table.createTBody();
months.forEach((_, i) => {
const row = body.insertRow();
const heading = element('th', , `${i + 1} 月`);
heading.scope = 'row';
row.append(heading);
for (const { values } of lines) {
row.insertCell().textContent = i <= latestMonth ? number.format(values[i]) : '—';
}
});
const scroll = element('div', 'tlc-scroll');
scroll.tabIndex = 0;
scroll.setAttribute('role', 'region');
scroll.setAttribute('aria-label', label);
scroll.append(table);
const data = element('details', 'tlc-data');
data.append(element('summary', , '查看每月数据'), scroll);
return data;
}
let drawTrend;
function showTrend() {
const knownMonths = months.slice(0, latestMonth + 1);
const lines = tags.filter(tag => selectedSeries.has(tag)).map(tag => ({
name: tag,
color: tagColor(tag),
values: knownMonths.map(month => month.tags.get(tag) || 0)
}));
if (selectedSeries.has(totalSeries)) {
lines.unshift({
name: '事件总量',
color: '#db447a',
values: knownMonths.map(month => month.total)
});
}
if (commercial.getAttribute('aria-pressed') === 'true') {
lines.push({
name: '💰 商单',
color: 'var(--tlc-gold)',
values: knownMonths.map(month => month.commercial),
gold: true
});
}
if (lines.length) showLineChart(lines, '各月事件数量', '条');
else chart.append(element('p', 'tlc-note', '选择至少一个走势,或开启 💰 商单。'));
}
function showLineChart(lines, label, unit) {
const wrap = element('div', 'tlc-plot-wrap');
const svg = svgElement('svg', { class: 'tlc-plot', role: 'group', 'aria-label': label });
const tooltip = element('div', 'tlc-tooltip');
tooltip.setAttribute('role', 'tooltip');
tooltip.hidden = true;
wrap.append(svg, tooltip);
lines = lines.map(line => ({ ...line, unit }));
const legend = element('ul', 'tlc-legend');
for (const { name, color } of lines) {
const item = element('li');
item.append(key(color), name);
legend.append(item);
}
chart.append(wrap, legend, trendTable(lines, label));
drawTrend = () => plot(svg, lines, tooltip);
drawTrend();
}
function showGameTrend() {
metric.replaceChildren(element('strong', , number.format(seenGames.size)), ' 款 · 全年去重');
if (!seenGames.size) {
chart.append(element('p', 'tlc-note', '暂无游戏记录。'));
return;
}
const first = gameMode.value === 'first';
const counts = first ? gameFirstCounts : months.map(month => month.games.size);
showLineChart([{
name: first ? '首次游玩游戏数' : '游玩游戏数',
color: tagColor('游戏'),
values: counts.slice(0, latestMonth + 1)
}], '各月游戏数量', '款');
}
function showGameRanking() {
const games = period.value === 'year' ? gameTotals : months[Number(period.value)].games;
const scope = period.value === 'year' ? '全年' : `${Number(period.value) + 1} 月`;
const rankedGames = [...games].sort((a, b) =>
b[1].count - a[1].count || a[0].localeCompare(b[0], 'zh-CN'));
const totalEvents = rankedGames.reduce((sum, [, stats]) => sum + stats.count, 0);
metric.replaceChildren(
element('strong', , number.format(rankedGames.length)),
` 款 · ${scope} · ${number.format(totalEvents)} 条游戏事件`
);
if (!rankedGames.length) {
chart.append(element('p', 'tlc-note', '暂无游戏记录。'));
return;
}
const markCommercial = rankingCommercial.getAttribute('aria-pressed') === 'true';
const limit = rankingLimit.value === 'all' ? Infinity : Number(rankingLimit.value);
const visible = rankedGames.slice(0, limit);
const list = element('ol', 'tlc-breakdown tlc-ranking');
const maxCount = rankedGames[0][1].count;
for (const [index, [game, stats]] of visible.entries()) {
const row = element('li', 'tlc-row');
row.dataset.game = game;
const name = element('span', 'tlc-game-name');
name.append(element('span', 'tlc-rank', index + 1), stats.name);
const count = element('span', 'tlc-count', number.format(stats.count));
if (markCommercial && stats.commercial) {
const money = element('span', 'tlc-commercial-count', ` · 💰 ${number.format(stats.commercial)}`);
money.setAttribute('aria-label', `其中商单 ${number.format(stats.commercial)} 条`);
count.append(money);
}
const track = element('div', 'tlc-track');
track.setAttribute('aria-hidden', 'true');
const bar = element('div', 'tlc-bar');
bar.style.width = `${stats.count / maxCount * 100}%`;
bar.style.setProperty('--tlc-series-color', tagColor('游戏'));
if (markCommercial && stats.commercial) {
const gold = element('span', 'tlc-commercial-part');
gold.style.width = `${stats.commercial / stats.count * 100}%`;
bar.append(gold);
}
track.append(bar);
row.append(name, count, track);
list.append(row);
}
chart.append(list);
const legend = element('div', 'tlc-legend');
const regular = element('span');
regular.append(key(tagColor('游戏')), markCommercial ? '普通事件' : '游戏事件');
legend.append(regular);
if (markCommercial) {
const gold = element('span');
gold.append(key('var(--tlc-gold)'), '商单事件');
legend.append(gold);
}
chart.append(legend);
}
function renderChart() {
chart.replaceChildren();
drawTrend = null;
const trend = kind.value === 'trend';
const games = kind.value === 'games';
const ranking = kind.value === 'ranking';
period.closest('label').hidden = trend || games;
rankingLimit.closest('label').hidden = !ranking;
gameMode.closest('label').hidden = !games;
series.closest('.tlc-series-controls').hidden = !trend;
commercial.hidden = !trend;
rankingCommercial.hidden = !ranking;
if (ranking) {
showGameRanking();
return;
}
if (games) {
showGameTrend();
return;
}
const stats = trend || period.value === 'year' ? annual : months[Number(period.value)];
const label = stats === annual ? '全年条目' : `${Number(period.value) + 1} 月条目`;
metric.replaceChildren(element('strong', , number.format(stats.total)), ` 条 · ${label}`);
if (trend) showTrend();
else if (stats.total) chart.append(breakdown(stats, kind.value === 'pie'));
else chart.append(element('p', 'tlc-note', '该月暂无日历条目。'));
}
period.add(new Option('全年', 'year'));
months.forEach((_, index) => period.add(new Option(`${index + 1} 月`, index)));
function seriesButton(label, onClick) {
const button = element('button', , label);
button.type = 'button';
button.addEventListener('click', () => {
onClick();
updateSeriesButtons();
renderChart();
});
series.append(button);
return button;
}
const allSeries = seriesButton('全部标签', () => {
const allSelected = tags.every(tag => selectedSeries.has(tag));
for (const tag of tags) {
if (allSelected) selectedSeries.delete(tag);
else selectedSeries.add(tag);
}
});
const seriesButtons = [totalSeries, ...tags].map(value => {
const button = seriesButton(value === totalSeries ? '事件总量' : value, () => {
if (selectedSeries.has(value)) selectedSeries.delete(value);
else selectedSeries.add(value);
});
return { value, button };
});
function updateSeriesButtons() {
allSeries.setAttribute('aria-pressed', String(tags.every(tag => selectedSeries.has(tag))));
for (const { value, button } of seriesButtons) {
button.setAttribute('aria-pressed', String(selectedSeries.has(value)));
}
}
updateSeriesButtons();
applyFilter();
commercial.addEventListener('click', () => {
commercial.setAttribute('aria-pressed', String(commercial.getAttribute('aria-pressed') !== 'true'));
renderChart();
});
rankingCommercial.addEventListener('click', () => {
rankingCommercial.setAttribute('aria-pressed', String(rankingCommercial.getAttribute('aria-pressed') !== 'true'));
renderChart();
});
for (const select of [period, kind, gameMode, rankingLimit]) select.addEventListener('change', renderChart);
panel.addEventListener('toggle', () => {
if (panel.open && !chart.childElementCount) renderChart();
});
if ('ResizeObserver' in window) {
let width = 0;
new ResizeObserver(([entry]) => {
if (entry.contentRect.width === width) return;
width = entry.contentRect.width;
if (width && drawTrend) drawTrend();
}).observe(chart);
}
panel.hidden = false;
}
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init, { once: true });
else init();
})(); </script>