Skip to content

Commit

Permalink
use single-filez-core module
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed May 30, 2022
1 parent e1a58c3 commit 20225f4
Show file tree
Hide file tree
Showing 89 changed files with 522 additions and 16,586 deletions.
6 changes: 3 additions & 3 deletions build-extension.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ cp src/extension/core/bg/config.js config.copy.js
jq "del(.options_page,.background.persistent,.optional_permissions[0],.oauth2)" manifest.copy.json >manifest.json
sed -i 's/7544745492-ig6uqhua0ads4jei52lervm1pqsi6hot/7544745492-oe3q2jjvdluks2st2smslmrofcdederh/g' manifest.json
sed -i 's/forceWebAuthFlow: false/forceWebAuthFlow: true/g' src/extension/core/bg/config.js
zip -r singlefilez-extension-firefox.zip manifest.json lib _locales src/extension src/single-file/vendor/zip/zip.js src/single-file/vendor/zip/zip.min.js src/single-file/vendor/zip/z-worker.js
zip -r singlefilez-extension-firefox.zip manifest.json lib _locales src/extension
mv config.copy.js src/extension/core/bg/config.js

jq "del(.browser_specific_settings,.permissions[0],.permissions[1],.options_ui.browser_style)" manifest.copy.json >manifest.json
sed -i 's/7544745492-ig6uqhua0ads4jei52lervm1pqsi6hot/7544745492-oe3q2jjvdluks2st2smslmrofcdederh/g' manifest.json
zip -r singlefilez-extension-chromium.zip manifest.json lib _locales src/single-file/vendor/zip/zip.js src/extension src/single-file/vendor/zip/zip.min.js src/single-file/vendor/zip/z-worker.js
zip -r singlefilez-extension-chromium.zip manifest.json lib _locales

cp src/extension/core/bg/config.js config.copy.js
jq "del(.browser_specific_settings,.permissions[0],.permissions[1],.options_ui.browser_style)" manifest.copy.json >manifest.json
Expand All @@ -28,7 +28,7 @@ mkdir _locales.copy
cp -R _locales/* _locales.copy
rm -rf _locales/*
cp -R _locales.copy/en _locales
zip -r singlefilez-extension-edge.zip manifest.json lib _locales src/extension src/single-file/vendor/zip/zip.js src/single-file/vendor/zip/zip.min.js src/single-file/vendor/zip/z-worker.js
zip -r singlefilez-extension-edge.zip manifest.json lib _locales
rm -rf _locales/*
mv _locales.copy/* _locales
rmdir _locales.copy
Expand Down
27 changes: 10 additions & 17 deletions cli/back-ends/common/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,17 @@
const fs = require("fs");

const SCRIPTS = [
"lib/infobar.js",
"lib/single-file-bootstrap.js"
"lib/single-file.js",
"lib/single-file-bootstrap.js",
"lib/single-file-hooks.js",
"lib/single-file-hooks-frames.js",
"lib/single-file-zip.min.js"
];

const INDEX_SCRIPTS = [
"lib/single-file.js"
];

const WEB_SCRIPTS = [
"/lib/web/hooks/hooks-web.js",
"/lib/web/hooks/hooks-frames-web.js",
"/lib/web/infobar-web.js",
"/src/single-file/vendor/zip/zip.min.js"
];
const basePath = "../../../";

exports.get = async options => {
const basePath = "../../../";
let scripts = "let _singleFileDefine; if (typeof define !== 'undefined') { _singleFileDefine = define; define = null }";
scripts += await readScriptFiles(INDEX_SCRIPTS, basePath);
const webScripts = {};
await Promise.all(WEB_SCRIPTS.map(async path => webScripts[path] = await readScriptFile(path, basePath)));
scripts += "window.singlefile.getFileContent = filename => (" + JSON.stringify(webScripts) + ")[filename];\n";
scripts += await readScriptFiles(SCRIPTS, basePath);
scripts += await readScriptFiles(options && options.browserScripts ? options.browserScripts : [], "");
if (options.browserStylesheets && options.browserStylesheets.length) {
Expand All @@ -57,6 +46,10 @@ exports.get = async options => {
return scripts;
};

exports.getInfobarScript = () => {
return readScriptFile("lib/single-file-infobar.js", basePath);
};

async function readScriptFiles(paths, basePath = "../../../") {
return (await Promise.all(paths.map(path => readScriptFile(path, basePath)))).join("");
}
Expand Down
4 changes: 0 additions & 4 deletions cli/back-ends/jsdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ async function getPageData(win, options) {
executeFrameScripts(doc, scripts);
options.removeHiddenElements = false;
options.loadDeferredImages = false;
options.getFileContent = win.singlefile.getFileContent;
options.compressContent = true;
if (options.browserWaitDelay) {
await new Promise(resolve => setTimeout(resolve, options.browserWaitDelay));
}
const pageData = await win.singlefile.getPageData(options, { fetch: url => fetchResource(url, options) }, doc, win);
if (options.includeInfobar) {
await win.infobar.includeScript(pageData);
}
pageData.content = new Uint8Array(pageData.content);
return pageData;

Expand Down
6 changes: 1 addition & 5 deletions cli/back-ends/playwright-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global singlefile, infobar, require, exports */
/* global singlefile, require, exports */

