File tree Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Expand file tree Collapse file tree 4 files changed +60
-3
lines changed Original file line number Diff line number Diff line change 22< html lang ="zh-CN ">
33 < head >
44 < meta charset ="utf-8 " />
5- < link rel ="icon " href ="%PUBLIC_URL%/favicon.ico " />
5+ < link rel ="icon " href ="%PUBLIC_URL%/logo.png " />
66 < meta name ="viewport " content ="width=device-width, initial-scale=1 " />
7- < meta name ="theme-color " content ="#3b82f6 " />
7+ < meta name ="theme-color " content ="#4f46e5 " />
88 < meta
99 name ="description "
1010 content ="Typescript Userscript Template - 使用TypeScript开发油猴脚本的现代化模板 "
1111 />
12- < link rel ="apple-touch-icon " href ="%PUBLIC_URL%/logo192 .png " />
12+ < link rel ="apple-touch-icon " href ="%PUBLIC_URL%/logo .png " />
1313 < link rel ="manifest " href ="%PUBLIC_URL%/manifest.json " />
1414 < link rel ="preconnect " href ="https://fonts.googleapis.com ">
1515 < link rel ="preconnect " href ="https://fonts.gstatic.com " crossorigin >
1616 < link href ="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap " rel ="stylesheet ">
1717 < link href ="https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500&display=swap " rel ="stylesheet ">
18+ < link href ="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap " rel ="stylesheet ">
19+ <!-- Google tag (gtag.js) -->
20+ < script async src ="https://www.googletagmanager.com/gtag/js?id=G-JN2B8D9NZ4 "> </ script >
21+ < script >
22+ window . dataLayer = window . dataLayer || [ ] ;
23+ function gtag ( ) { dataLayer . push ( arguments ) ; }
24+ gtag ( 'js' , new Date ( ) ) ;
25+
26+ gtag ( 'config' , 'G-JN2B8D9NZ4' ) ;
27+ </ script >
1828 < title > Typescript Userscript Template | 油猴脚本开发模板</ title >
1929 </ head >
2030 < body >
Original file line number Diff line number Diff line change 1+ {
2+ "short_name" : " TS UserScript" ,
3+ "name" : " TypeScript UserScript Template" ,
4+ "icons" : [
5+ {
6+ "src" : " favicon.svg" ,
7+ "sizes" : " 64x64 32x32 24x24 16x16" ,
8+ "type" : " image/svg+xml"
9+ }
10+ ],
11+ "start_url" : " ." ,
12+ "display" : " standalone" ,
13+ "theme_color" : " #4f46e5" ,
14+ "background_color" : " #ffffff"
15+ }
Original file line number Diff line number Diff line change 1+ const fs = require ( 'fs' ) ;
2+ const path = require ( 'path' ) ;
3+
4+ // 读取 package.json
5+ const packageJson = JSON . parse ( fs . readFileSync ( 'package.json' , 'utf-8' ) ) ;
6+
7+ // 读取原始的油猴头
8+ const originalHeader = fs . readFileSync ( 'userscript-headers.js' , 'utf-8' ) ;
9+
10+ // 替换变量,添加默认值处理
11+ let devHeader = originalHeader
12+ . replace ( / \$ { name} / g, packageJson . name || '' )
13+ . replace ( / \$ { repository} / g, packageJson . repository || '' )
14+ . replace ( / \$ { version} / g, packageJson . version || '' )
15+ . replace ( / \$ { description} / g, packageJson . description || '' )
16+ . replace ( / \$ { document} / g, packageJson . document || '' )
17+ . replace ( / \$ { author} / g, packageJson . author || '' ) ;
18+
19+ // 在最后一行前添加 @require
20+ devHeader = devHeader . replace (
21+ '// ==/UserScript==' ,
22+ `// @require file://${ process . cwd ( ) } /dist/index.js\n// ==/UserScript==`
23+ ) ;
24+
25+ // 确保 dist 目录存在
26+ if ( ! fs . existsSync ( 'dist' ) ) {
27+ fs . mkdirSync ( 'dist' ) ;
28+ }
29+
30+ // 写入开发版本的油猴头
31+ fs . writeFileSync ( 'dist/userscript-headers.dev.js' , devHeader ) ;
32+ console . log ( 'Development userscript header generated successfully!' ) ;
You can’t perform that action at this time.
0 commit comments