|
|
@@ -185,7 +185,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
async run() {
|
|
|
if (this.root) {
|
|
|
this.processor.initialize(this.batchRequest);
|
|
|
- this.onprogress(new ProgressEvent(RESOURCES_INITIALIZED, { pageURL: this.options.url, index: 0, max: this.processor.maxResources }));
|
|
|
+ this.onprogress(new ProgressEvent(RESOURCES_INITIALIZED, { pageURL: this.options.url, max: this.processor.maxResources }));
|
|
|
}
|
|
|
await this.batchRequest.run(detail => {
|
|
|
detail.pageURL = this.options.url;
|
|
|
@@ -303,7 +303,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
try {
|
|
|
const content = await util.getContent(resourceURL, { asDataURI, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
indexResource = indexResource + 1;
|
|
|
- onloadListener({ index: indexResource, url: resourceURL });
|
|
|
+ onloadListener({ url: resourceURL });
|
|
|
resourceRequests.forEach(callbacks => {
|
|
|
const duplicateCallbacks = this.duplicates.get(requestKey);
|
|
|
const duplicate = duplicateCallbacks && duplicateCallbacks.length > 1 && duplicateCallbacks.includes(callbacks);
|
|
|
@@ -311,7 +311,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
});
|
|
|
} catch (error) {
|
|
|
indexResource = indexResource + 1;
|
|
|
- onloadListener({ index: indexResource, url: resourceURL });
|
|
|
+ onloadListener({ url: resourceURL });
|
|
|
resourceRequests.forEach(resourceRequest => resourceRequest.reject(error));
|
|
|
}
|
|
|
}));
|
|
|
@@ -349,6 +349,9 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
if (!this.options.saveRawPage && !this.options.removeFrames && this.options.frames) {
|
|
|
this.options.frames.forEach(frameData => this.maxResources += frameData.maxResources || 0);
|
|
|
}
|
|
|
+ if (!this.options.removeImports && this.options.imports) {
|
|
|
+ this.options.imports.forEach(importData => this.maxResources += importData.maxResources || 0);
|
|
|
+ }
|
|
|
this.stats.set("processed", "resources", this.maxResources);
|
|
|
}
|
|
|
|
|
|
@@ -941,9 +944,6 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
|
|
|
async resolveHtmlImportURLs() {
|
|
|
const linkElements = Array.from(this.doc.querySelectorAll("link[rel=import][href]"));
|
|
|
- if (!this.relImportProcessors && !this.options.removeImports) {
|
|
|
- this.relImportProcessors = new Map();
|
|
|
- }
|
|
|
await Promise.all(linkElements.map(async linkElement => {
|
|
|
const resourceURL = linkElement.href;
|
|
|
linkElement.removeAttribute("href");
|
|
|
@@ -959,16 +959,16 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
options.url = resourceURL;
|
|
|
const attributeValue = linkElement.getAttribute(util.HTML_IMPORT_ATTRIBUTE_NAME);
|
|
|
if (attributeValue) {
|
|
|
- const content = options.imports[Number(linkElement.getAttribute(util.HTML_IMPORT_ATTRIBUTE_NAME))];
|
|
|
- options.content = content;
|
|
|
- if (!Util.testIgnoredPath(resourceURL) && Util.testValidPath(resourceURL)) {
|
|
|
- const processor = new Runner(options);
|
|
|
- if (!this.options.removeImports) {
|
|
|
- this.relImportProcessors.set(linkElement, processor);
|
|
|
+ const importData = options.imports[Number(attributeValue)];
|
|
|
+ if (importData) {
|
|
|
+ options.content = importData.content;
|
|
|
+ importData.processor = new Runner(options);
|
|
|
+ await importData.processor.loadPage();
|
|
|
+ await importData.processor.initialize();
|
|
|
+ if (!options.removeImports) {
|
|
|
+ importData.maxResources = importData.processor.batchRequest.getMaxResources();
|
|
|
}
|
|
|
- await processor.loadPage();
|
|
|
- await processor.initialize();
|
|
|
- processor.processor.stylesheets.forEach(stylesheet => {
|
|
|
+ importData.processor.processor.stylesheets.forEach(stylesheet => {
|
|
|
const importedStyleElement = this.doc.createElement("style");
|
|
|
linkElement.insertAdjacentElement("afterEnd", importedStyleElement);
|
|
|
this.stylesheets.set(importedStyleElement, stylesheet);
|
|
|
@@ -1108,16 +1108,19 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
async processHtmlImports() {
|
|
|
const linkElements = Array.from(this.doc.querySelectorAll("link[rel=import]"));
|
|
|
await Promise.all(linkElements.map(async linkElement => {
|
|
|
- const processor = this.relImportProcessors.get(linkElement);
|
|
|
- if (processor) {
|
|
|
- this.stats.add("processed", "HTML imports", 1);
|
|
|
- this.relImportProcessors.delete(linkElement);
|
|
|
- await processor.run();
|
|
|
- const pageData = await processor.getPageData();
|
|
|
- linkElement.setAttribute("href", "data:text/html," + pageData.content);
|
|
|
- this.stats.addAll(pageData);
|
|
|
- } else {
|
|
|
- this.stats.add("discarded", "HTML imports", 1);
|
|
|
+ const attributeValue = linkElement.getAttribute(util.HTML_IMPORT_ATTRIBUTE_NAME);
|
|
|
+ if (attributeValue) {
|
|
|
+ const importData = this.options.imports[Number(attributeValue)];
|
|
|
+ if (importData.processor) {
|
|
|
+ this.stats.add("processed", "HTML imports", 1);
|
|
|
+ await importData.processor.run();
|
|
|
+ const pageData = await importData.processor.getPageData();
|
|
|
+ linkElement.removeAttribute(util.HTML_IMPORT_ATTRIBUTE_NAME);
|
|
|
+ linkElement.setAttribute("href", "data:text/html," + pageData.content);
|
|
|
+ this.stats.addAll(pageData);
|
|
|
+ } else {
|
|
|
+ this.stats.add("discarded", "HTML imports", 1);
|
|
|
+ }
|
|
|
}
|
|
|
}));
|
|
|
}
|