|
@@ -18,12 +18,11 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-/* global browser, SingleFile, singlefile, frameTree, document, Blob, MouseEvent, getSelection, prompt, addEventListener, Node, window, timeout, MutationObserver */
|
|
|
|
|
|
|
+/* global browser, SingleFile, singlefile, frameTree, document, Blob, MouseEvent, getSelection, prompt, addEventListener, Node, window, lazyLoader */
|
|
|
|
|
|
|
|
this.singlefile.top = this.singlefile.top || (() => {
|
|
this.singlefile.top = this.singlefile.top || (() => {
|
|
|
|
|
|
|
|
const MESSAGE_PREFIX = "__SingleFile__::";
|
|
const MESSAGE_PREFIX = "__SingleFile__::";
|
|
|
- const TIMEOUT_LAZY_LOADING = 500;
|
|
|
|
|
const SingleFileClass = SingleFile.getClass();
|
|
const SingleFileClass = SingleFile.getClass();
|
|
|
|
|
|
|
|
let processing = false;
|
|
let processing = false;
|
|
@@ -109,7 +108,7 @@ this.singlefile.top = this.singlefile.top || (() => {
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
if (options.lazyLoadImages) {
|
|
if (options.lazyLoadImages) {
|
|
|
- await lazyLoadResources();
|
|
|
|
|
|
|
+ await lazyLoader.process();
|
|
|
}
|
|
}
|
|
|
await processor.initialize();
|
|
await processor.initialize();
|
|
|
await processor.preparePageData();
|
|
await processor.preparePageData();
|
|
@@ -128,40 +127,6 @@ this.singlefile.top = this.singlefile.top || (() => {
|
|
|
return page;
|
|
return page;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- async function lazyLoadResources() {
|
|
|
|
|
- const scriptURL = browser.runtime.getURL("lib/single-file/lazy-loader-before.js");
|
|
|
|
|
- const scriptBeforeElement = document.createElement("script");
|
|
|
|
|
- scriptBeforeElement.src = scriptURL;
|
|
|
|
|
- document.body.appendChild(scriptBeforeElement);
|
|
|
|
|
- let timeoutId;
|
|
|
|
|
- const promise = new Promise(resolve => {
|
|
|
|
|
- scriptBeforeElement.onload = () => scriptBeforeElement.remove();
|
|
|
|
|
- const observer = new MutationObserver(mutationsList => {
|
|
|
|
|
- mutationsList.forEach(mutation => {
|
|
|
|
|
- if (mutation.attributeName == "src" || mutation.attributeName == "srcset") {
|
|
|
|
|
- timeoutId = deferLazyLoadEnd(timeoutId, observer, resolve);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- observer.observe(document, { attributes: true, childList: true, subtree: true });
|
|
|
|
|
- timeoutId = deferLazyLoadEnd(resolve);
|
|
|
|
|
- });
|
|
|
|
|
- return promise;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- function deferLazyLoadEnd(timeoutId, observer, resolve) {
|
|
|
|
|
- timeout.clear(timeoutId);
|
|
|
|
|
- return timeout.set(() => {
|
|
|
|
|
- resolve();
|
|
|
|
|
- const scriptURL = browser.runtime.getURL("lib/single-file/lazy-loader-after.js");
|
|
|
|
|
- const scriptAfterElement = document.createElement("script");
|
|
|
|
|
- scriptAfterElement.src = scriptURL;
|
|
|
|
|
- document.body.appendChild(scriptAfterElement);
|
|
|
|
|
- scriptAfterElement.onload = () => scriptAfterElement.remove();
|
|
|
|
|
- observer.disconnect();
|
|
|
|
|
- }, TIMEOUT_LAZY_LOADING);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function markSelectedContent() {
|
|
function markSelectedContent() {
|
|
|
const selection = getSelection();
|
|
const selection = getSelection();
|
|
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|