528 lines
18 KiB
JavaScript
528 lines
18 KiB
JavaScript
(() => {
|
|||
|
|
'use strict';
|
||
|
|
|
||
|
|
const PLATFORMS = ['windows', 'android', 'ios', 'macos'];
|
||
|
|
const PLATFORM_NAMES = { windows: 'Windows', android: 'Android', ios: 'iOS', macos: 'macOS' };
|
||
|
|
const { REPO, FIRST_PAGE, parseChangelog, translate, formatDate, changelogMeta, timelineHtml } = globalThis.ZytbSite;
|
||
|
|
const SITE = new URL('..', document.currentScript.src);
|
||
|
|
|
||
|
|
const root = document.documentElement;
|
||
|
|
const $ = (selector, scope = document) => scope.querySelector(selector);
|
||
|
|
const reducedMotion = matchMedia('(prefers-reduced-motion: reduce)');
|
||
|
|
|
||
|
|
const state = {
|
||
|
|
platform: 'windows',
|
||
|
|
detected: { platform: null, ios: false },
|
||
|
|
platformChosen: false,
|
||
|
|
release: null,
|
||
|
|
releaseFailed: false,
|
||
|
|
versions: [],
|
||
|
|
changelogFailed: false,
|
||
|
|
shown: FIRST_PAGE,
|
||
|
|
query: '',
|
||
|
|
};
|
||
|
|
|
||
|
|
function t(key, ...args) {
|
||
|
|
return translate('zh', key, ...args);
|
||
|
|
}
|
||
|
|
|
||
|
|
function el(tag, props, ...children) {
|
||
|
|
const node = document.createElement(tag);
|
||
|
|
if (props) {
|
||
|
|
for (const [key, value] of Object.entries(props)) {
|
||
|
|
if (value == null || value === false) continue;
|
||
|
|
if (key === 'class') node.className = value;
|
||
|
|
else if (key === 'text') node.textContent = value;
|
||
|
|
else if (key.startsWith('on')) node.addEventListener(key.slice(2), value);
|
||
|
|
else node.setAttribute(key, value === true ? '' : value);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for (const child of children.flat()) {
|
||
|
|
if (child == null || child === false) continue;
|
||
|
|
node.append(child);
|
||
|
|
}
|
||
|
|
return node;
|
||
|
|
}
|
||
|
|
|
||
|
|
function svg(markup) {
|
||
|
|
const template = document.createElement('template');
|
||
|
|
template.innerHTML = markup.trim();
|
||
|
|
return template.content.firstChild;
|
||
|
|
}
|
||
|
|
|
||
|
|
const ICON_DOWN =
|
||
|
|
'<svg viewBox="0 0 20 20" width="18" height="18" aria-hidden="true"><path d="M10 3.5v11m0 0-4.5-4.5m4.5 4.5 4.5-4.5" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||
|
|
|
||
|
|
function rise(node, index) {
|
||
|
|
if (reducedMotion.matches || !node.animate) return;
|
||
|
|
node.animate([{ opacity: 0, translate: '0 14px' }, { opacity: 1, translate: '0 0' }], {
|
||
|
|
duration: 600,
|
||
|
|
delay: 40 * index,
|
||
|
|
easing: 'cubic-bezier(0.22, 1, 0.36, 1)',
|
||
|
|
fill: 'backwards',
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function formatAgo(iso) {
|
||
|
|
if (!iso) return '';
|
||
|
|
const days = Math.round((Date.now() - Date.parse(`${iso}T00:00:00Z`)) / 86400000);
|
||
|
|
const rtf = new Intl.RelativeTimeFormat('zh-CN', { numeric: 'auto' });
|
||
|
|
if (days < 7) return rtf.format(-Math.max(days, 0), 'day');
|
||
|
|
if (days < 30) return rtf.format(-Math.round(days / 7), 'week');
|
||
|
|
if (days < 365) return rtf.format(-Math.round(days / 30.4), 'month');
|
||
|
|
return rtf.format(-Math.round(days / 365), 'year');
|
||
|
|
}
|
||
|
|
|
||
|
|
function formatSize(bytes) {
|
||
|
|
return `${(bytes / 1048576).toFixed(1)} MB`;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 发布 workflow 产出的文件名,见 .github/workflows/publish-release.yml。
|
||
|
|
function buildsFor(platform) {
|
||
|
|
switch (platform) {
|
||
|
|
case 'windows':
|
||
|
|
return [
|
||
|
|
{ platform, suffix: '-setup.exe', kind: 'EXE', titleKey: 'winSetup', note: 'noteWinSetup', rec: true },
|
||
|
|
{ platform, suffix: '.zip', kind: 'ZIP', titleKey: 'winPortable', note: 'noteWinPortable' },
|
||
|
|
];
|
||
|
|
case 'android':
|
||
|
|
return [{ platform, suffix: '.apk', kind: 'APK', title: 'APK 安装包', note: 'noteAndroid', rec: true }];
|
||
|
|
case 'ios':
|
||
|
|
return [{ platform, suffix: '-unsigned.ipa', kind: 'IPA', title: '未签名 IPA', note: 'noteIos', rec: true }];
|
||
|
|
case 'macos':
|
||
|
|
return [{ platform, suffix: '.zip', kind: 'ZIP', title: 'macOS 应用', note: 'noteMacos', rec: true }];
|
||
|
|
default:
|
||
|
|
return [];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function assetName(release, build) {
|
||
|
|
return `zhongyu-toolbox-${build.platform}-v${release.version}${build.suffix}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
function assetHref(release, name) {
|
||
|
|
if (release.assets && !release.assets.has(name)) return `${REPO}/releases/tag/${release.tag}`;
|
||
|
|
return `${REPO}/releases/download/${release.tag}/${name}`;
|
||
|
|
}
|
||
|
|
|
||
|
|
function resolveBuilds(platform) {
|
||
|
|
const release = state.release;
|
||
|
|
if (!release) return [];
|
||
|
|
return buildsFor(platform).map((build) => {
|
||
|
|
const name = assetName(release, build);
|
||
|
|
const asset = release.assets ? release.assets.get(name) : null;
|
||
|
|
return {
|
||
|
|
...build,
|
||
|
|
name,
|
||
|
|
title: build.titleKey ? t(build.titleKey) : build.title,
|
||
|
|
href: assetHref(release, name),
|
||
|
|
size: asset ? asset.size : null,
|
||
|
|
digest: asset && asset.digest ? asset.digest.replace(/^sha256:/, '') : null,
|
||
|
|
};
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function isIos() {
|
||
|
|
const ua = navigator.userAgent;
|
||
|
|
return /iphone|ipad|ipod/i.test(ua) || (/macintosh/i.test(ua) && navigator.maxTouchPoints > 1);
|
||
|
|
}
|
||
|
|
|
||
|
|
function platformFromAgent() {
|
||
|
|
const ua = navigator.userAgent;
|
||
|
|
if (/android/i.test(ua)) return 'android';
|
||
|
|
if (isIos()) return 'ios';
|
||
|
|
if (/windows/i.test(ua)) return 'windows';
|
||
|
|
if (/macintosh|mac os x/i.test(ua)) return 'macos';
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
async function loadData() {
|
||
|
|
const [markdown, release] = await Promise.allSettled([
|
||
|
|
fetch(new URL('CHANGELOG.md', SITE), { cache: 'no-cache' }).then((r) =>
|
||
|
|
r.ok ? r.text() : Promise.reject(r.status),
|
||
|
|
),
|
||
|
|
fetch(new URL('release.json', SITE), { cache: 'no-cache' }).then((r) => (r.ok ? r.json() : null)),
|
||
|
|
]);
|
||
|
|
|
||
|
|
if (markdown.status === 'fulfilled') state.versions = parseChangelog(markdown.value);
|
||
|
|
else state.changelogFailed = true;
|
||
|
|
|
||
|
|
const meta = release.status === 'fulfilled' ? release.value : null;
|
||
|
|
if (meta && meta.tag) {
|
||
|
|
state.release = {
|
||
|
|
tag: meta.tag,
|
||
|
|
version: meta.tag.replace(/^v/, ''),
|
||
|
|
date: (meta.publishedAt || '').slice(0, 10),
|
||
|
|
assets: new Map((meta.assets || []).map((asset) => [asset.name, asset])),
|
||
|
|
};
|
||
|
|
} else {
|
||
|
|
const stable = state.versions.find((v) => !v.tag.includes('-'));
|
||
|
|
if (stable) state.release = { tag: stable.tag, version: stable.version, date: stable.date, assets: null };
|
||
|
|
else state.releaseFailed = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function applyStaticText() {
|
||
|
|
root.lang = 'zh-CN';
|
||
|
|
document.title = t('pageTitle');
|
||
|
|
$('meta[name="description"]').content = t('pageDescription');
|
||
|
|
for (const node of document.querySelectorAll('[data-i18n]')) node.textContent = t(node.dataset.i18n);
|
||
|
|
for (const node of document.querySelectorAll('[data-i18n-placeholder]')) {
|
||
|
|
node.placeholder = t(node.dataset.i18nPlaceholder);
|
||
|
|
}
|
||
|
|
$('#platform-seg').setAttribute('aria-label', t('platformLabel'));
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderReleaseMeta() {
|
||
|
|
const release = state.release;
|
||
|
|
if (release) {
|
||
|
|
$('#hero-release-text').textContent = t('heroRelease', release.tag, formatDate(release.date));
|
||
|
|
$('#hero-release').href = `#${release.tag}`;
|
||
|
|
$('#dl-meta').textContent = $('#dock-dl-meta').textContent = t(
|
||
|
|
'dlMeta',
|
||
|
|
release.version,
|
||
|
|
formatDate(release.date),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderCta() {
|
||
|
|
const cta = $('#cta');
|
||
|
|
const sub = $('#cta-sub');
|
||
|
|
const note = $('#cta-note');
|
||
|
|
$('#hero-platform').textContent = PLATFORM_NAMES[state.platform];
|
||
|
|
note.hidden = !state.detected.ios;
|
||
|
|
note.textContent = state.detected.ios ? t('ctaIos') : '';
|
||
|
|
const builds = state.detected.ios && !state.platformChosen ? [] : resolveBuilds(state.platform);
|
||
|
|
const pick = builds.find((b) => b.rec) || builds[0];
|
||
|
|
if (!pick) {
|
||
|
|
$('#cta-title').textContent = t('ctaChoose');
|
||
|
|
sub.hidden = true;
|
||
|
|
cta.href = '#download';
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
$('#cta-title').textContent = t('ctaDownload', PLATFORM_NAMES[state.platform]);
|
||
|
|
const parts = [pick.title];
|
||
|
|
if (pick.size) parts.push(formatSize(pick.size));
|
||
|
|
sub.textContent = parts.join(' · ');
|
||
|
|
sub.hidden = false;
|
||
|
|
cta.href = pick.href;
|
||
|
|
}
|
||
|
|
|
||
|
|
function selectTab(group, value) {
|
||
|
|
for (const button of group.querySelectorAll('[role="tab"]')) {
|
||
|
|
const selected = button.dataset.value === value;
|
||
|
|
button.setAttribute('aria-selected', String(selected));
|
||
|
|
button.tabIndex = selected ? 0 : -1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function wireTabs(group, onSelect) {
|
||
|
|
group.addEventListener('click', (event) => {
|
||
|
|
const button = event.target.closest('[role="tab"]');
|
||
|
|
if (button) onSelect(button.dataset.value);
|
||
|
|
});
|
||
|
|
group.addEventListener('keydown', (event) => {
|
||
|
|
if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
|
||
|
|
const tabs = [...group.querySelectorAll('[role="tab"]')];
|
||
|
|
const index = tabs.indexOf(document.activeElement);
|
||
|
|
if (index < 0) return;
|
||
|
|
event.preventDefault();
|
||
|
|
let next = index;
|
||
|
|
if (event.key === 'ArrowLeft') next = (index - 1 + tabs.length) % tabs.length;
|
||
|
|
if (event.key === 'ArrowRight') next = (index + 1) % tabs.length;
|
||
|
|
if (event.key === 'Home') next = 0;
|
||
|
|
if (event.key === 'End') next = tabs.length - 1;
|
||
|
|
tabs[next].focus();
|
||
|
|
onSelect(tabs[next].dataset.value);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function fileRow(build) {
|
||
|
|
const sha = build.digest
|
||
|
|
? el('button', {
|
||
|
|
class: 'sha',
|
||
|
|
type: 'button',
|
||
|
|
text: 'SHA-256',
|
||
|
|
title: build.digest,
|
||
|
|
'aria-label': t('copySha', build.name),
|
||
|
|
onclick: (event) => copyText(build.digest, event.currentTarget),
|
||
|
|
})
|
||
|
|
: null;
|
||
|
|
return el(
|
||
|
|
'li',
|
||
|
|
{ class: build.rec ? 'file rec' : 'file' },
|
||
|
|
el(
|
||
|
|
'div',
|
||
|
|
{ class: 'file-main' },
|
||
|
|
el(
|
||
|
|
'p',
|
||
|
|
{ class: 'file-head' },
|
||
|
|
el('a', { class: 'file-title', href: build.href, title: build.name, text: build.title }),
|
||
|
|
build.rec ? el('span', { class: 'rec-tag', text: t('recommended') }) : null,
|
||
|
|
),
|
||
|
|
el(
|
||
|
|
'p',
|
||
|
|
{ class: 'file-sub' },
|
||
|
|
el('span', { class: 'note', text: t(build.note) }),
|
||
|
|
el('span', { class: 'kind', text: build.kind }),
|
||
|
|
build.size ? el('span', { class: 'size', text: formatSize(build.size) }) : null,
|
||
|
|
sha,
|
||
|
|
),
|
||
|
|
),
|
||
|
|
el('span', { class: 'go', 'aria-hidden': 'true' }, svg(ICON_DOWN)),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
function tip(titleKey, textKey) {
|
||
|
|
return el('div', { class: 'tip' }, el('h3', { text: t(titleKey) }), el('p', { text: t(textKey) }));
|
||
|
|
}
|
||
|
|
|
||
|
|
function extrasFor(platform) {
|
||
|
|
const tips = { windows: 'tipWindows', android: 'tipAndroid', ios: 'tipIos', macos: 'tipMacos' };
|
||
|
|
const titles = {
|
||
|
|
windows: 'tipWindowsTitle',
|
||
|
|
android: 'tipAndroidTitle',
|
||
|
|
ios: 'tipIosTitle',
|
||
|
|
macos: 'tipMacosTitle',
|
||
|
|
};
|
||
|
|
return [tip(titles[platform], tips[platform]), tip('tipAccountTitle', 'tipAccount')];
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderPanel(withMotion) {
|
||
|
|
const hints = { windows: 'hintWindows', android: 'hintAndroid', ios: 'hintIos', macos: 'hintMacos' };
|
||
|
|
$('#panel-hint').textContent = t(hints[state.platform]);
|
||
|
|
$('#panel').setAttribute('aria-labelledby', `tab-${state.platform}`);
|
||
|
|
|
||
|
|
const files = $('#files');
|
||
|
|
files.replaceChildren(...resolveBuilds(state.platform).map(fileRow));
|
||
|
|
$('#dl-error').hidden = !state.releaseFailed;
|
||
|
|
$('#dl-error').textContent = state.releaseFailed ? t('dlError') : '';
|
||
|
|
$('#extras').replaceChildren(...extrasFor(state.platform));
|
||
|
|
if (withMotion) [...files.children, ...$('#extras').children].forEach(rise);
|
||
|
|
}
|
||
|
|
|
||
|
|
function setPlatform(platform) {
|
||
|
|
if (!PLATFORM_NAMES[platform]) return;
|
||
|
|
const changed = platform !== state.platform;
|
||
|
|
state.platform = platform;
|
||
|
|
state.platformChosen = true;
|
||
|
|
selectTab($('#platform-seg'), platform);
|
||
|
|
renderCta();
|
||
|
|
renderPanel(changed);
|
||
|
|
}
|
||
|
|
|
||
|
|
function matchVersion(version, query) {
|
||
|
|
if (version.version.includes(query) || version.tag.toLowerCase().includes(query)) return version.groups;
|
||
|
|
return version.groups
|
||
|
|
.map((group) => ({
|
||
|
|
...group,
|
||
|
|
entries: group.entries.filter(
|
||
|
|
(entry) =>
|
||
|
|
entry.text.toLowerCase().includes(query) ||
|
||
|
|
(entry.scope && entry.scope.toLowerCase().includes(query)) ||
|
||
|
|
(entry.id && entry.id.startsWith(query)),
|
||
|
|
),
|
||
|
|
}))
|
||
|
|
.filter((group) => group.entries.length);
|
||
|
|
}
|
||
|
|
|
||
|
|
const revealer =
|
||
|
|
'IntersectionObserver' in window
|
||
|
|
? new IntersectionObserver(
|
||
|
|
(entries) => {
|
||
|
|
for (const entry of entries) {
|
||
|
|
if (!entry.isIntersecting) continue;
|
||
|
|
entry.target.classList.replace('pending', 'shown');
|
||
|
|
revealer.unobserve(entry.target);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
{ rootMargin: '0px 0px -8% 0px' },
|
||
|
|
)
|
||
|
|
: null;
|
||
|
|
|
||
|
|
function stageReveal(nodes) {
|
||
|
|
if (!revealer || reducedMotion.matches) return;
|
||
|
|
for (const node of nodes) {
|
||
|
|
if (node.getBoundingClientRect().top < innerHeight * 0.92) continue;
|
||
|
|
node.classList.add('pending');
|
||
|
|
revealer.observe(node);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
let lastYear = null;
|
||
|
|
|
||
|
|
function appendReleases(container, items, query) {
|
||
|
|
const { html, year } = timelineHtml(items, {
|
||
|
|
query,
|
||
|
|
latestTag: state.versions[0]?.tag,
|
||
|
|
ago: formatAgo,
|
||
|
|
year: lastYear,
|
||
|
|
});
|
||
|
|
lastYear = year;
|
||
|
|
const template = document.createElement('template');
|
||
|
|
template.innerHTML = html;
|
||
|
|
const releases = [...template.content.querySelectorAll('.release')];
|
||
|
|
container.append(template.content);
|
||
|
|
stageReveal(releases);
|
||
|
|
}
|
||
|
|
|
||
|
|
function renderTimeline() {
|
||
|
|
const timeline = $('#timeline');
|
||
|
|
const status = $('#cl-status');
|
||
|
|
|
||
|
|
if (state.changelogFailed) {
|
||
|
|
status.replaceChildren(
|
||
|
|
t('clError'),
|
||
|
|
' ',
|
||
|
|
el('a', { href: `${REPO}/releases`, text: t('clErrorLink') }),
|
||
|
|
);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
timeline.replaceChildren();
|
||
|
|
lastYear = null;
|
||
|
|
|
||
|
|
const versions = state.versions;
|
||
|
|
$('#cl-meta').textContent = $('#dock-cl-meta').textContent = changelogMeta(versions);
|
||
|
|
|
||
|
|
const query = state.query.trim().toLowerCase();
|
||
|
|
if (!query) {
|
||
|
|
status.replaceChildren();
|
||
|
|
appendReleases(
|
||
|
|
timeline,
|
||
|
|
versions.slice(0, state.shown).map((version) => ({ version, groups: version.groups })),
|
||
|
|
'',
|
||
|
|
);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
const matches = versions
|
||
|
|
.map((version) => ({ version, groups: matchVersion(version, query) }))
|
||
|
|
.filter(({ version, groups }) => groups.length || version.version.includes(query));
|
||
|
|
const entryCount = matches.reduce(
|
||
|
|
(sum, { groups }) => sum + groups.reduce((n, group) => n + group.entries.length, 0),
|
||
|
|
0,
|
||
|
|
);
|
||
|
|
const clear = el('button', {
|
||
|
|
type: 'button',
|
||
|
|
text: t('clClear'),
|
||
|
|
onclick: () => {
|
||
|
|
$('#cl-search').value = '';
|
||
|
|
state.query = '';
|
||
|
|
renderTimeline();
|
||
|
|
$('#cl-search').focus();
|
||
|
|
},
|
||
|
|
});
|
||
|
|
if (matches.length) status.replaceChildren(t('clResults', entryCount, matches.length), ' · ', clear);
|
||
|
|
else status.replaceChildren(t('clNone', state.query.trim()), ' ', clear);
|
||
|
|
appendReleases(timeline, matches, query);
|
||
|
|
}
|
||
|
|
|
||
|
|
function revealHash() {
|
||
|
|
let tag;
|
||
|
|
try {
|
||
|
|
tag = decodeURIComponent(location.hash.slice(1));
|
||
|
|
} catch {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const index = state.versions.findIndex((v) => v.tag === tag);
|
||
|
|
if (index < 0) return;
|
||
|
|
requestAnimationFrame(() => document.getElementById(tag)?.scrollIntoView());
|
||
|
|
}
|
||
|
|
|
||
|
|
async function copyText(text, button) {
|
||
|
|
let ok = false;
|
||
|
|
try {
|
||
|
|
await navigator.clipboard.writeText(text);
|
||
|
|
ok = true;
|
||
|
|
} catch {
|
||
|
|
const area = el('textarea', { readonly: true, style: 'position:fixed;opacity:0' });
|
||
|
|
area.value = text;
|
||
|
|
document.body.append(area);
|
||
|
|
area.select();
|
||
|
|
try {
|
||
|
|
ok = document.execCommand('copy');
|
||
|
|
} catch {}
|
||
|
|
area.remove();
|
||
|
|
}
|
||
|
|
if (!ok) return;
|
||
|
|
button.classList.add('done');
|
||
|
|
const label = button.classList.contains('sha') ? button.textContent : null;
|
||
|
|
if (label) button.textContent = t('copied');
|
||
|
|
clearTimeout(button._reset);
|
||
|
|
button._reset = setTimeout(() => {
|
||
|
|
button.classList.remove('done');
|
||
|
|
if (label) button.textContent = label;
|
||
|
|
}, 1600);
|
||
|
|
}
|
||
|
|
|
||
|
|
function takeCarriedView() {
|
||
|
|
const params = new URLSearchParams(location.search);
|
||
|
|
const view = { platform: params.get('platform'), query: params.get('q') };
|
||
|
|
if (!['platform', 'q'].some((key) => params.has(key))) return view;
|
||
|
|
for (const key of ['platform', 'q']) params.delete(key);
|
||
|
|
const search = params.toString();
|
||
|
|
history.replaceState(history.state, '', `${location.pathname}${search ? `?${search}` : ''}${location.hash}`);
|
||
|
|
return view;
|
||
|
|
}
|
||
|
|
|
||
|
|
function wireEvents() {
|
||
|
|
wireTabs($('#platform-seg'), setPlatform);
|
||
|
|
|
||
|
|
let searchTimer = 0;
|
||
|
|
$('#cl-search').addEventListener('input', (event) => {
|
||
|
|
clearTimeout(searchTimer);
|
||
|
|
searchTimer = setTimeout(() => {
|
||
|
|
state.query = event.target.value;
|
||
|
|
renderTimeline();
|
||
|
|
}, 80);
|
||
|
|
});
|
||
|
|
$('#cl-search').addEventListener('keydown', (event) => {
|
||
|
|
if (event.key === 'Escape' && event.target.value) {
|
||
|
|
event.target.value = '';
|
||
|
|
state.query = '';
|
||
|
|
renderTimeline();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
document.addEventListener('keydown', (event) => {
|
||
|
|
if (event.key !== '/' || event.metaKey || event.ctrlKey || event.altKey) return;
|
||
|
|
if (event.target.closest('input, textarea, [contenteditable]')) return;
|
||
|
|
event.preventDefault();
|
||
|
|
$('#cl-search').focus({ preventScroll: true });
|
||
|
|
$('#changelog').scrollIntoView();
|
||
|
|
});
|
||
|
|
addEventListener('hashchange', revealHash);
|
||
|
|
}
|
||
|
|
|
||
|
|
async function start() {
|
||
|
|
const carried = takeCarriedView();
|
||
|
|
state.platform = platformFromAgent() || 'windows';
|
||
|
|
applyStaticText();
|
||
|
|
selectTab($('#platform-seg'), state.platform);
|
||
|
|
renderCta();
|
||
|
|
wireEvents();
|
||
|
|
|
||
|
|
await loadData();
|
||
|
|
const detected = platformFromAgent();
|
||
|
|
state.detected = { platform: detected, ios: isIos() };
|
||
|
|
state.platform = detected || 'windows';
|
||
|
|
if (PLATFORMS.includes(carried.platform)) {
|
||
|
|
state.platform = carried.platform;
|
||
|
|
state.platformChosen = true;
|
||
|
|
}
|
||
|
|
if (carried.query) {
|
||
|
|
state.query = carried.query;
|
||
|
|
$('#cl-search').value = carried.query;
|
||
|
|
}
|
||
|
|
|
||
|
|
renderReleaseMeta();
|
||
|
|
selectTab($('#platform-seg'), state.platform);
|
||
|
|
renderCta();
|
||
|
|
renderPanel(false);
|
||
|
|
renderTimeline();
|
||
|
|
if (location.hash) revealHash();
|
||
|
|
}
|
||
|
|
|
||
|
|
start();
|
||
|
|
})();
|