|
@@ -21,7 +21,7 @@
|
|
|
* Source.
|
|
* Source.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-/* global browser, document, globalThis, location, setTimeout */
|
|
|
|
|
|
|
+/* global browser, document, globalThis, location, setTimeout, URL */
|
|
|
|
|
|
|
|
import * as download from "./../common/download.js";
|
|
import * as download from "./../common/download.js";
|
|
|
import { fetch, frameFetch } from "./../../lib/single-file/fetch/content/content-fetch.js";
|
|
import { fetch, frameFetch } from "./../../lib/single-file/fetch/content/content-fetch.js";
|
|
@@ -38,7 +38,7 @@ const SHARE_PAGE_BUTTON_MESSAGE = browser.i18n.getMessage("topPanelSharePageButt
|
|
|
const SHARE_SELECTION_BUTTON_MESSAGE = browser.i18n.getMessage("topPanelShareSelectionButton");
|
|
const SHARE_SELECTION_BUTTON_MESSAGE = browser.i18n.getMessage("topPanelShareSelectionButton");
|
|
|
const ERROR_TITLE_MESSAGE = browser.i18n.getMessage("topPanelError");
|
|
const ERROR_TITLE_MESSAGE = browser.i18n.getMessage("topPanelError");
|
|
|
|
|
|
|
|
-let processor, processing, downloadParser, openFileInfobar;
|
|
|
|
|
|
|
+let processor, processing, downloadParser, openFileInfobar, scrollY, transform, overflow;
|
|
|
|
|
|
|
|
setLabels({
|
|
setLabels({
|
|
|
EMBEDDED_IMAGE_BUTTON_MESSAGE,
|
|
EMBEDDED_IMAGE_BUTTON_MESSAGE,
|
|
@@ -50,7 +50,15 @@ setLabels({
|
|
|
if (!bootstrap || !bootstrap.initializedSingleFile) {
|
|
if (!bootstrap || !bootstrap.initializedSingleFile) {
|
|
|
singlefile.init({ fetch, frameFetch });
|
|
singlefile.init({ fetch, frameFetch });
|
|
|
browser.runtime.onMessage.addListener(message => {
|
|
browser.runtime.onMessage.addListener(message => {
|
|
|
- if (message.method == "content.save" || message.method == "content.cancelSave" || message.method == "content.download" || message.method == "content.getSelectedLinks" || message.method == "content.error" || message.method == "content.prompt") {
|
|
|
|
|
|
|
+ if (message.method == "content.save" ||
|
|
|
|
|
+ message.method == "content.cancelSave" ||
|
|
|
|
|
+ message.method == "content.download" ||
|
|
|
|
|
+ message.method == "content.getSelectedLinks" ||
|
|
|
|
|
+ message.method == "content.error" ||
|
|
|
|
|
+ message.method == "content.prompt" ||
|
|
|
|
|
+ message.method == "content.beginScrollTo" ||
|
|
|
|
|
+ message.method == "content.scrollTo" ||
|
|
|
|
|
+ message.method == "content.endScrollTo") {
|
|
|
return onMessage(message);
|
|
return onMessage(message);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -116,6 +124,26 @@ async function onMessage(message) {
|
|
|
if (message.method == "content.prompt") {
|
|
if (message.method == "content.prompt") {
|
|
|
return ui.prompt(message.message, message.value);
|
|
return ui.prompt(message.message, message.value);
|
|
|
}
|
|
}
|
|
|
|
|
+ if (message.method == "content.beginScrollTo") {
|
|
|
|
|
+ scrollY = globalThis.scrollY;
|
|
|
|
|
+ transform = document.documentElement.style.getPropertyValue("transform");
|
|
|
|
|
+ overflow = document.documentElement.style.getPropertyValue("overflow");
|
|
|
|
|
+ globalThis.scrollTo(0, 0);
|
|
|
|
|
+ document.documentElement.style.setProperty("transform", "translateY(0px)");
|
|
|
|
|
+ document.documentElement.style.setProperty("overflow", "hidden");
|
|
|
|
|
+ return {};
|
|
|
|
|
+ }
|
|
|
|
|
+ if (message.method == "content.scrollTo") {
|
|
|
|
|
+ document.documentElement.style.setProperty("transform", "translateY(-" + message.y + "px)");
|
|
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
|
|
+ return {};
|
|
|
|
|
+ }
|
|
|
|
|
+ if (message.method == "content.endScrollTo") {
|
|
|
|
|
+ globalThis.scrollTo(0, scrollY);
|
|
|
|
|
+ document.documentElement.style.setProperty("transform", transform);
|
|
|
|
|
+ document.documentElement.style.setProperty("overflow", overflow);
|
|
|
|
|
+ return {};
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -172,9 +200,27 @@ async function processPage(options) {
|
|
|
processor = new singlefile.SingleFile(options);
|
|
processor = new singlefile.SingleFile(options);
|
|
|
const preInitializationPromises = [];
|
|
const preInitializationPromises = [];
|
|
|
options.insertCanonicalLink = true;
|
|
options.insertCanonicalLink = true;
|
|
|
- let index = 0, maxIndex = 0;
|
|
|
|
|
- options.onprogress = event => {
|
|
|
|
|
|
|
+ let index = 0, maxIndex = 0, initializing;
|
|
|
|
|
+ options.onprogress = async event => {
|
|
|
|
|
+ const { options } = event.detail;
|
|
|
if (!processor.cancelled) {
|
|
if (!processor.cancelled) {
|
|
|
|
|
+ if (event.type == event.RESOURCES_INITIALIZING) {
|
|
|
|
|
+ if (!initializing && options.insertEmbeddedScreenshotImage && options.compressContent) {
|
|
|
|
|
+ initializing = true;
|
|
|
|
|
+ ui.setVisible(false);
|
|
|
|
|
+ const screenshotBlobURI = await browser.runtime.sendMessage({
|
|
|
|
|
+ method: "tabs.getScreenshot",
|
|
|
|
|
+ width: document.documentElement.scrollWidth,
|
|
|
|
|
+ height: document.documentElement.scrollHeight,
|
|
|
|
|
+ innerHeight: globalThis.innerHeight
|
|
|
|
|
+ });
|
|
|
|
|
+ ui.setVisible(true);
|
|
|
|
|
+ ui.onInsertingEmbeddedImage(options);
|
|
|
|
|
+ options.embeddedImage = new Uint8Array(await (await fetch(screenshotBlobURI)).arrayBuffer());
|
|
|
|
|
+ URL.revokeObjectURL(screenshotBlobURI);
|
|
|
|
|
+ ui.onInsertEmbeddedImage(options);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (event.type == event.RESOURCES_INITIALIZED) {
|
|
if (event.type == event.RESOURCES_INITIALIZED) {
|
|
|
maxIndex = event.detail.max;
|
|
maxIndex = event.detail.max;
|
|
|
if (options.loadDeferredImages) {
|
|
if (options.loadDeferredImages) {
|
|
@@ -185,7 +231,7 @@ async function processPage(options) {
|
|
|
if (event.type == event.RESOURCE_LOADED) {
|
|
if (event.type == event.RESOURCE_LOADED) {
|
|
|
index++;
|
|
index++;
|
|
|
}
|
|
}
|
|
|
- browser.runtime.sendMessage({ method: "ui.processProgress", index, maxIndex });
|
|
|
|
|
|
|
+ await browser.runtime.sendMessage({ method: "ui.processProgress", index, maxIndex });
|
|
|
ui.onLoadResource(index, maxIndex, options);
|
|
ui.onLoadResource(index, maxIndex, options);
|
|
|
} else if (!event.detail.frame) {
|
|
} else if (!event.detail.frame) {
|
|
|
if (event.type == event.PAGE_LOADING) {
|
|
if (event.type == event.PAGE_LOADING) {
|