Skip to content

Commit 6cb5f0a

Browse files
committed
feat: plugin state lang
1 parent c2967ad commit 6cb5f0a

11 files changed

Lines changed: 133 additions & 19 deletions

File tree

index.js

Lines changed: 98 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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: / TREM-Lite >=([\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: / TREM-Lite =([\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;

info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "language",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": {
55
"zh_tw": "TREM-Lite Language Plugin"
66
},

lang/en-US/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,9 @@ html[lang="en-US"] {
232232
.current:empty:before {
233233
content: "Not set";
234234
}
235+
.extended-list-button[for="extended-state-list"]:before {
236+
content: "Extended Status";
237+
}
235238
.extended-list-button[for="extended-installed-list"]:before {
236239
content: "Extended List";
237240
}

lang/id-ID/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ html[lang="id-ID"] {
231231
.current:empty:before {
232232
content: "Tidak diatur";
233233
}
234+
.extended-list-button[for="extended-state-list"]:before {
235+
content: "Status Diperpanjang";
236+
}
234237
.extended-list-button[for="extended-installed-list"]:before {
235238
content: "Daftar Diperpanjang";
236239
}

lang/ja-JP/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ html[lang="ja-JP"] {
211211
.confirm-cancel::before {
212212
content: "取り消";
213213
}
214+
.extended-list-button[for="extended-state-list"]:before {
215+
content: "拡張機能ステート";
216+
}
214217
.extended-list-button[for="extended-installed-list"]:before {
215218
content: "拡張機能リスト";
216219
}

lang/ko-KR/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ html[lang="ko-KR"] {
231231
.current:empty:before {
232232
content: "설정 해제";
233233
}
234+
.extended-list-button[for="extended-state-list"]:before {
235+
content: "확장 상태";
236+
}
234237
.extended-list-button[for="extended-installed-list"]:before {
235238
content: "확장 목록";
236239
}

lang/th-TH/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ html[lang="th-TH"] {
234234
.current:empty:before {
235235
content: "ไม่ได้ตั้งค่า";
236236
}
237+
.extended-list-button[for="extended-state-list"]:before {
238+
content: "สถานะฟังก์ชั่นเพิ่มเติม";
239+
}
237240
.extended-list-button[for="extended-installed-list"]:before {
238241
content: "รายการฟังก์ชั่นเพิ่มเติม";
239242
}

lang/vi-VN/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ html[lang="vi-VN"] {
233233
.current:empty:before {
234234
content: "Chưa thiết lập";
235235
}
236+
.extended-list-button[for="extended-state-list"]:before {
237+
content: "Trạng thái mở rộng";
238+
}
236239
.extended-list-button[for="extended-installed-list"]:before {
237240
content: "Danh sách mở rộng";
238241
}

lang/zh-CN/setting/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ html[lang="zh-CN"] {
215215
.current:empty:before {
216216
content: "未设置";
217217
}
218+
.extended-list-button[for="extended-state-list"]:before {
219+
content: "扩充状态";
220+
}
218221
.extended-list-button[for="extended-installed-list"]:before {
219222
content: "扩充列表";
220223
}

language.trem

2.27 KB
Binary file not shown.

0 commit comments

Comments
 (0)