From 2773684293c0a3fd87e36a0dc2b82dee047f2967 Mon Sep 17 00:00:00 2001 From: teaSummer Date: Sun, 4 Aug 2024 06:31:24 +0800 Subject: [PATCH] perf: download & debug --- index.html | 3 ++ locales/en.yml | 19 ++++++------ locales/zh-CN.yml | 19 ++++++------ scripts/init.js | 74 ++++++++++++++++++++++++++++++++++++++--------- scripts/main.js | 72 +++++++++++++-------------------------------- 5 files changed, 103 insertions(+), 84 deletions(-) diff --git a/index.html b/index.html index 0e1ff5c..8a97382 100644 --- a/index.html +++ b/index.html @@ -71,6 +71,9 @@
+ +
+
diff --git a/locales/en.yml b/locales/en.yml index 9794361..903aba0 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -37,7 +37,7 @@ data: goto: Just Go! download: Download downloadedLauncherUpdate: 'Launcher Update (Downloaded):' - updatedTo: updated to + updatedTo: 'has been updated:' updateArrow: ➔ exclamationMark: '!' search: Search @@ -70,6 +70,7 @@ data: darkTheme: Dark Theme earlyTheme: Early Theme ellipsis: .... + startDownloading: 'It will start downloading:' statistics: Statistics visitorCount: Visitor Count contributors: Contributors @@ -95,18 +96,18 @@ data: preRelease: Dev preRelease.note: the developing beta version launcher.release: >- - ${downloadSVG}{download} {release} ${linkVersion} launcher.release.latest: >- - ${downloadSVG}{download} {latest} {release} launcher.preRelease: >- - ${downloadSVG} {download} {preRelease} ${linkDevVersion} launcher.preRelease.latest: >- - ${downloadSVG} {download} {latest} {preRelease} \ No newline at end of file diff --git a/locales/zh-CN.yml b/locales/zh-CN.yml index 64ff8f1..2e533f6 100644 --- a/locales/zh-CN.yml +++ b/locales/zh-CN.yml @@ -37,7 +37,7 @@ data: goto: 跳转 download: 下载 downloadedLauncherUpdate: 您下载过的启动器更新啦: - updatedTo: 已更新至 + updatedTo: 已发布新版本: updateArrow: ➔ exclamationMark: ! search: 搜索 @@ -69,6 +69,7 @@ data: darkTheme: 深色主题 earlyTheme: 早期主题 ellipsis: .... + startDownloading: 即将开始下载: statistics: 统计信息 visitorCount: 访问计数 contributors: 贡献者 @@ -94,18 +95,18 @@ data: preRelease: 开发版 preRelease.note: 开发测试版 launcher.release: >- - ${downloadSVG}{download}{release} ${linkVersion} launcher.release.latest: >- - ${downloadSVG}{download}{latest}{release} launcher.preRelease: >- - ${downloadSVG}{download}{preRelease} ${linkDevVersion} launcher.preRelease.latest: >- - ${downloadSVG}{download}{latest}{preRelease} \ No newline at end of file diff --git a/scripts/init.js b/scripts/init.js index 7535502..2e866c1 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -4,9 +4,14 @@ let searchKeyword = '', searchableAbbr = ''; let notificationCount = ''; let visibility = true; +const downloadMirrorUrl = 'https://ghproxy.cn/' const downloadSVG = ''; -const downloadMirror = ((url) => `https://ghproxy.cn/${url}`); // 针对大陆地区 | for Chinese Mainland - +const downloadMirror = ((url) => $('.github-proxy').is(':checked') && String(url).startsWith('https://github.com/') ? downloadMirrorUrl.replace('', url) : url); // 针对大陆地区 | for Chinese Mainland +const downloadClick = (() => $('.download').click(function() { + $('.start-download a').remove(); + $('.start-download br').after(`${this.href.split('/').slice(-1)[0]}`); + $('.start-download').attr('open', true); +})); // 国际化 (internationalization) al.setLangPropPath('locales'); @@ -21,6 +26,25 @@ const i18n = ((callback = () => {}) => { }); +// 不记录历史滚动位置 +if (history.scrollRestoration) { + history.scrollRestoration = 'manual'; +}; + + +// 监听标签页切换事件 +$(document).on('visibilitychange', () => { + if (document.visibilityState == 'hidden') { + // 当前标签页隐藏时 + visibility = false; + }; + if (document.visibilityState == 'visible') { + // 当前标签页显示时 + visibility = true; + }; +}); + + // 读取 JSON5 文件 const read = ((file) => { return JSON5.parse($.ajax({ @@ -30,6 +54,40 @@ const read = ((file) => { }).responseText); }); + +// URL哈希属性监听 +const hashChanged = (() => { + if (location.hash == '') return; + let hash = decodeURI(location.hash).replace('/', '\\/'); + const slicedHash = hash.slice(0, -3); + // 自动展开/收起:
元素 + try { + // 通过检测哈希属性 + if (hash == '#全部展开') $('.page-content').find('details:not(.keep)').attr('open', true); + if (hash == '#全部收起') $('.page-content').find('details:not(.keep)').attr('open', false); + if (hash.endsWith('-展开')) { + $(slicedHash).find('details').attr('open', true); + $(slicedHash).find('.to-fold').show(); + $(slicedHash).find('.to-unfold').hide(); + location.hash = slicedHash; + }; + if (hash.endsWith('-收起')) { + $(slicedHash).find('details:not(.keep)').attr('open', false); + $(slicedHash).find('.to-unfold').show(); + $(slicedHash).find('.to-fold').hide(); + hash = slicedHash; + }; + // 通过检测 元素 + if ($(hash).html().startsWith('')) $(hash).attr('open', true); + else $(`${hash}>*:first-child`).addClass('hash'); + } catch {}; +}); +$(window).on('hashchange', () => { + $('.hash').removeClass('hash'); + hashChanged(); +}); + + // 启动器数据 const launcherData = read('launcher'); // 各平台启动器数据 @@ -45,15 +103,3 @@ const searchable = read('searchable'); // 各类网站数据 const utilityWebsite = read('utilityWebsite'); const otherForum = read('otherForum'); - - -// 不记录历史滚动位置 -if (history.scrollRestoration) { - history.scrollRestoration = 'manual'; -}; - - -// 调试模式 (Debug Mode) -let debug = false; -const debugChange = (e = $('[visibleInDebugMode]')) => {for (const t of e) t.style.display = (debug ? 'block': 'none')}; -debugChange(); /* 监听变更我就先咕咕咕了 <(^-^)> --xs */ diff --git a/scripts/main.js b/scripts/main.js index 9c357db..9ac238c 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -30,16 +30,15 @@ const createUpdateLayer = ((abbr, lastVersion, latestVersion, download, device,
${abbr} - - ${latestVersion} +
${lastVersion} ${latestVersion}
(${deviceInfo})
- +
`; $('sidebar').before(dom); $(`.update-layer-${updateLayerNumber} .download`).click(() => { @@ -112,11 +111,8 @@ const launcherChanged = ((event = {target: $('mdui-select.launcher-list')}) => { }; for (const attribute of ['data-download', 'data-dev-download', 'data-url']) { const button = $(`.${attribute}-launcher`); - let url = checked.attr(attribute); + const url = downloadMirror(checked.attr(attribute)); if (attribute.endsWith('download')) { - if ($('.github-proxy').is(':checked') && String(url).startsWith('https://github.com/')) { - url = downloadMirror(url); - }; const removeEmpty = ((version) => { if (version === void 0) { button.removeAttr('href').removeAttr('title').removeAttr('data-backup-href'); @@ -170,12 +166,12 @@ const proxyChanged = (() => { localStorage.setItem('github-proxy', $('.github-proxy').is(':checked')); try { if ($('.github-proxy').is(':checked')) { - $('.launcher-download>a.button').each((i, e) => { + $('.launcher-download a.button, .update-layer a.download').each((i, e) => { const url = $(e).attr('href'); - if (url.startsWith('https://github.com/')) $(e).attr('href', downloadMirror(url)); + $(e).attr('href', downloadMirror(url)); }); } else { - $('.launcher-download>a.button').each((i, e) => { + $('.launcher-download a.button, .update-layer a.download').each((i, e) => { $(e).attr('href', $(e).attr('data-backup-href')); }); }; @@ -431,39 +427,6 @@ const pre_list = ((e) => { }); -// URL哈希属性监听 -const hashChanged = (() => { - if (location.hash == '') return; - let hash = decodeURI(location.hash).replace('/', '\\/'); - const slicedHash = hash.slice(0, -3); - // 自动展开/收起:
元素 - try { - // 通过检测哈希属性 - if (hash == '#全部展开') $('.page-content').find('details:not(.keep)').attr('open', true); - if (hash == '#全部收起') $('.page-content').find('details:not(.keep)').attr('open', false); - if (hash.endsWith('-展开')) { - $(slicedHash).find('details').attr('open', true); - $(slicedHash).find('.to-fold').show(); - $(slicedHash).find('.to-unfold').hide(); - location.hash = slicedHash; - }; - if (hash.endsWith('-收起')) { - $(slicedHash).find('details:not(.keep)').attr('open', false); - $(slicedHash).find('.to-unfold').show(); - $(slicedHash).find('.to-fold').hide(); - hash = slicedHash; - }; - // 通过检测 元素 - if ($(hash).html().startsWith('')) $(hash).attr('open', true); - else $(`${hash}>*:first-child`).addClass('hash'); - } catch {}; -}); -$(window).on('hashchange', () => { - $('.hash').removeClass('hash'); - hashChanged(); -}); - - // 获取正常状态的简体中文论坛 const CSForum = [{"简体中文论坛": []}]; @@ -543,6 +506,7 @@ $(document).ready(() => { }; }; $('.update-layer').click(deleteUpdateLayer); + downloadClick(); i18n(); }; // 默认值初始化 @@ -565,14 +529,18 @@ $(document).ready(() => { } else $('#ces')[0].remove(); }); }); -// 监听标签页切换事件 -$(document).on('visibilitychange', () => { - if (document.visibilityState == 'hidden') { - // 当前标签页隐藏时 - visibility = false; - }; - if (document.visibilityState == 'visible') { - // 当前标签页显示时 - visibility = true; + + +// 调试模式 (Debug Mode) +const debugCallback = (e = $('[visibleInDebugMode]')) => (debug.mode ? e.show() : e.hide()); +const debugChange = ((object) => { + const handler = { + defineProperty: (target, property, descriptor) => { + Reflect.defineProperty(target, property, descriptor); + debugCallback(); + } }; + return new Proxy(object, handler); }); +const debug = debugChange({mode: false}); +debugCallback();