-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsite-configs.js
More file actions
173 lines (160 loc) · 4.47 KB
/
site-configs.js
File metadata and controls
173 lines (160 loc) · 4.47 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
// 网站特定配置
let SITE_CONFIGS = {
// LibreOffice 翻译网站
'translations.documentfoundation.org': {
name: 'LibreOffice Weblate',
selectors: {
// 翻译文本区域选择器
translationTextarea: [
'textarea[name*="target"]',
'textarea[id*="target"]',
'.translation-form textarea:not([readonly])',
'textarea.target'
],
// 源文本选择器
sourceText: [
'[data-clone-value]', // 最准确的源文本
'.list-group-item-text span:not(.badge)', // 显示的文本内容
'.source-text',
'textarea[readonly]',
'.msgid',
'[class*="source"]',
'[class*="original"]'
],
// 表单容器
formContainer: 'form, .translation-form, .source-language-group'
},
// UI 注入配置
ui: {
buttonPosition: 'after', // after, before, inside
buttonClass: 'llm-weblate-btn',
containerClass: 'llm-weblate-container'
},
// 文本获取策略
textExtraction: {
// 获取源文本的方法优先级
sourceTextMethods: [
'dataCloneValue',
'listGroupItemText',
'readonlyTextarea',
'sourceElements',
'previousTextarea'
]
}
},
// LibreOffice 维基
'wiki.documentfoundation.org': {
name: 'LibreOffice Wiki',
selectors: {
// 翻译文本区域选择器
translationTextarea: [
'textarea.tux-textarea-translation.mw-editfont-monospace',
'textarea[class*="tux-textarea-translation"]'
],
// 源文本选择器
sourceText: [
'span.sourcemessage.mw-editfont-monospace',
'.twelve.columns.sourcemessage.mw-editfont-monospace',
'span[class*="sourcemessage"]'
],
// 表单容器
formContainer: '.seven.columns.editcolumn, .row.tux-editor-actions-block, .tux-editor-actions-block'
},
// UI 注入配置
ui: {
buttonPosition: 'after', // after, before, inside
buttonClass: 'llm-wiki-btn',
containerClass: 'llm-wiki-container'
},
// 文本获取策略
textExtraction: {
// 获取源文本的方法优先级
sourceTextMethods: [
'spanSourceText', // 从span元素获取源文本
'sourceElements'
]
}
},
// 默认配置(通用规则)
'default': {
name: 'Generic Site',
selectors: {
translationTextarea: [
'textarea[name*="target"]',
'textarea[name*="translation"]',
'textarea[class*="target"]',
'textarea[class*="translation"]',
'textarea:not([readonly]):not([disabled])'
],
sourceText: [
'[data-clone-value]',
'textarea[readonly]',
'textarea[disabled]',
'[class*="source"]',
'[class*="original"]',
'.source-text'
],
formContainer: 'form, .form, .translation-form'
},
ui: {
buttonPosition: 'after',
buttonClass: 'llm-generic-btn',
containerClass: 'llm-generic-container'
},
textExtraction: {
sourceTextMethods: [
'dataCloneValue',
'readonlyTextarea',
'sourceElements',
'previousTextarea'
]
}
}
};
SITE_CONFIGS['hosted.weblate.org'] = SITE_CONFIGS['translations.documentfoundation.org'];
SITE_CONFIGS['hosted.weblate.org'].name = 'Weblate';
// 检查当前站点是否被支持
function isSiteSupported(hostname) {
if (!hostname) {
return false;
}
// 精确匹配
if (SITE_CONFIGS[hostname] && hostname !== 'default') {
return true;
}
// 部分匹配
for (const domain in SITE_CONFIGS) {
if (domain !== 'default' && hostname.includes(domain)) {
return true;
}
}
return false;
}
// 获取当前网站配置
function getCurrentSiteConfig() {
const hostname = window.location.hostname;
// 精确匹配
if (SITE_CONFIGS[hostname]) {
return SITE_CONFIGS[hostname];
}
// 部分匹配
for (const domain in SITE_CONFIGS) {
if (domain !== 'default' && hostname.includes(domain)) {
return SITE_CONFIGS[domain];
}
}
// 返回默认配置
return SITE_CONFIGS['default'];
}
// 导出配置
if (typeof module !== 'undefined' && module.exports) {
module.exports = { SITE_CONFIGS, getCurrentSiteConfig, isSiteSupported };
} else {
window.SITE_CONFIGS = SITE_CONFIGS;
window.getCurrentSiteConfig = getCurrentSiteConfig;
window.isSiteSupported = isSiteSupported;
}
// 确保在浏览器环境中不返回任何值
if (typeof window !== 'undefined') {
undefined;
}