Skip to content

Commit

Permalink
perf: download & debug
Browse files Browse the repository at this point in the history
  • Loading branch information
teaSummer committed Aug 3, 2024
1 parent 680f548 commit 2773684
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 84 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
</dl>
</sidebar>
<main class="wait" style="display: none;">
<mdui-snackbar class="start-download" closeable>
<text al="startDownloading"></text><br>
</mdui-snackbar>
<div class="page-content">
<div class="introduction" id="介绍">
<a class="传送锚点" id="顶部"></a>
Expand Down
19 changes: 10 additions & 9 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,6 +70,7 @@ data:
darkTheme: Dark Theme
earlyTheme: Early Theme
ellipsis: ....
startDownloading: 'It will start downloading:'
statistics: Statistics
visitorCount: Visitor Count
contributors: Contributors
Expand All @@ -95,18 +96,18 @@ data:
preRelease: Dev
preRelease.note: the developing beta version
launcher.release: >-
<a class="button download data-download-launcher" target="_blank"
href="${linkUrl}" data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-download-launcher" href="${linkUrl}"
data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download} {release.note} ${linkVersion}">${downloadSVG}{download} {release} ${linkVersion}</a>
launcher.release.latest: >-
<a class="button download data-download-launcher" target="_blank"
href="${linkUrl}" data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-download-launcher" href="${linkUrl}"
data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download} {release.note} {latest.note}">${downloadSVG}{download} {latest} {release}</a>
launcher.preRelease: >-
<a class="button download data-dev-download-launcher" target="_blank"
href="${linkDevUrl}" data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-dev-download-launcher" href="${linkDevUrl}"
data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download} {preRelease.note} ${linkDevVersion}">${downloadSVG} {download} {preRelease} ${linkDevVersion}</a>
launcher.preRelease.latest: >-
<a class="button download data-dev-download-launcher" target="_blank"
href="${linkDevUrl}" data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-dev-download-launcher" href="${linkDevUrl}"
data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download} {preRelease.note} {latest.note}">${downloadSVG} {download} {latest} {preRelease}</a>
19 changes: 10 additions & 9 deletions locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ data:
goto: 跳转
download: 下载
downloadedLauncherUpdate: 您下载过的启动器更新啦:
updatedTo: 已更新至
updatedTo: 已发布新版本:
updateArrow:
exclamationMark:
search: 搜索
Expand Down Expand Up @@ -69,6 +69,7 @@ data:
darkTheme: 深色主题
earlyTheme: 早期主题
ellipsis: ....
startDownloading: 即将开始下载:
statistics: 统计信息
visitorCount: 访问计数
contributors: 贡献者
Expand All @@ -94,18 +95,18 @@ data:
preRelease: 开发版
preRelease.note: 开发测试版
launcher.release: >-
<a class="button download data-download-launcher" target="_blank"
href="${linkUrl}" data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-download-launcher" href="${linkUrl}"
data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download}{release.note} ${linkVersion}">${downloadSVG}{download}{release} ${linkVersion}</a>
launcher.release.latest: >-
<a class="button download data-download-launcher" target="_blank"
href="${linkUrl}" data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-download-launcher" href="${linkUrl}"
data-backup-href="${linkDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download}{latest.note}{release.note}">${downloadSVG}{download}{latest}{release}</a>
launcher.preRelease: >-
<a class="button download data-dev-download-launcher" target="_blank"
href="${linkDevUrl}"data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-dev-download-launcher" href="${linkDevUrl}"
data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download}{preRelease.note} ${linkDevVersion}">${downloadSVG}{download}{preRelease} ${linkDevVersion}</a>
launcher.preRelease.latest: >-
<a class="button download data-dev-download-launcher" target="_blank"
href="${linkDevUrl}" data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
<a class="button download data-dev-download-launcher" href="${linkDevUrl}"
data-backup-href="${linkDevDownload}" ondragstart="event.dataTransfer.effectAllowed = 'none';"
title="{download}{latest.note}{preRelease.note}">${downloadSVG}{download}{latest}{preRelease}</a>
74 changes: 60 additions & 14 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ let searchKeyword = '', searchableAbbr = '';
let notificationCount = '';
let visibility = true;

const downloadMirrorUrl = 'https://ghproxy.cn/<T>'
const downloadSVG = '<span class="svg right"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M320 336h76c55 0 100-21.21 100-75.6s-53-73.47-96-75.6C391.11 99.74 329 48 256 48c-69 0-113.44 45.79-128 91.2-60 5.7-112 35.88-112 98.4S70 336 136 336h56M192 400.1l64 63.9 64-63.9M256 224v224.03" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="56"></path></svg></span>';
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('<T>', url) : url); // 针对大陆地区 | for Chinese Mainland
const downloadClick = (() => $('.download').click(function() {
$('.start-download a').remove();
$('.start-download br').after(`<a href="${this.href}">${this.href.split('/').slice(-1)[0]}</a>`);
$('.start-download').attr('open', true);
}));

// 国际化 (internationalization)
al.setLangPropPath('locales');
Expand All @@ -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({
Expand All @@ -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);
// 自动展开/收起:<details> 元素
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;
};
// 通过检测 <summary> 元素
if ($(hash).html().startsWith('<summary>')) $(hash).attr('open', true);
else $(`${hash}>*:first-child`).addClass('hash');
} catch {};
});
$(window).on('hashchange', () => {
$('.hash').removeClass('hash');
hashChanged();
});


// 启动器数据
const launcherData = read('launcher');
// 各平台启动器数据
Expand All @@ -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 */
72 changes: 20 additions & 52 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,15 @@ const createUpdateLayer = ((abbr, lastVersion, latestVersion, download, device,
<div al="downloadedLauncherUpdate"></div>
<div>
<text class="abbr">${abbr}</text>
<text al="updatedTo"></text>
<text al="${flag}"></text>
<text class="latest-version">${latestVersion}</text><text al="exclamationMark"></text>
<text al="updatedTo"></text>
</div><div>
<text class="last-version">${lastVersion}</text>
<text al="updateArrow"></text>
<text class="latest-version">${latestVersion}</text>
</div>
<div>(${deviceInfo})</div>
<a class="download" href="${download}" target="_blank" al="download" ondragstart="event.dataTransfer.effectAllowed = 'none';"></a>
<a class="download" href="${downloadMirror(download)}" data-backup-href="${download}" target="_blank" al="download" ondragstart="event.dataTransfer.effectAllowed = 'none';"></a>
</div>`;
$('sidebar').before(dom);
$(`.update-layer-${updateLayerNumber} .download`).click(() => {
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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'));
});
};
Expand Down Expand Up @@ -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);
// 自动展开/收起:<details> 元素
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;
};
// 通过检测 <summary> 元素
if ($(hash).html().startsWith('<summary>')) $(hash).attr('open', true);
else $(`${hash}>*:first-child`).addClass('hash');
} catch {};
});
$(window).on('hashchange', () => {
$('.hash').removeClass('hash');
hashChanged();
});



// 获取正常状态的简体中文论坛
const CSForum = [{"简体中文论坛": []}];
Expand Down Expand Up @@ -543,6 +506,7 @@ $(document).ready(() => {
};
};
$('.update-layer').click(deleteUpdateLayer);
downloadClick();
i18n();
};
// 默认值初始化
Expand All @@ -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();

0 comments on commit 2773684

Please sign in to comment.