safe check

This commit is contained in:
lllyasviel 2023-10-20 17:58:26 -07:00
parent 9b0dc625fa
commit 60c05342b2
1 changed files with 14 additions and 0 deletions

View File

@ -1,3 +1,5 @@
var re_num = /^[.\d]+$/;
var original_lines = {};
var translated_lines = {};
@ -11,6 +13,15 @@ function textNodesUnder(el) {
return a;
}
function canBeTranslated(node, text) {
if (!text) return false;
if (!node.parentElement) return false;
var parentType = node.parentElement.nodeName;
if (parentType == 'SCRIPT' || parentType == 'STYLE' || parentType == 'TEXTAREA') return false;
if (re_num.test(text)) return false;
return true;
}
function getTranslation(text) {
if (!text) return undefined;
@ -28,6 +39,9 @@ function getTranslation(text) {
function processTextNode(node) {
var text = node.textContent.trim();
if (!canBeTranslated(node, text)) return;
var tl = getTranslation(text);
if (tl !== undefined) {
node.textContent = tl;