mirror of
https://github.com/lllyasviel/Fooocus.git
synced 2026-08-16 13:13:16 +02:00
safe check
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
var re_num = /^[.\d]+$/;
|
||||||
|
|
||||||
var original_lines = {};
|
var original_lines = {};
|
||||||
var translated_lines = {};
|
var translated_lines = {};
|
||||||
|
|
||||||
@@ -11,6 +13,15 @@ function textNodesUnder(el) {
|
|||||||
return a;
|
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) {
|
function getTranslation(text) {
|
||||||
if (!text) return undefined;
|
if (!text) return undefined;
|
||||||
|
|
||||||
@@ -28,6 +39,9 @@ function getTranslation(text) {
|
|||||||
|
|
||||||
function processTextNode(node) {
|
function processTextNode(node) {
|
||||||
var text = node.textContent.trim();
|
var text = node.textContent.trim();
|
||||||
|
|
||||||
|
if (!canBeTranslated(node, text)) return;
|
||||||
|
|
||||||
var tl = getTranslation(text);
|
var tl = getTranslation(text);
|
||||||
if (tl !== undefined) {
|
if (tl !== undefined) {
|
||||||
node.textContent = tl;
|
node.textContent = tl;
|
||||||
|
|||||||
Reference in New Issue
Block a user