Skip to content

Commit b1d3af7

Browse files
authored
v0.6: 提升速度
1 parent 2676de8 commit b1d3af7

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

TechPowerUp_Specs.user.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// ==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/*
119
// ==/UserScript==
1210

1311
const locale = {
@@ -55,14 +53,15 @@ const locale = {
5553
'Launch MSRP:': '首发定价:',
5654
'Bundled Cooler:': '捆绑散热器:',
5755
'Codename:': '研发代号:',
58-
'Generation:': '产品时代:',
56+
'Generation:': '产品世代:',
5957
'Part#:': '钢印编号:',
6058
'PPT:': '典型功耗:',
6159
'Memory Support:': '内存支持:',
6260
'DDR4 Speed:': 'DDR4 频率:',
6361
'DDR5 Speed:': 'DDR5 频率:',
6462
'Rated Speed:': '内存频率:',
6563
'Memory Bus:': '内存通道:',
64+
'Memory Bandwidth:': '内存带宽:',
6665
'Dual-channel': '双通道',
6766
'Eight-channel': '八通道',
6867
'ECC Memory:': '内存纠错:',
@@ -156,31 +155,36 @@ const locale = {
156155

157156
const i18nMap = {
158157
'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+
}
160163
},
161164
'div': (table) => {
162-
[...table.children].forEach((tr) => [...tr.children].forEach(i18nElement));
165+
for (let tr of table.children) {
166+
i18nElement(tr);
167+
}
163168
}
164169
};
165170

166171
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) {
172174
let [li, table] = detail.children;
173175
i18nElement(li);
174176
i18nMap[table.localName]?.(table);
175-
});
177+
}
176178
}, 500);
177179

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+
}
185189
}
186190
}

0 commit comments

Comments
 (0)