多语言文案测试-脚本扫描小工具
发布时间:2026/8/21 7:53:27 作者:尧图编辑部 阅读量:1,286

多语言文案测试-全量页面脚本扫描小工具使用方法 提示在 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/altdocument.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, 位置: ‘’ });br/ }// 输出结果if (results.length 0) {console.warn(⚠️ 共发现 ${results.length} 处中文残留);console.table(results);} else {console.log(‘✅ 当前页面无中文残留’);}return results;}deepScan();