single-file-core 1.10.1 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/index.js +28 -0
- package/package.json +1 -1
package/core/index.js
CHANGED
|
@@ -117,6 +117,7 @@ const STAGES = [{
|
|
|
117
117
|
{ action: "setInputValues" },
|
|
118
118
|
{ option: "moveStylesInHead", action: "moveStylesInHead" },
|
|
119
119
|
{ option: "blockScripts", action: "removeEmbedScripts" },
|
|
120
|
+
{ option: "selectedElementsSelector", action: "selectElements" },
|
|
120
121
|
{ option: "selected", action: "removeUnselectedElements" },
|
|
121
122
|
{ option: "blockVideos", action: "insertVideoPosters" },
|
|
122
123
|
{ option: "blockVideos", action: "insertVideoLinks" },
|
|
@@ -893,7 +894,33 @@ class Processor {
|
|
|
893
894
|
}
|
|
894
895
|
}
|
|
895
896
|
|
|
897
|
+
selectElements() {
|
|
898
|
+
let selectedElements = [];
|
|
899
|
+
try {
|
|
900
|
+
selectedElements = Array.from(this.doc.body.querySelectorAll(this.options.selectedElementsSelector));
|
|
901
|
+
} catch {
|
|
902
|
+
// ignored
|
|
903
|
+
}
|
|
904
|
+
if (selectedElements.length) {
|
|
905
|
+
selectedElements.forEach(element => {
|
|
906
|
+
markElement(element);
|
|
907
|
+
element.querySelectorAll("*").forEach(markElement);
|
|
908
|
+
let parentElement = element.parentElement;
|
|
909
|
+
while (parentElement) {
|
|
910
|
+
markElement(parentElement);
|
|
911
|
+
parentElement = parentElement.parentElement;
|
|
912
|
+
}
|
|
913
|
+
});
|
|
914
|
+
this.removeUnselectedElements();
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
function markElement(element) {
|
|
918
|
+
element.setAttribute(util.SELECTED_CONTENT_ATTRIBUTE_NAME, "");
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
896
922
|
removeUnselectedElements() {
|
|
923
|
+
this.doc.documentElement.removeAttribute(util.SELECTED_CONTENT_ATTRIBUTE_NAME);
|
|
897
924
|
removeUnmarkedElements(this.doc.body);
|
|
898
925
|
this.doc.body.removeAttribute(util.SELECTED_CONTENT_ATTRIBUTE_NAME);
|
|
899
926
|
|
|
@@ -1586,6 +1613,7 @@ class Processor {
|
|
|
1586
1613
|
options.saveFilenameTemplateData = false;
|
|
1587
1614
|
options.embeddedScript = null;
|
|
1588
1615
|
options.selected = false;
|
|
1616
|
+
options.selectedElementsSelector = null;
|
|
1589
1617
|
options.embeddedImage = null;
|
|
1590
1618
|
options.embeddedPdf = null;
|
|
1591
1619
|
options.url = frameData.baseURI;
|