@@ -17,6 +17,57 @@ class Plugin {
1717 { value : 'id-ID' , text : 'Bahasa Indonesia' } ,
1818 { value : 'th-TH' , text : 'ภาษาไทย' } ,
1919 ] ;
20+ this . msgClassMap = {
21+ 'no-certificate' : {
22+ regex : / 未 發 現 有 效 簽 名 / ,
23+ translations : {
24+ 'en-US' : 'No valid certificate were found and you should deactivate this extension immediately unless you trust the source of this extension.' ,
25+ 'ja-JP' : '有効な証明書が見つからなかったので、この拡張機能の提供元を信頼しない限り、この拡張機能を直ちに無効にしてください。' ,
26+ 'zh-CN' : '未找到有效证书,除非您信任该扩展的来源,否则应立即停用该扩展。' ,
27+ 'ko-KR' : '유효한 인증서를 찾을 수 없으므로 이 확장 프로그램의 출처를 신뢰하지 않는 한 즉시 이 확장 프로그램을 비활성화해야 합니다。' ,
28+ 'vi-VN' : 'Không tìm thấy chứng chỉ hợp lệ nào và bạn nên hủy kích hoạt tiện ích mở rộng này ngay lập tức trừ khi bạn tin tưởng nguồn gốc của tiện ích mở rộng này。' ,
29+ 'id-ID' : 'Tidak ada sertifikat valid yang ditemukan dan Anda harus segera menonaktifkan ekstensi ini kecuali Anda memercayai sumber ekstensi ini.' ,
30+ 'th-TH' : 'ไม่พบใบรับรองที่ถูกต้อง และคุณควรปิดใช้งานส่วนขยายนี้ทันที เว้นแต่คุณจะเชื่อถือแหล่งที่มาของส่วนขยายนี้' ,
31+ }
32+ } ,
33+ 'version-low-greater' : {
34+ regex : / 需 要 至 少 T R E M - L i t e 的 版 本 為 > = ( [ \d . - \w ] + ) 以 上 , 但 目 前 安 裝 的 版 本 為 ( [ \d . - \w ] + ) 。 / ,
35+ translations : {
36+ 'en-US' : 'At least TREM-Lite version >={requiredVersion} is required, but the currently installed version is {installedVersion}.' ,
37+ 'ja-JP' : '少なくとも TREM-Lite のバージョン >={requiredVersion} が必要ですが、現在インストールされているバージョンは {installedVersion} です。' ,
38+ 'zh-CN' : '至少需要 TREM-Lite 版本 >={requiredVersion},但当前安装的版本为 {installedVersion}。' ,
39+ 'ko-KR' : 'TREM-Lite 버전 >={requiredVersion} 이상이 필요하지만 현재 설치된 버전은 {installedVersion} 입니다.' ,
40+ 'vi-VN' : 'Yêu cầu ít nhất là phiên bản TREM-Lite >={requiredVersion}, nhưng phiên bản hiện tại được cài đặt là {installedVersion}.' ,
41+ 'id-ID' : 'Setidaknya versi TREM-Lite >={requiredVersion} diperlukan, tetapi versi yang terinstal saat ini adalah {installedVersion}.' ,
42+ 'th-TH' : 'อย่างน้อยต้องมีเวอร์ชัน TREM-Lite >={requiredVersion} แต่เวอร์ชันที่ติดตั้งในปัจจุบันคือ {installedVersion}'
43+ }
44+ } ,
45+ 'version-low-equal' : {
46+ regex : / 需 要 至 少 T R E M - L i t e 的 版 本 為 = ( [ \d . - \w ] + ) 以 上 , 但 目 前 安 裝 的 版 本 為 ( [ \d . - \w ] + ) 。 / ,
47+ translations : {
48+ 'en-US' : 'At least TREM-Lite version ={requiredVersion} is required, but the currently installed version is {installedVersion}.' ,
49+ 'ja-JP' : '少なくとも TREM-Lite のバージョン ={requiredVersion} が必要ですが、現在インストールされているバージョンは {installedVersion} です。' ,
50+ 'zh-CN' : '至少需要 TREM-Lite 版本 ={requiredVersion},但当前安装的版本为 {installedVersion}。' ,
51+ 'ko-KR' : 'TREM-Lite 버전 ={requiredVersion} 이상이 필요하지만 현재 설치된 버전은 {installedVersion} 입니다.' ,
52+ 'vi-VN' : 'Yêu cầu ít nhất là phiên bản TREM-Lite ={requiredVersion}, nhưng phiên bản hiện tại được cài đặt là {installedVersion}.' ,
53+ 'id-ID' : 'Setidaknya versi TREM-Lite ={requiredVersion} diperlukan, tetapi versi yang terinstal saat ini adalah {installedVersion}.' ,
54+ 'th-TH' : 'อย่างน้อยต้องมีเวอร์ชัน TREM-Lite ={requiredVersion} แต่เวอร์ชันที่ติดตั้งในปัจจุบันคือ {installedVersion}'
55+ }
56+ } ,
57+ 'missing-dependencies' : {
58+ regex : / 缺 少 ( [ \d . - \w ] + ) 依 賴 。 / ,
59+ translations : {
60+ 'en-US' : 'Missing {requiredDependencies} dependencies.' ,
61+ 'ja-JP' : '{requiredDependencies} 依存関係がありません。' ,
62+ 'zh-CN' : '缺少 {requiredDependencies} 依赖项。' ,
63+ 'zh-Hant' : '缺少 {requiredDependencies} 依賴。' ,
64+ 'ko-KR' : '{requiredDependencies} 종속성이 누락되었습니다.' ,
65+ 'vi-VN' : 'Thiếu các phụ thuộc {requiredDependencies}.' ,
66+ 'id-ID' : 'Dependensi {requiredDependencies} hilang.' ,
67+ 'th-TH' : 'ขาดการอ้างอิง {requiredDependencies}'
68+ }
69+ }
70+ } ;
2071 }
2172
2273 async updateLanguage ( lang , updateStorage = true ) {
@@ -33,6 +84,9 @@ class Plugin {
3384 if ( lang !== 'zh-Hant' ) {
3485 await this . getLanguagePath ( currentPath , lang ) ;
3586 }
87+
88+ const pluginStatus = JSON . parse ( localStorage . getItem ( 'plugin-status' ) ) || [ ] ;
89+ this . generatePluginStatusCSS ( lang , pluginStatus ) ;
3690 }
3791
3892 async getLanguagePath ( currentPath , lang ) {
@@ -47,19 +101,57 @@ class Plugin {
47101 await this . loadCSS ( paths . index ) ;
48102 } else if ( currentPath . includes ( '/setting' ) ) {
49103 await this . loadCSS ( paths . setting ) ;
104+ const pluginStatus = JSON . parse ( localStorage . getItem ( 'plugin-status' ) ) || [ ] ;
105+ this . generatePluginStatusCSS ( this . lang , pluginStatus ) ;
50106 } else if ( currentPath . includes ( '/yaml' ) ) {
51107 await this . loadCSS ( paths . pluginEdit ) ;
52108 }
53109 }
54110
111+ generatePluginStatusCSS ( lang , pluginStatus ) {
112+ let cssRules = '' ;
113+ pluginStatus . forEach ( item => {
114+ for ( const [ className , { regex, translations } ] of Object . entries ( this . msgClassMap ) ) {
115+ const match = item . msg . match ( regex ) ;
116+ if ( match ) {
117+ let content = translations [ lang ] ;
118+ if ( ! content ) continue ;
119+ if ( className === 'version-low-greater' || className === 'version-low-equal' ) {
120+ const requiredVersion = match [ 1 ] ;
121+ const installedVersion = match [ 2 ] ;
122+ content = content && content
123+ . replace ( '{requiredVersion}' , requiredVersion )
124+ . replace ( '{installedVersion}' , installedVersion ) ;
125+ } else if ( className === 'missing-dependencies' ) {
126+ const requiredDependencies = match [ 1 ] ;
127+ content = content && content
128+ . replace ( '{requiredDependencies}' , requiredDependencies )
129+ }
130+ cssRules += `.${ className } ::before {
131+ content: "${ content && content . replace ( / " / g, '\\"' ) } " !important;
132+ font-weight: bold;
133+ }\n` ;
134+ break ;
135+ }
136+ }
137+ } ) ;
138+ const existingStyle = document . getElementById ( 'plugin-status-style' ) ;
139+ if ( existingStyle ) existingStyle . remove ( ) ;
140+ const styleElement = document . createElement ( 'style' ) ;
141+ styleElement . id = 'plugin-status-style' ;
142+ styleElement . textContent = cssRules ;
143+ document . head . appendChild ( styleElement ) ;
144+ }
145+
146+
55147 loadCSS ( href ) {
56148 return new Promise ( ( resolve , reject ) => {
57149 const link = document . createElement ( 'link' ) ;
58150 link . rel = 'stylesheet' ;
59151 link . href = href ;
60152 link . setAttribute ( 'rel' , 'preload' ) ;
61153 link . setAttribute ( 'as' , 'style' ) ;
62- if ( ! href . includes ( 'main' ) ) {
154+ if ( ! href . includes ( 'main' ) ) {
63155 link . setAttribute ( 'data-type' , 'plugin-lang' ) ;
64156 }
65157 link . onload = ( ) => {
@@ -73,7 +165,7 @@ class Plugin {
73165
74166 addDropDown ( ) {
75167 const thisElement = document . querySelector ( '#plugin-language .extended-list-buttons' ) ;
76- if ( thisElement ) {
168+ if ( thisElement ) {
77169 const box = document . createElement ( 'div' ) ;
78170 box . className = 'select-language-box' ;
79171 const select = document . createElement ( 'select' ) ;
@@ -95,7 +187,7 @@ class Plugin {
95187 if ( drop ) {
96188 drop . addEventListener ( 'change' , async ( ) => {
97189 const selectedType = drop . value ;
98- this . updateLanguage ( selectedType ) ;
190+ await this . updateLanguage ( selectedType ) ;
99191 } ) ;
100192 }
101193
@@ -123,14 +215,14 @@ class Plugin {
123215 this . addDropDown ( ) ;
124216 this . init ( ) ;
125217 } catch ( error ) {
126- logger . error ( 'CSS 載入失敗:' , error ) ;
218+ console . error ( 'CSS 載入失敗:' , error ) ;
127219 }
128220 }
129221
130222 async onLoad ( ) {
131223 this . initializeStyles ( ) ;
132- logger . info ( " Loading Language plugin..." ) ;
224+ console . info ( ' Loading Language plugin...' ) ;
133225 }
134226}
135227
136- module . exports = Plugin ;
228+ module . exports = Plugin ;
0 commit comments