多语言文案测试-脚本扫描小工具
多语言文案测试-全量页面脚本扫描小工具
使用方法:💡 提示:在 Console 中按 ↑ 可以调出上一次执行的代码,切换语言后直接按回车即可重复扫描,不用重新粘贴。
切换到 English → 粘贴脚本 → 回车 → 记录结果
切换到 Français → 粘贴脚本 → 回车 → 记录结果
切换到 Español → 粘贴脚本 → 回车 → 记录结果
…(每种语言重复)
// 增强版:扫描当前页面所有文本节点,包括title、placeholder、alt等
function deepScan() {
const results = [];
// 扫描可见文本
const walker = document.createTreeWalker(
document.body, NodeFilter.SHOW_TEXT, null, false
);
let node;
while (node = walker.nextNode()) {
const text = node.textContent.trim();
if (text && /[\u4e00-\u9fa5]/.test(text)) {
results.push({
类型: ‘文本内容’,
内容: text.substring(0, 50),
位置: node.parentElement.tagName + (node.parentElement.className ? ‘.’ + node.parentElement.className.split(’ ')[0] : ‘’)
});
}
}
// 扫描属性(placeholder/title/alt)
document.querySelectorAll(‘[placeholder], [title], [alt], [aria-label]’).forEach(el => {
[‘placeholder’, ‘title’, ‘alt’, ‘aria-label’].forEach(attr => {
const val = el.getAttribute(attr);
if (val && /[\u4e00-\u9fa5]/.test(val)) {
results.push({
类型:属性(${attr}),
内容: val.substring(0, 50),
位置: el.tagName + ‘#’ + (el.id || el.className?.split(’ ')[0] || ‘’)
});
}
});
});
// 扫描页面标题
if (/[\u4e00-\u9fa5]/.test(document.title)) {
results.push({ 类型: ‘页面标题’, 内容: document.title, 位置: ‘
// 输出结果
if (results.length > 0) {
console.warn(⚠️ 共发现 ${results.length} 处中文残留:);
console.table(results);
} else {
console.log(‘✅ 当前页面无中文残留’);
}
return results;
}
deepScan();
