-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathi18n.js
More file actions
361 lines (339 loc) · 13.9 KB
/
Copy pathi18n.js
File metadata and controls
361 lines (339 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
(function() {
'use strict';
if (window.MGR_I18N && window.MGR_THEME) return;
const zh = {
appName: 'Gallery Reader',
appSubtitle: '多站点漫画阅读器',
appDescription: '面向 E-Hentai、ExHentai、nhentai、hitomi.la 和 Wnacg 的多站点阅读器。',
backToGallery: '返回画廊',
loadingTitle: '加载中...',
loading: '加载中',
page: '第 {page} 页',
shortcutsTitle: '快捷键',
shortcutsHint: '快捷键: ← → 翻页 | + - 缩放 | 0 重置 | 空格 下一页',
reverseReading: '反向阅读',
autoPage: '自动翻页(单击开关,Alt+单击设置间隔)',
autoScroll: '自动滚动(单击开始,Alt+单击设置速度)',
autoScrollRunning: '自动滚动中({speed}px/帧)- 单击停止,Alt+单击设置速度',
autoPageRunning: '自动翻页中({seconds}s)- 单击停止,Alt+单击设置间隔',
fullscreen: '全屏 (F11)',
toggleTheme: '切换主题',
readerSettings: '阅读设置',
closeSettings: '关闭设置',
layoutMode: '阅读布局',
singleHorizontal: '横向单页',
singleVertical: '纵向单页',
continuousHorizontal: '横向连续',
continuousVertical: '纵向连续',
continuousSettings: '连续布局',
verticalPadding: '纵向侧边留白',
horizontalGap: '横向图片间距',
verticalGap: '纵向图片间距',
performance: '图片加载',
preloadCount: '预加载页数',
pagesUnit: '页',
autoPaging: '自动翻页',
automation: '自动控制',
autoInterval: '翻页间隔',
secondsUnit: '秒',
scrollSpeed: '自动滚动速度',
pxPerFrameUnit: 'px/帧',
resetSettings: '恢复默认设置',
resetConfirm: '确定要恢复所有设置到默认值吗?',
setScrollSpeedPrompt: '设置自动滚动速度(px/帧,支持小数,建议 2-10)',
setPageIntervalPrompt: '设置翻页间隔(秒,支持小数)',
missingElements: '缺少必要 DOM 元素: {items}',
imageListEmpty: '错误:无法加载图片列表',
imageListEmptyAlert: '无法加载图片列表,请刷新页面重试。',
initFailedAlert: 'Gallery Reader 初始化失败: {message}\n\n请刷新页面重试。',
imagePageUrlMissing: '图片页面 URL 不存在',
imageUrlMissing: '图片 URL 不存在',
pageUrlMissing: '无法获取页面 URL',
fetchPageMissing: 'fetchPageImageUrl 函数不存在',
realImageUrlMissing: '无法获取真实图片 URL',
realImageUrlExtractFailed: '无法从页面提取图片 URL',
imageLoadFailed: '图片加载失败',
imageLoadTimeout: '图片加载超时',
unknownGallery: '未知画廊',
previousPage: '前一页',
currentPage: '当前页',
nextPage: '后一页',
previousPageTitle: '上一页 (←)',
nextPageTitle: '下一页 (→)',
retry: '重试',
close: '关闭',
launchFailed: '启动阅读器失败:{message}',
unsupportedSite: '非目标站点',
detecting: '检测中...',
running: '运行中',
extensionStatus: '扩展状态',
currentSite: '当前站点',
shortcuts: '快捷键',
features: '核心功能',
turnPage: '翻页',
homeEnd: '首页/末页',
toggleSidebar: '切换缩略图栏',
exitFullscreen: '退出全屏',
modernUi: '现代化 UI',
darkMode: '深色模式',
smartPreload: '智能图片预加载',
progressMemory: '阅读进度记忆',
responsiveLayout: '响应式布局',
keyboardMouse: '键盘/鼠标控制',
realLoadingProgress: '真实图片加载进度',
multiSiteSupport: '多站点支持',
options: '设置',
reloadPage: '刷新页面',
popupTagline: '现代化多站点阅读体验',
footer: 'Made for better reading',
optionsTitle: 'Gallery Reader 设置',
currentVersion: '当前版本:',
builtinStrategies: '以下策略已内置,暂不提供开关。',
debugMode: '调试模式(控制台日志)',
debugModeTip: '开启后会在控制台输出详细日志,可能影响性能。调试问题时可临时开启。',
thumbnailFallback: '缩略图:使用画廊小图回退',
nlFallback: '图片失败:nl-token 镜像回退',
keyF: '键盘:F 切换缩略图栏',
docsLinks: '文档:',
feedbackTip: '反馈问题时请附带控制台日志',
welcomeTitle: '欢迎使用 Gallery Reader',
welcomeSubtitle: '多站点阅读器(E-Hentai / ExHentai / nhentai / hitomi.la / Wnacg)',
openE: '表站 (e-hentai.org)',
openEx: '里站 (exhentai.org)',
openNh: 'nhentai.net',
openHitomi: 'hitomi.la',
openWnacg: '紳士漫畫',
siteSupport: '支持站点',
installation: '安装与调试',
installStep1: '打开 chrome://extensions/',
installStep2: '开启开发者模式',
installStep3: '点击“加载已解压的扩展程序”并选择项目目录',
installStep4: '修改代码后在扩展管理页点击刷新按钮',
hitomiNote: 'hitomi.la 和紳士漫畫现在会接管原生阅读入口,并使用原站图片列表和缩略图。',
readReadme: '打开 README',
openOptions: '打开设置'
};
const en = {
appName: 'Gallery Reader',
appSubtitle: 'Multi-site manga reader',
appDescription: 'A multi-site reader for E-Hentai, ExHentai, nhentai, hitomi.la, and Wnacg.',
backToGallery: 'Back to gallery',
loadingTitle: 'Loading...',
loading: 'Loading',
page: 'Page {page}',
shortcutsTitle: 'Shortcuts',
shortcutsHint: 'Shortcuts: ← → turn pages | + - zoom | 0 reset | Space next page',
reverseReading: 'Reverse reading direction',
autoPage: 'Auto page (click to toggle, Alt+click to set interval)',
autoScroll: 'Auto scroll (click to start, Alt+click to set speed)',
autoScrollRunning: 'Auto scrolling ({speed}px/frame) - click to stop, Alt+click to set speed',
autoPageRunning: 'Auto paging ({seconds}s) - click to stop, Alt+click to set interval',
fullscreen: 'Fullscreen (F11)',
toggleTheme: 'Toggle theme',
readerSettings: 'Reader Settings',
closeSettings: 'Close settings',
layoutMode: 'Reading Layout',
singleHorizontal: 'Single horizontal',
singleVertical: 'Single vertical',
continuousHorizontal: 'Continuous horizontal',
continuousVertical: 'Continuous vertical',
continuousSettings: 'Continuous Layout',
verticalPadding: 'Vertical side padding',
horizontalGap: 'Horizontal gap',
verticalGap: 'Vertical gap',
performance: 'Image Loading',
preloadCount: 'Prefetch pages',
pagesUnit: 'pages',
autoPaging: 'Auto Paging',
automation: 'Automation',
autoInterval: 'Page interval',
secondsUnit: 'sec',
scrollSpeed: 'Auto scroll speed',
pxPerFrameUnit: 'px/frame',
resetSettings: 'Reset settings',
resetConfirm: 'Reset all settings to defaults?',
setScrollSpeedPrompt: 'Set auto scroll speed (px/frame, decimals allowed, 2-10 recommended)',
setPageIntervalPrompt: 'Set page interval (seconds, decimals allowed)',
missingElements: 'Missing required DOM elements: {items}',
imageListEmpty: 'Error: unable to load image list',
imageListEmptyAlert: 'Unable to load the image list. Please refresh and try again.',
initFailedAlert: 'Gallery Reader failed to initialize: {message}\n\nPlease refresh and try again.',
imagePageUrlMissing: 'Image page URL is missing',
imageUrlMissing: 'Image URL is missing',
pageUrlMissing: 'Unable to get page URL',
fetchPageMissing: 'fetchPageImageUrl is missing',
realImageUrlMissing: 'Unable to get real image URL',
realImageUrlExtractFailed: 'Unable to extract image URL from the page',
imageLoadFailed: 'Image failed to load',
imageLoadTimeout: 'Image load timed out',
unknownGallery: 'Untitled gallery',
previousPage: 'Previous page',
currentPage: 'Current page',
nextPage: 'Next page',
previousPageTitle: 'Previous page (←)',
nextPageTitle: 'Next page (→)',
retry: 'Retry',
close: 'Close',
launchFailed: 'Failed to launch reader: {message}',
unsupportedSite: 'Unsupported site',
detecting: 'Detecting...',
running: 'Running',
extensionStatus: 'Extension status',
currentSite: 'Current site',
shortcuts: 'Shortcuts',
features: 'Core Features',
turnPage: 'Turn pages',
homeEnd: 'First/last page',
toggleSidebar: 'Toggle thumbnail bar',
exitFullscreen: 'Exit fullscreen',
modernUi: 'Modern UI',
darkMode: 'Dark mode',
smartPreload: 'Smart image preloading',
progressMemory: 'Reading progress memory',
responsiveLayout: 'Responsive layout',
keyboardMouse: 'Keyboard/mouse controls',
realLoadingProgress: 'Real image loading progress',
multiSiteSupport: 'Multi-site support',
options: 'Options',
reloadPage: 'Reload page',
popupTagline: 'Multi-site reading experience',
footer: 'Made for better reading',
optionsTitle: 'Gallery Reader Options',
currentVersion: 'Current version:',
builtinStrategies: 'These strategies are built in and are not configurable yet.',
debugMode: 'Debug mode (console logs)',
debugModeTip: 'When enabled, detailed logs are printed to the console and may affect performance. Turn it on only while debugging.',
thumbnailFallback: 'Thumbnails: fallback to gallery thumbnails',
nlFallback: 'Image failures: nl-token mirror fallback',
keyF: 'Keyboard: F toggles thumbnail bar',
docsLinks: 'Documentation:',
feedbackTip: 'Include console logs when reporting issues',
welcomeTitle: 'Welcome to Gallery Reader',
welcomeSubtitle: 'Multi-site reader (E-Hentai / ExHentai / nhentai / hitomi.la / Wnacg)',
openE: 'E-Hentai',
openEx: 'ExHentai',
openNh: 'nhentai.net',
openHitomi: 'hitomi.la',
openWnacg: 'Wnacg',
siteSupport: 'Supported Sites',
installation: 'Install and Debug',
installStep1: 'Open chrome://extensions/',
installStep2: 'Enable Developer mode',
installStep3: 'Click "Load unpacked" and choose this project folder',
installStep4: 'After editing code, click the reload button on the extension card',
hitomiNote: 'hitomi.la and Wnacg now take over native reader entries and use native image lists plus gallery thumbnails.',
readReadme: 'Open README',
openOptions: 'Open Options'
};
function detectLang() {
const candidates = [];
try {
if (chrome && chrome.i18n && chrome.i18n.getUILanguage) {
candidates.push(chrome.i18n.getUILanguage());
}
} catch {}
try {
candidates.push(navigator.language);
if (Array.isArray(navigator.languages)) candidates.push(...navigator.languages);
} catch {}
return candidates.some((lang) => /^zh(?:-|_|$)/i.test(String(lang || ''))) ? 'zh' : 'en';
}
const lang = detectLang();
const dict = lang === 'zh' ? zh : en;
function t(key, params) {
let text = dict[key] || en[key] || key;
if (params) {
for (const [name, value] of Object.entries(params)) {
text = text.replace(new RegExp(`\\{${name}\\}`, 'g'), String(value));
}
}
return text;
}
function applyI18n(root) {
const scope = root || document;
scope.querySelectorAll('[data-i18n]').forEach((el) => {
el.textContent = t(el.getAttribute('data-i18n'));
});
scope.querySelectorAll('[data-i18n-title]').forEach((el) => {
el.setAttribute('title', t(el.getAttribute('data-i18n-title')));
});
scope.querySelectorAll('[data-i18n-html]').forEach((el) => {
el.innerHTML = t(el.getAttribute('data-i18n-html'));
});
scope.querySelectorAll('[data-i18n-placeholder]').forEach((el) => {
el.setAttribute('placeholder', t(el.getAttribute('data-i18n-placeholder')));
});
if (document && document.documentElement) {
document.documentElement.lang = lang === 'zh' ? 'zh-CN' : 'en';
}
}
window.MGR_I18N = { lang, t, applyI18n };
const THEME_STORAGE_KEY = 'eh_reader_theme';
const themeListeners = new Set();
let currentTheme = 'dark';
function normalizeTheme(theme) {
return theme === 'light' ? 'light' : 'dark';
}
function applyTheme(theme) {
const nextTheme = normalizeTheme(theme);
const changed = nextTheme !== currentTheme;
currentTheme = nextTheme;
try {
const root = document && document.documentElement;
const isThemeSurface = root && typeof root.hasAttribute === 'function'
&& root.hasAttribute('data-mgr-theme-page');
if (isThemeSurface) {
root.dataset.mgrTheme = currentTheme;
root.style.colorScheme = currentTheme;
}
} catch {}
if (changed) {
themeListeners.forEach((listener) => {
try { listener(currentTheme); } catch {}
});
}
return currentTheme;
}
function getTheme() {
return currentTheme;
}
function setTheme(theme) {
const nextTheme = applyTheme(theme);
return new Promise((resolve) => {
try {
if (chrome && chrome.storage && chrome.storage.local) {
chrome.storage.local.set({ [THEME_STORAGE_KEY]: nextTheme }, () => resolve(nextTheme));
return;
}
} catch {}
resolve(nextTheme);
});
}
function subscribeTheme(listener) {
if (typeof listener !== 'function') return () => {};
themeListeners.add(listener);
try { listener(currentTheme); } catch {}
return () => themeListeners.delete(listener);
}
window.MGR_THEME = Object.freeze({
storageKey: THEME_STORAGE_KEY,
get: getTheme,
set: setTheme,
subscribe: subscribeTheme
});
// Apply the dark reader default synchronously so extension pages never flash white.
applyTheme(currentTheme);
try {
if (chrome && chrome.storage && chrome.storage.local) {
chrome.storage.local.get([THEME_STORAGE_KEY], (result) => {
applyTheme(result && result[THEME_STORAGE_KEY]);
});
}
if (chrome && chrome.storage && chrome.storage.onChanged) {
chrome.storage.onChanged.addListener((changes, areaName) => {
if (areaName !== 'local' || !changes || !changes[THEME_STORAGE_KEY]) return;
applyTheme(changes[THEME_STORAGE_KEY].newValue);
});
}
} catch {}
})();