single-file-core 1.2.39 → 1.2.40

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/helper.js CHANGED
@@ -244,7 +244,7 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
244
244
  }
245
245
  getResourcesInfo(win, doc, element, options, data, elementHidden, computedStyle);
246
246
  const shadowRoot = !((element instanceof win.SVGElement) || (element instanceof globalThis.SVGElement)) && getShadowRoot(element);
247
- if (shadowRoot && !element.classList.contains(SINGLE_FILE_UI_ELEMENT_CLASS)) {
247
+ if (shadowRoot && !element.classList.contains(SINGLE_FILE_UI_ELEMENT_CLASS) && element.tagName.toLowerCase() != INFOBAR_TAGNAME) {
248
248
  const shadowRootInfo = {};
249
249
  element.setAttribute(SHADOW_ROOT_ATTRIBUTE_NAME, data.shadowRoots.length);
250
250
  data.markedElements.push(element);
package/core/index.js CHANGED
@@ -651,6 +651,10 @@ class Processor {
651
651
  }
652
652
 
653
653
  saveFilenameTemplateData() {
654
+ const existingScript = this.doc.querySelector("script[" + SCRIPT_OPTIONS + "][type=\"application/json\"]");
655
+ if (existingScript) {
656
+ existingScript.remove();
657
+ }
654
658
  const optionsElement = this.doc.createElement("script");
655
659
  optionsElement.type = "application/json";
656
660
  optionsElement.setAttribute(SCRIPT_OPTIONS, "");
@@ -1036,15 +1040,25 @@ class Processor {
1036
1040
  this.stats.set("discarded", "hidden elements", removedElements.length);
1037
1041
  this.stats.set("processed", "hidden elements", removedElements.length);
1038
1042
  if (hiddenElements.length) {
1039
- const styleElement = this.doc.createElement("style");
1040
- styleElement.textContent = ".sf-hidden{display:none!important;}";
1041
- this.doc.head.appendChild(styleElement);
1043
+ const className = "sf-hidden";
1044
+ const stylesheetContent = "." + className + "{display:none!important}";
1045
+ let foundStylesheet = false;
1046
+ this.doc.querySelectorAll("style").forEach(styleElement => {
1047
+ if (styleElement.textContent == stylesheetContent) {
1048
+ foundStylesheet = true;
1049
+ }
1050
+ });
1051
+ if (!foundStylesheet) {
1052
+ const styleElement = this.doc.createElement("style");
1053
+ styleElement.textContent = stylesheetContent;
1054
+ this.doc.head.appendChild(styleElement);
1055
+ }
1042
1056
  hiddenElements.forEach(element => {
1043
1057
  if (element.style.getPropertyValue("display") != "none") {
1044
1058
  if (element.style.getPropertyPriority("display") == "important") {
1045
1059
  element.style.setProperty("display", "none", "important");
1046
- } else {
1047
- element.classList.add("sf-hidden");
1060
+ } else if (!element.classList.contains(className)) {
1061
+ element.classList.add(className);
1048
1062
  }
1049
1063
  }
1050
1064
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.39",
3
+ "version": "1.2.40",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",