|
1 | 1 | // ==UserScript== |
2 | | -// @name TechPowerUp CPU/GPU Specs - Simplified Chinese |
3 | | -// @name:zh TechPowerUp CPU/GPU规格中文化 |
4 | | -// @namespace https://github.com/jc3213/userscript |
5 | | -// @version 0.5 |
6 | | -// @description Translate TechPowerUp CPU, and GPU Specs into Simplified Chinese |
7 | | -// @description:zh 将TechPowerUp关于CPU和GPU规格的相关网页进行中文化 |
8 | | -// @author jc3213 |
9 | | -// @match https://www.techpowerup.com/cpu-specs/* |
10 | | -// @match https://www.techpowerup.com/gpu-specs/* |
| 2 | +// @name TechPowerUp CPU/GPU规格中文化 |
| 3 | +// @namespace https://github.com/jc3213/userscript |
| 4 | +// @version 0.6 |
| 5 | +// @description 将TechPowerUp关于CPU和GPU规格的相关网页进行中文化 |
| 6 | +// @author jc3213 |
| 7 | +// @match https://www.techpowerup.com/cpu-specs/* |
| 8 | +// @match https://www.techpowerup.com/gpu-specs/* |
11 | 9 | // ==/UserScript== |
12 | 10 |
|
13 | 11 | const locale = { |
@@ -55,14 +53,15 @@ const locale = { |
55 | 53 | 'Launch MSRP:': '首发定价:', |
56 | 54 | 'Bundled Cooler:': '捆绑散热器:', |
57 | 55 | 'Codename:': '研发代号:', |
58 | | - 'Generation:': '产品时代:', |
| 56 | + 'Generation:': '产品世代:', |
59 | 57 | 'Part#:': '钢印编号:', |
60 | 58 | 'PPT:': '典型功耗:', |
61 | 59 | 'Memory Support:': '内存支持:', |
62 | 60 | 'DDR4 Speed:': 'DDR4 频率:', |
63 | 61 | 'DDR5 Speed:': 'DDR5 频率:', |
64 | 62 | 'Rated Speed:': '内存频率:', |
65 | 63 | 'Memory Bus:': '内存通道:', |
| 64 | + 'Memory Bandwidth:': '内存带宽:', |
66 | 65 | 'Dual-channel': '双通道', |
67 | 66 | 'Eight-channel': '八通道', |
68 | 67 | 'ECC Memory:': '内存纠错:', |
@@ -156,31 +155,36 @@ const locale = { |
156 | 155 |
|
157 | 156 | const i18nMap = { |
158 | 157 | 'table': (table) => { |
159 | | - [...table.children[0].children].forEach((tr) => [...tr.children].forEach(i18nElement)); |
| 158 | + for (let tr of table.children[0].children) { |
| 159 | + for (let el of tr.children) { |
| 160 | + i18nElement(tr); |
| 161 | + } |
| 162 | + } |
160 | 163 | }, |
161 | 164 | 'div': (table) => { |
162 | | - [...table.children].forEach((tr) => [...tr.children].forEach(i18nElement)); |
| 165 | + for (let tr of table.children) { |
| 166 | + i18nElement(tr); |
| 167 | + } |
163 | 168 | } |
164 | 169 | }; |
165 | 170 |
|
166 | 171 | setTimeout(() => { |
167 | | - const section = [...document.querySelectorAll('section')]; |
168 | | - |
169 | | - const details = section.slice(0, -1); |
170 | | - |
171 | | - details.forEach((detail) => { |
| 172 | + const details = [...document.querySelectorAll('section')].slice(0, -1); |
| 173 | + for (let detail of details) { |
172 | 174 | let [li, table] = detail.children; |
173 | 175 | i18nElement(li); |
174 | 176 | i18nMap[table.localName]?.(table); |
175 | | - }); |
| 177 | + } |
176 | 178 | }, 500); |
177 | 179 |
|
178 | | -function i18nElement(el) { |
179 | | - let text = el.innerText; |
180 | | - let i18n = locale[text]; |
181 | | - if (i18n) { |
182 | | - el.innerText = i18n; |
183 | | - } else { |
184 | | - console.log(text, i18n); |
| 180 | +function i18nElement(tr) { |
| 181 | + for (let el of tr.children) { |
| 182 | + let text = el.innerText; |
| 183 | + let i18n = locale[text]; |
| 184 | + if (i18n) { |
| 185 | + el.innerText = i18n; |
| 186 | + } else { |
| 187 | + console.log(text, i18n); |
| 188 | + } |
185 | 189 | } |
186 | 190 | } |
0 commit comments