From e6bbaaa2ad52e3f919d92647708fbd8b926bfa19 Mon Sep 17 00:00:00 2001 From: hymbz Date: Wed, 21 Jun 2023 16:33:59 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20:zap:=20=E4=BC=98=E5=8C=96=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=8F=90=E7=A4=BA=E7=9A=84=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release.mjs | 21 ++++---- rollup.config.ts | 13 +++-- src/components/Toast/index.module.css | 1 + src/helper/useInit.tsx | 76 ++++++++++++--------------- 4 files changed, 55 insertions(+), 56 deletions(-) diff --git a/release.mjs b/release.mjs index 7d682f97..c7a8d9ac 100644 --- a/release.mjs +++ b/release.mjs @@ -18,6 +18,17 @@ const exec = (...commands) => { (async () => { if (process.argv.slice(2).includes('push')) { const { version } = packageJSON; + + // 打包代码 + exec('pnpm build'); + + // 将打包出来的脚本文件复制到根目录上 + shell.cp( + '-f', + path.join(__dirname, './dist/index.js'), + path.join(__dirname, './ComicRead.user.js'), + ); + // 提交上传更改 exec( 'git add .', @@ -50,14 +61,4 @@ const exec = (...commands) => { // 将最新的更改日志写入 LatestChange.md shell.echo(changelog).to('docs/LatestChange.md'); - - // 打包代码 - exec('pnpm build'); - - // 将打包出来的脚本文件复制到根目录上 - shell.cp( - '-f', - path.join(__dirname, './dist/index.js'), - path.join(__dirname, './ComicRead.user.js'), - ); })(); diff --git a/rollup.config.ts b/rollup.config.ts index 30f2a234..4082bcc8 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -195,18 +195,21 @@ export const buildOptions = ( switch (name) { case 'main': return `\`\n${fs - .readFileSync('./dist/cache/main.js') + .readFileSync(resolve(__dirname, 'dist/cache/main.js')) .toString() .replaceAll('\\', '\\\\') .replaceAll('`', '\\`') .replaceAll('${', '\\${')}\``; + case 'LatestChange': + return `\`\n${fs + .readFileSync(resolve(__dirname, `docs/LatestChange.md`)) + .toString()}\`;`; + default: return fs - .readFileSync( - resolve(__dirname, 'dist/cache/', `${name}.js`), - ) - ?.toString() + .readFileSync(resolve(__dirname, `dist/cache/${name}.js`)) + .toString() .replaceAll('require$1', 'require'); } }, diff --git a/src/components/Toast/index.module.css b/src/components/Toast/index.module.css index 6c7d59bb..cd6c89fa 100644 --- a/src/components/Toast/index.module.css +++ b/src/components/Toast/index.module.css @@ -74,6 +74,7 @@ & ul { margin: 0; + text-align: left; } } diff --git a/src/helper/useInit.tsx b/src/helper/useInit.tsx index 8c0608bb..4df9cbc4 100644 --- a/src/helper/useInit.tsx +++ b/src/helper/useInit.tsx @@ -4,7 +4,6 @@ import { useFab } from '../components/useComponents/Fab'; import { toast } from '../components/useComponents/Toast'; import { useSiteOptions } from './useSiteOptions'; import { useSpeedDial } from './useSpeedDial'; -import { request } from '.'; /** * 对所有支持站点页面的初始化操作的封装 @@ -34,46 +33,41 @@ export const useInit = async >( // 检查脚本的版本变化,提示用户 const version = await GM.getValue('Version'); if (version && version !== GM.info.script.version) { - (async () => { - const res = await request( - `https://cdn.jsdelivr.net/gh/hymbz/ComicReadScript@${GM.info.script.version}/docs/LatestChange.md`, - { errorText: '' }, - ); - toast( - () => ( - <> -

🥳 ComicRead 已更新到 v{GM.info.script.version}

-
- - {(mdText) => { - switch (mdText[0]) { - case '#': - return

{mdText.replace('### ', '')}

; - case '*': - return ( -
    - - {(item) =>
  • {item}
  • } -
    -
- ); - default: - return null; - } - }} -
-
- - ), - { - id: 'Version Tip', - type: 'custom', - duration: Infinity, - // 手动点击关掉通知后才不会再次弹出 - onDismiss: () => GM.setValue('Version', GM.info.script.version), - }, - ); - })(); + const latestChange = inject('LatestChange'); + toast( + () => ( + <> +

🥳 ComicRead 已更新到 v{GM.info.script.version}

+
+ + {(mdText) => { + switch (mdText[0]) { + case '#': + return

{mdText.replace('### ', '')}

; + case '*': + return ( +
    + + {(item) =>
  • {item}
  • } +
    +
+ ); + default: + return null; + } + }} +
+
+ + ), + { + id: 'Version Tip', + type: 'custom', + duration: Infinity, + // 手动点击关掉通知后才不会再次弹出 + onDismiss: () => GM.setValue('Version', GM.info.script.version), + }, + ); // 监听储存的版本数据的变动,如果和当前版本一致就关掉弹窗 // 防止在更新版本后一次性打开多个页面,不得不一个一个关过去