Просмотр исходного кода

use globalThis instead of window

Gildas 5 лет назад
Родитель
Сommit
04bd6756c0
2 измененных файлов с 11 добавлено и 11 удалено
  1. 8 8
      extension/core/content/content-bootstrap.js
  2. 3 3
      extension/core/content/content.js

+ 8 - 8
extension/core/content/content-bootstrap.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, globalThis, window, addEventListener, removeEventListener, document, location, setTimeout, prompt, Node */
+/* global browser, globalThis, window, document, location, setTimeout, prompt, Node */
 
 const singlefile = globalThis.singlefileBootstrap;
 
@@ -102,7 +102,7 @@ function init() {
 async function initAutoSavePage(message) {
 	options = message.options;
 	if (document.readyState != "complete") {
-		await new Promise(resolve => window.addEventListener("load", resolve));
+		await new Promise(resolve => globalThis.addEventListener("load", resolve));
 	}
 	await autoSavePage();
 	if (options.autoSaveRepeat) {
@@ -128,14 +128,14 @@ async function autoSavePage() {
 			let frames = [];
 			let framesSessionId;
 			autoSaveTimeout = null;
-			if (!options.removeFrames && window.frames && window.frames.length) {
+			if (!options.removeFrames && globalThis.frames && globalThis.frames.length) {
 				frames = await singlefile.processors.frameTree.getAsync(options);
 			}
 			framesSessionId = frames && frames.sessionId;
 			if (options.userScriptEnabled && waitForUserScript) {
 				await waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
 			}
-			const docData = helper.preProcessDoc(document, window, options);
+			const docData = helper.preProcessDoc(document, globalThis, options);
 			savePage(docData, frames);
 			if (framesSessionId) {
 				singlefile.processors.frameTree.cleanup(framesSessionId);
@@ -153,11 +153,11 @@ async function autoSavePage() {
 function refresh() {
 	if (autoSaveEnabled && options && (options.autoSaveUnload || options.autoSaveLoadOrUnload)) {
 		if (!unloadListenerAdded) {
-			addEventListener("unload", onUnload);
+			globalThis.addEventListener("unload", onUnload);
 			unloadListenerAdded = true;
 		}
 	} else {
-		removeEventListener("unload", onUnload);
+		globalThis.removeEventListener("unload", onUnload);
 		unloadListenerAdded = false;
 	}
 }
@@ -167,13 +167,13 @@ function onUnload() {
 	if (!pageAutoSaved || options.autoSaveUnload) {
 		const waitForUserScript = window._singleFile_waitForUserScript;
 		let frames = [];
-		if (!options.removeFrames && window.frames && window.frames.length) {
+		if (!options.removeFrames && globalThis.frames && globalThis.frames.length) {
 			frames = singlefile.processors.frameTree.getSync(options);
 		}
 		if (options.userScriptEnabled && waitForUserScript) {
 			waitForUserScript(helper.ON_BEFORE_CAPTURE_EVENT_NAME);
 		}
-		const docData = helper.preProcessDoc(document, window, options);
+		const docData = helper.preProcessDoc(document, globalThis, options);
 		savePage(docData, frames);
 	}
 }

+ 3 - 3
extension/core/content/content.js

@@ -21,7 +21,7 @@
  *   Source.
  */
 
-/* global browser, document, globalThis, window, location, setTimeout */
+/* global browser, document, globalThis, location, setTimeout */
 
 import * as download from "./../common/download.js";
 import { fetch, frameFetch } from "./../../lib/single-file/fetch/content/content-fetch.js";
@@ -117,7 +117,7 @@ async function processPage(options) {
 	options.insertSingleFileComment = true;
 	options.insertCanonicalLink = true;
 	if (!options.saveRawPage) {
-		if (!options.removeFrames && frames && window.frames && window.frames.length) {
+		if (!options.removeFrames && frames && globalThis.frames && globalThis.frames.length) {
 			let frameTreePromise;
 			if (options.loadDeferredImages) {
 				frameTreePromise = new Promise(resolve => setTimeout(() => resolve(frames.getAsync(options)), options.loadDeferredImagesMaxIdleTime - frames.TIMEOUT_INIT_REQUEST_MESSAGE));
@@ -190,7 +190,7 @@ async function processPage(options) {
 	});
 	framesSessionId = options.frames && options.frames.sessionId;
 	const selectedFrame = options.frames && options.frames.find(frameData => frameData.requestedFrame);
-	options.win = window;
+	options.win = globalThis;
 	if (selectedFrame) {
 		options.content = selectedFrame.content;
 		options.url = selectedFrame.baseURI;