const playwright = require("playwright").chromium;
const scripts = require("./common/scripts.js");
Expand Down Expand Up @@ -105,11 +105,7 @@ async function getPageData(page, options) {
}
const pageData = await page.evaluate(async options => {
options.compressContent = true;
options.getFileContent = singlefile.getFileContent;
const pageData = await singlefile.getPageData(options);
if (options.includeInfobar) {
await infobar.includeScript(pageData);
}
return pageData;
}, options);
pageData.content = new Uint8Array(pageData.content);
Expand Down
6 changes: 1 addition & 5 deletions cli/back-ends/playwright-firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global singlefile, infobar, require, exports */
/* global singlefile, require, exports */

const playwright = require("playwright").firefox;
const scripts = require("./common/scripts.js");
Expand Down Expand Up @@ -105,11 +105,7 @@ async function getPageData(page, options) {
}
const pageData = await page.evaluate(async options => {
options.compressContent = true;
options.getFileContent = singlefile.getFileContent;
const pageData = await singlefile.getPageData(options);
if (options.includeInfobar) {
await infobar.includeScript(pageData);
}
return pageData;
}, options);
pageData.content = new Uint8Array(pageData.content);
Expand Down
6 changes: 1 addition & 5 deletions cli/back-ends/puppeteer-firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global singlefile, infobar, require, exports */
/* global singlefile, require, exports */

const puppeteer = require("puppeteer-core");
const scripts = require("./common/scripts.js");
Expand Down Expand Up @@ -114,11 +114,7 @@ async function getPageData(browser, page, options) {
}
const pageData = await page.evaluate(async options => {
options.compressContent = true;
options.getFileContent = singlefile.getFileContent;
const pageData = await singlefile.getPageData(options);
if (options.includeInfobar) {
await infobar.includeScript(pageData);
}
return pageData;
}, options);
pageData.content = new Uint8Array(pageData.content);
Expand Down
6 changes: 1 addition & 5 deletions cli/back-ends/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global singlefile, infobar, require, exports */
/* global singlefile, require, exports */

