(node: any)
| 182 | |
| 183 | // 检查节点内容是否主要为数字 |
| 184 | function isMainlyNumericContent(node: any): boolean { |
| 185 | if (!node || !node.textContent) return false; |
| 186 | |
| 187 | const text = node.textContent.trim(); |
| 188 | if (!text) return false; |
| 189 | |
| 190 | // 如果内容很短,且是纯数字格式,则跳过 |
| 191 | // 对于短文本,直接判断整体是否为数字格式 |
| 192 | if (text.length < 30 && isNumericContent(text)) return true; |
| 193 | |
| 194 | // 检查是否为用户名或用户ID格式 |
| 195 | if (isUserIdentifier(text)) return true; |
| 196 | |
| 197 | // 对于较长的内容,检查是否主要为数字格式 |
| 198 | // 处理节点可能含有多个文本子节点的情况 |
| 199 | // 这有助于更精确地识别混合内容中的数字部分 |
| 200 | const textNodes = []; |
| 201 | const walker = document.createTreeWalker(node, NodeFilter.SHOW_TEXT, null); |
| 202 | let textNode; |
| 203 | while (textNode = walker.nextNode()) { |
| 204 | const nodeText = textNode.textContent?.trim() || ''; |
| 205 | if (nodeText) { |
| 206 | textNodes.push(nodeText); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // 如果只有一个文本节点且为数字,则跳过翻译 |
| 211 | if (textNodes.length === 1 && isNumericContent(textNodes[0])) return true; |
| 212 | |
| 213 | // 如果所有文本节点都是数字,则跳过翻译 |
| 214 | // 这可能是表格中的数字列或者纯数字列表等 |
| 215 | if (textNodes.length > 0 && textNodes.every(t => isNumericContent(t))) return true; |
| 216 | |
| 217 | // 否则不跳过,允许翻译 |
| 218 | return false; |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * 检查文本是否为用户标识符(用户名、ID等) |
no test coverage detected