|
@@ -27,10 +27,10 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME = "data-single-file-selected-content-root";
|
|
const SELECTED_CONTENT_ROOT_ATTRIBUTE_NAME = "data-single-file-selected-content-root";
|
|
|
const DEBUG = false;
|
|
const DEBUG = false;
|
|
|
|
|
|
|
|
- let Download, docUtil, URL, cssTree, sessionId = 0;
|
|
|
|
|
|
|
+ let docUtil, cssTree, sessionId = 0;
|
|
|
|
|
|
|
|
function getClass(...args) {
|
|
function getClass(...args) {
|
|
|
- [Download, docUtil, URL, cssTree] = args;
|
|
|
|
|
|
|
+ [docUtil, cssTree] = args;
|
|
|
return SingleFileClass;
|
|
return SingleFileClass;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -283,7 +283,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const [resourceURL, asDataURI] = JSON.parse(requestKey);
|
|
const [resourceURL, asDataURI] = JSON.parse(requestKey);
|
|
|
const resourceRequests = this.requests.get(requestKey);
|
|
const resourceRequests = this.requests.get(requestKey);
|
|
|
try {
|
|
try {
|
|
|
- const content = await Download.getContent(resourceURL, { asDataURI, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
|
|
|
|
+ const content = await docUtil.getContent(resourceURL, { asDataURI, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
indexResource = indexResource + 1;
|
|
indexResource = indexResource + 1;
|
|
|
onloadListener({ index: indexResource, url: resourceURL });
|
|
onloadListener({ index: indexResource, url: resourceURL });
|
|
|
resourceRequests.forEach(resourceRequest => resourceRequest.resolve({ content: content.data, indexResource, duplicate: Boolean(resourceRequests.length > 1) }));
|
|
resourceRequests.forEach(resourceRequest => resourceRequest.resolve({ content: content.data, indexResource, duplicate: Boolean(resourceRequests.length > 1) }));
|
|
@@ -327,7 +327,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
async loadPage(pageContent) {
|
|
async loadPage(pageContent) {
|
|
|
let resourceURL;
|
|
let resourceURL;
|
|
|
if (!pageContent || this.options.saveRawPage) {
|
|
if (!pageContent || this.options.saveRawPage) {
|
|
|
- const content = await Download.getContent(this.baseURI, { asDataURI: false, maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
|
|
|
|
+ const content = await docUtil.getContent(this.baseURI, { asDataURI: false, maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
pageContent = content.data;
|
|
pageContent = content.data;
|
|
|
this.baseURI = this.options.url = resourceURL;
|
|
this.baseURI = this.options.url = resourceURL;
|
|
|
}
|
|
}
|
|
@@ -337,7 +337,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
|
|
|
|
|
async getPageData() {
|
|
async getPageData() {
|
|
|
docUtil.postProcessDoc(this.doc, this.options);
|
|
docUtil.postProcessDoc(this.doc, this.options);
|
|
|
- const url = new URL(this.baseURI);
|
|
|
|
|
|
|
+ const url = docUtil.parseURL(this.baseURI);
|
|
|
if (this.options.insertSingleFileComment) {
|
|
if (this.options.insertSingleFileComment) {
|
|
|
const infobarContent = (this.options.infobarContent || "").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
|
|
const infobarContent = (this.options.infobarContent || "").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
|
|
|
const commentNode = this.doc.createComment("\n Page saved with SingleFile" +
|
|
const commentNode = this.doc.createComment("\n Page saved with SingleFile" +
|
|
@@ -593,7 +593,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const normalizedHref = DomUtil.normalizeURL(href);
|
|
const normalizedHref = DomUtil.normalizeURL(href);
|
|
|
if (element.tagName == "LINK") {
|
|
if (element.tagName == "LINK") {
|
|
|
try {
|
|
try {
|
|
|
- element.setAttribute("href", new URL(href, this.options.baseURI || this.options.url));
|
|
|
|
|
|
|
+ element.setAttribute("href", docUtil.resolveURL(href, this.options.baseURI || this.options.url));
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
if (element.tagName == "LINK") {
|
|
if (element.tagName == "LINK") {
|
|
|
element.setAttribute("href", EMPTY_URL);
|
|
element.setAttribute("href", EMPTY_URL);
|
|
@@ -601,7 +601,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
}
|
|
|
} else if (normalizedHref == href) {
|
|
} else if (normalizedHref == href) {
|
|
|
try {
|
|
try {
|
|
|
- element.setAttribute("href", new URL(normalizedHref, this.options.baseURI || this.options.url));
|
|
|
|
|
|
|
+ element.setAttribute("href", docUtil.resolveURL(normalizedHref, this.options.baseURI || this.options.url));
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// ignored
|
|
// ignored
|
|
|
}
|
|
}
|
|
@@ -869,7 +869,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("script[src]")).map(async scriptElement => {
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("script[src]")).map(async scriptElement => {
|
|
|
if (scriptElement.src) {
|
|
if (scriptElement.src) {
|
|
|
this.stats.add("processed", "scripts", 1);
|
|
this.stats.add("processed", "scripts", 1);
|
|
|
- const content = await Download.getContent(scriptElement.src, { asDataURI: false, maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
|
|
|
|
+ const content = await docUtil.getContent(scriptElement.src, { asDataURI: false, maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
scriptElement.textContent = content.data.replace(/<\//gi, "<\\/").replace(/\/>/gi, "\\/>");
|
|
scriptElement.textContent = content.data.replace(/<\//gi, "<\\/").replace(/\/>/gi, "\\/>");
|
|
|
}
|
|
}
|
|
|
scriptElement.removeAttribute("src");
|
|
scriptElement.removeAttribute("src");
|
|
@@ -1034,7 +1034,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
class DomProcessorHelper {
|
|
class DomProcessorHelper {
|
|
|
static async evalTemplate(template, options, content, dontReplaceSlash) {
|
|
static async evalTemplate(template, options, content, dontReplaceSlash) {
|
|
|
const date = new Date();
|
|
const date = new Date();
|
|
|
- const url = new URL(options.url);
|
|
|
|
|
|
|
+ const url = docUtil.parseURL(options.url);
|
|
|
template = await DomUtil.evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash);
|
|
template = await DomUtil.evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash);
|
|
|
template = await DomUtil.evalTemplateVariable(template, "page-language", () => options.info.lang || "No language", dontReplaceSlash);
|
|
template = await DomUtil.evalTemplateVariable(template, "page-language", () => options.info.lang || "No language", dontReplaceSlash);
|
|
|
template = await DomUtil.evalTemplateVariable(template, "page-description", () => options.info.description || "No description", dontReplaceSlash);
|
|
template = await DomUtil.evalTemplateVariable(template, "page-description", () => options.info.description || "No description", dontReplaceSlash);
|
|
@@ -1168,13 +1168,13 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
let resourceURL = DomUtil.normalizeURL(match.resourceURL);
|
|
let resourceURL = DomUtil.normalizeURL(match.resourceURL);
|
|
|
if (!DomUtil.testIgnoredPath(resourceURL) && DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
if (!DomUtil.testIgnoredPath(resourceURL) && DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
|
try {
|
|
try {
|
|
|
- resourceURL = new URL(match.resourceURL, baseURI).href;
|
|
|
|
|
|
|
+ resourceURL = docUtil.resolveURL(match.resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// ignored
|
|
// ignored
|
|
|
}
|
|
}
|
|
|
if (DomUtil.testValidURL(resourceURL, baseURI, options.url)) {
|
|
if (DomUtil.testValidURL(resourceURL, baseURI, options.url)) {
|
|
|
const downloadOptions = { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled, validateTextContentType: true };
|
|
const downloadOptions = { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled, validateTextContentType: true };
|
|
|
- const content = await Download.getContent(resourceURL, downloadOptions);
|
|
|
|
|
|
|
+ const content = await docUtil.getContent(resourceURL, downloadOptions);
|
|
|
resourceURL = content.resourceURL;
|
|
resourceURL = content.resourceURL;
|
|
|
let importedStylesheetContent = DomUtil.removeCssComments(content.data);
|
|
let importedStylesheetContent = DomUtil.removeCssComments(content.data);
|
|
|
if (options.compressCSS) {
|
|
if (options.compressCSS) {
|
|
@@ -1201,7 +1201,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
|
let resolvedURL;
|
|
let resolvedURL;
|
|
|
try {
|
|
try {
|
|
|
- resolvedURL = new URL(resourceURL, baseURI).href;
|
|
|
|
|
|
|
+ resolvedURL = docUtil.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// ignored
|
|
// ignored
|
|
|
}
|
|
}
|
|
@@ -1233,7 +1233,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
resourceURL = DomUtil.normalizeURL(resourceURL);
|
|
resourceURL = DomUtil.normalizeURL(resourceURL);
|
|
|
if (resourceURL && resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
if (resourceURL && resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
const downloadOptions = { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled, charset: options.charset };
|
|
const downloadOptions = { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled, charset: options.charset };
|
|
|
- const content = await Download.getContent(resourceURL, downloadOptions);
|
|
|
|
|
|
|
+ const content = await docUtil.getContent(resourceURL, downloadOptions);
|
|
|
resourceURL = content.resourceURL;
|
|
resourceURL = content.resourceURL;
|
|
|
let stylesheetContent = DomUtil.removeCssComments(content.data);
|
|
let stylesheetContent = DomUtil.removeCssComments(content.data);
|
|
|
if (options.compressCSS) {
|
|
if (options.compressCSS) {
|
|
@@ -1341,7 +1341,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
|
try {
|
|
try {
|
|
|
- resourceURL = new URL(resourceURL, baseURI).href;
|
|
|
|
|
|
|
+ resourceURL = docUtil.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// ignored
|
|
// ignored
|
|
|
}
|
|
}
|
|
@@ -1379,7 +1379,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url) && !DomUtil.testIgnoredPath(resourceURL)) {
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url) && !DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
try {
|
|
try {
|
|
|
- resourceURL = new URL(resourceURL, baseURI).href;
|
|
|
|
|
|
|
+ resourceURL = docUtil.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// ignored
|
|
// ignored
|
|
|
}
|
|
}
|
|
@@ -1420,7 +1420,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
if (DomUtil.testValidPath(resourceURL, baseURI, options.url)) {
|
|
|
try {
|
|
try {
|
|
|
- resourceURL = new URL(resourceURL, baseURI).href;
|
|
|
|
|
|
|
+ resourceURL = docUtil.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
// ignored
|
|
// ignored
|
|
|
}
|
|
}
|