keep selector support for sub-element
This commit is contained in:
@@ -392,8 +392,8 @@ export const I18N = {
|
|||||||
en: `Keep unchanged selector`,
|
en: `Keep unchanged selector`,
|
||||||
},
|
},
|
||||||
keep_selector_helper: {
|
keep_selector_helper: {
|
||||||
zh: `1、遵循CSS选择器语法。2、留空表示采用全局设置。`,
|
zh: `1、遵循CSS选择器语法。2、留空表示采用全局设置。3、子元素选择器用“>>>”隔开。`,
|
||||||
en: `1. Follow CSS selector syntax. 2. Leave blank to adopt the global setting.`,
|
en: `1. Follow CSS selector syntax. 2. Leave blank to adopt the global setting. 3.Sub-element selectors are separated by ">>>".`,
|
||||||
},
|
},
|
||||||
root_selector: {
|
root_selector: {
|
||||||
zh: `根选择器`,
|
zh: `根选择器`,
|
||||||
|
|||||||
@@ -396,10 +396,15 @@ export class Translator {
|
|||||||
|
|
||||||
const keepSelector = this._rule.keepSelector || "";
|
const keepSelector = this._rule.keepSelector || "";
|
||||||
const keeps = [];
|
const keeps = [];
|
||||||
if (keepSelector.trim()) {
|
const [matchSelector, subSelector] = keepSelector.split(SHADOW_KEY);
|
||||||
|
if (matchSelector.trim() || subSelector?.trim()) {
|
||||||
let text = "";
|
let text = "";
|
||||||
el.childNodes.forEach((child) => {
|
el.childNodes.forEach((child) => {
|
||||||
if (child.nodeType === 1 && child.matches(keepSelector)) {
|
if (
|
||||||
|
child.nodeType === 1 &&
|
||||||
|
((matchSelector.trim() && child.matches(matchSelector)) ||
|
||||||
|
(subSelector?.trim() && child.querySelector(subSelector)))
|
||||||
|
) {
|
||||||
if (child.nodeName === "IMG") {
|
if (child.nodeName === "IMG") {
|
||||||
child.style.cssText += `width: ${child.width}px;`;
|
child.style.cssText += `width: ${child.width}px;`;
|
||||||
child.style.cssText += `height: ${child.height}px;`;
|
child.style.cssText += `height: ${child.height}px;`;
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ function brFixer(node, tag = "p") {
|
|||||||
html += `</${tag}>${child.outerHTML}<${tag} class="kiss-p">`;
|
html += `</${tag}>${child.outerHTML}<${tag} class="kiss-p">`;
|
||||||
} else if (child.outerHTML) {
|
} else if (child.outerHTML) {
|
||||||
html += child.outerHTML;
|
html += child.outerHTML;
|
||||||
} else if (child.nodeValue) {
|
} else if (child.textContent) {
|
||||||
html += child.nodeValue;
|
html += child.textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (index === node.childNodes.length - 1) {
|
if (index === node.childNodes.length - 1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user