const puppeteer = require("puppeteer-core");
const scripts = require("./common/scripts.js");
Expand Down Expand Up @@ -138,11 +138,7 @@ async function getPageData(browser, page, options) {
}
const pageData = await page.evaluate(async options => {
options.compressContent = true;
options.getFileContent = singlefile.getFileContent;
const pageData = await singlefile.getPageData(options);
if (options.includeInfobar) {
await infobar.includeScript(pageData);
}
return pageData;
}, options);
pageData.content = new Uint8Array(pageData.content);
Expand Down
5 changes: 2 additions & 3 deletions cli/back-ends/webdriver-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ function getPageDataScript() {
async function getPageData() {
options.compressContent = true;
options.getFileContent = singlefile.getFileContent;
const pageData = await singlefile.getPageData(options);
if (options.includeInfobar) {
await infobar.includeScript(pageData);
if (options.infobarScript) {
pageData.content += options.infobarScript;
}
return pageData;
}
Expand Down
5 changes: 2 additions & 3 deletions cli/back-ends/webdriver-gecko.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,9 @@ function getPageDataScript() {
async function getPageData() {
options.compressContent = true;
options.getFileContent = window.singlefile.getFileContent;
const pageData = await window.singlefile.getPageData(options);
if (options.includeInfobar) {
await infobar.includeScript(pageData);
if (options.infobarScript) {
pageData.content += options.infobarScript;
}
return pageData;
}
Expand Down
11 changes: 11 additions & 0 deletions cli/single-file-cli-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

const fs = require("fs");
const path = require("path");
const scripts = require("./back-ends/common/scripts.js");
const VALID_URL_TEST = /^(https?|file):\/\//;

const DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -62,6 +63,7 @@ const DEFAULT_OPTIONS = {
insertMetaCSP: true,
insertMetaNoIndex: false,
password: "",
insertSingleFileComment: true,
blockImages: false,
blockStylesheets: false,
blockFont: false,
Expand Down Expand Up @@ -230,6 +232,10 @@ function getHostURL(url) {
async function capturePage(options) {
try {
let filename;
if (options.includeInfobar) {
options.infobarScript = await getInfobarScript();
}
options.zipScript = fs.readFileSync("./../lib/single-file-zip.min.js").toString();
const pageData = await backend.getPageData(options);
if (options.output) {
filename = getFilename(options.output, options);
Expand Down Expand Up @@ -289,3 +295,8 @@ function getFilename(filename, options, index = 1) {
return newFilename;
}
}

async function getInfobarScript() {
const infobarContent = await scripts.getInfobarScript();
return "<script>document.currentScript.remove();" + infobarContent + "</script>";
}
1 change: 0 additions & 1 deletion lib/extension.js

This file was deleted.

1 change: 0 additions & 1 deletion lib/infobar.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/single-file-bootstrap.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions lib/single-file-extension-editor-helper.js

Large diffs are not rendered by default.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6384,7 +6384,7 @@
});

/*
* Copyright 2010-2020 Gildas Lormeau
* Copyright 2010-2022 Gildas Lormeau
* contact : gildas.lormeau <at> gmail.com
*
* This file is part of SingleFile.
Expand Down Expand Up @@ -6528,7 +6528,7 @@
}

/*
* Copyright 2010-2020 Gildas Lormeau
* Copyright 2010-2022 Gildas Lormeau
* contact : gildas.lormeau <at> gmail.com
*
* This file is part of SingleFile.
Expand Down Expand Up @@ -7599,7 +7599,7 @@ table {
async function init({ content, password }, { filename, reset } = {}) {
await initConstants();
const zipOptions = {
workerScripts: { inflate: ["/src/single-file/vendor/zip/z-worker.js"] }
workerScripts: { inflate: ["/lib/single-file-z-worker.js"] }
};
try {
const worker = new Worker(zipOptions.workerScripts);
Expand All @@ -7610,7 +7610,7 @@ table {
const { docContent, origDocContent, resources, url } = await extract(content, {
password,
prompt,
shadowRootScriptURL: new URL("/lib/web/editor/editor-init-web.js", document.baseURI).href,
shadowRootScriptURL: new URL("/lib/single-file-extension-editor-init-web.js", document.baseURI).href,
zipOptions
});
pageResources = resources;
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions lib/single-file-extension-infobar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/single-file-extension.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/single-file-frames.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions lib/single-file-z-worker.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/single-file-zip.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/single-file-zip.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/single-file.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/web/editor/editor-helper-web.js

This file was deleted.

22 changes: 11 additions & 11 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"js": [
"lib/chrome-browser-polyfill.js",
"lib/single-file-frames.js",
"lib/extension-frames.js"
"lib/single-file-extension-frames.js"
],
"all_frames": true,
"match_about_blank": true
Expand All @@ -32,8 +32,8 @@
"js": [
"lib/chrome-browser-polyfill.js",
"lib/single-file-bootstrap.js",
"lib/extension-bootstrap.js",
"lib/web/infobar-web.js"
"lib/single-file-extension-bootstrap.js",
"lib/single-file-infobar.js"
]
}
],
Expand Down Expand Up @@ -78,16 +78,16 @@
}
},
"web_accessible_resources": [
"lib/web/hooks/hooks-web.js",
"lib/web/hooks/hooks-frames-web.js",
"lib/web/infobar-web.js",
"lib/web/editor/editor-init-web.js",
"lib/web/editor/editor-web.js",
"lib/web/editor/editor-helper-web.js",
"lib/single-file-hooks.js",
"lib/single-file-hooks-frames.js",
"lib/single-file-infobar.js",
"lib/single-file-extension-editor-init.js",
"lib/single-file-extension-editor.js",
"lib/single-file-extension-editor-helper.js",
"lib/single-file-zip.min.js",
"lib/single-file-z-worker.js",
"src/extension/lib/readability/Readability.js",
"src/extension/lib/readability/Readability-readerable.js",
"src/single-file/vendor/zip/zip.min.js",
"src/single-file/vendor/zip/z-worker.js",
"src/extension/ui/pages/editor-note-web.css",
"src/extension/ui/pages/editor-mask-web.css",
"src/extension/ui/pages/editor-frame-web.css"
Expand Down
Loading

0 comments on commit 20225f4

Please sign in to comment.