فهرست منبع

moved code from content.js to single-file-core.js

Gildas 7 سال پیش
والد
کامیت
6f09d2c3b3
2فایلهای تغییر یافته به همراه24 افزوده شده و 24 حذف شده
  1. 0 24
      extension/core/content/content.js
  2. 24 0
      lib/single-file/single-file-core.js

+ 0 - 24
extension/core/content/content.js

@@ -108,8 +108,6 @@ this.singlefile.top = this.singlefile.top || (() => {
 	async function getOptions(options) {
 		options.doc = document;
 		options.win = window;
-		options.canvasData = getCanvasData();
-		options.emptyStyleRulesText = getEmptyStyleRulesText();
 		if (!options.removeFrames) {
 			options.framesData = await FrameTree.getFramesData();
 		}
@@ -135,28 +133,6 @@ this.singlefile.top = this.singlefile.top || (() => {
 		return options;
 	}
 
-	function getEmptyStyleRulesText() {
-		const textData = [];
-		document.querySelectorAll("style").forEach(styleElement => {
-			if (!styleElement.textContent) {
-				textData.push(Array.from(styleElement.sheet.cssRules).map(rule => rule.cssText).join("\n"));
-			}
-		});
-		return textData;
-	}
-
-	function getCanvasData() {
-		const canvasData = [];
-		document.querySelectorAll("canvas").forEach(canvasElement => {
-			try {
-				canvasData.push({ dataURI: canvasElement.toDataURL("image/png", ""), width: canvasElement.clientWidth, height: canvasElement.clientHeight });
-			} catch (error) {
-				canvasData.push(null);
-			}
-		});
-		return canvasData;
-	}
-
 	async function downloadPage(page, options) {
 		const response = await browser.runtime.sendMessage({ download: true, url: page.url, saveAs: options.confirmFilename, filename: page.filename });
 		if (response.notSupported) {

+ 24 - 0
lib/single-file/single-file-core.js

@@ -78,6 +78,8 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			this.options.url = this.options.url || this.options.doc.location.href;
 			this.processor = new DOMProcessor(options);
 			if (this.options.doc) {
+				this.options.canvasData = this.processor.getCanvasData();
+				this.options.emptyStyleRulesText = this.processor.getEmptyStyleRulesText();
 				this.processor.fixInlineScripts();
 				this.processor.disableNoscriptElements();
 				this.processor.hideNonMetadataContents();
@@ -396,6 +398,28 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			this.options.doc.querySelectorAll("[" + WIN_ID_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(WIN_ID_ATTRIBUTE_NAME));
 		}
 
+		getEmptyStyleRulesText() {
+			const textData = [];
+			this.options.doc.querySelectorAll("style").forEach(styleElement => {
+				if (!styleElement.textContent) {
+					textData.push(Array.from(styleElement.sheet.cssRules).map(rule => rule.cssText).join("\n"));
+				}
+			});
+			return textData;
+		}
+
+		getCanvasData() {
+			const canvasData = [];
+			this.options.doc.querySelectorAll("canvas").forEach(canvasElement => {
+				try {
+					canvasData.push({ dataURI: canvasElement.toDataURL("image/png", ""), width: canvasElement.clientWidth, height: canvasElement.clientHeight });
+				} catch (error) {
+					canvasData.push(null);
+				}
+			});
+			return canvasData;
+		}
+
 		enableDisabledNoscriptTags(noscriptTags) {
 			noscriptTags.forEach(element => {
 				const noscriptElement = this.options.doc.createElement("noscript");