Skip to content

Commit

Permalink
integrate new infobar
Browse files Browse the repository at this point in the history
  • Loading branch information
gildas-lormeau committed Aug 17, 2023
1 parent 5e9c5b8 commit de8bf01
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 130 deletions.
1 change: 0 additions & 1 deletion lib/single-file-extension-infobar.js

This file was deleted.

20 changes: 6 additions & 14 deletions rollup.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ export default [{
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/core/content/content-infobar.js"],
input: ["single-filez-core/single-file-mini-helper.js"],
output: [{
file: "lib/single-file-extension-infobar.js",
file: "lib/single-file-extension-editor-helper.js",
format: "umd",
name: "infobar",
name: "singlefile",
plugins: []
}]
}],
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/core/content/content-bootstrap.js"],
output: [{
Expand Down Expand Up @@ -136,16 +138,6 @@ export default [{
}],
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/ui/content/content-ui-editor-helper-web"],
output: [{
file: "lib/single-file-extension-editor-helper.js",
format: "umd",
name: "singlefile",
plugins: []
}],
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/lib/single-file/browser-polyfill/chrome-browser-polyfill.js"],
output: [{
Expand Down
20 changes: 6 additions & 14 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,15 @@ export default [{
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/core/content/content-infobar.js"],
input: ["single-file-core/single-file-mini-helper.js"],
output: [{
file: "lib/single-file-extension-infobar.js",
file: "lib/single-file-extension-editor-helper.js",
format: "umd",
name: "infobar",
name: "singlefile",
plugins: [terser()]
}]
}],
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/core/content/content-bootstrap.js"],
output: [{
Expand Down Expand Up @@ -136,16 +138,6 @@ export default [{
}],
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/ui/content/content-ui-editor-helper-web"],
output: [{
file: "lib/single-file-extension-editor-helper.js",
format: "umd",
name: "singlefile",
plugins: [terser()]
}],
plugins: PLUGINS,
external: EXTERNAL
}, {
input: ["src/lib/single-file/browser-polyfill/chrome-browser-polyfill.js"],
output: [{
Expand Down
5 changes: 1 addition & 4 deletions src/core/bg/autosave.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global browser, infobar, URL, singlefile */
/* global browser, URL, singlefile */

import * as config from "./config.js";
import * as business from "./business.js";
Expand Down Expand Up @@ -162,9 +162,6 @@ async function saveContent(message, tab) {
options.filenameConflictAction = testSkip.filenameConflictAction;
}
if (!skipped) {
if (options.includeInfobar) {
pageData.content += await infobar.getScript();
}
const blob = await singlefile.processors.compression.process(pageData, {
insertTextBody: options.insertTextBody,
url: tab.url,
Expand Down
3 changes: 1 addition & 2 deletions src/core/bg/background.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
<body>
<script src="/lib/chrome-browser-polyfill.js"></script>
<script src="/lib/single-file-extension-background.js"></script>
<script src="/lib/single-file.js"></script>
<script src="/lib/single-file-extension-infobar.js"></script>
<script src="/lib/single-file.js"></script>
</body>

</html>
1 change: 0 additions & 1 deletion src/core/bg/business.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const TASK_PENDING_STATE = "pending";
const TASK_PROCESSING_STATE = "processing";

const extensionScriptFiles = [
"lib/single-file-extension-infobar.js",
"lib/single-file-extension.js"
];

Expand Down
5 changes: 1 addition & 4 deletions src/core/common/download.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global browser, infobar */
/* global browser */

import * as yabson from "./../../lib/yabson/yabson.js";

Expand All @@ -33,9 +33,6 @@ async function downloadPage(pageData, options) {
if (options.includeBOM) {
pageData.content = "\ufeff" + pageData.content;
}
if (options.includeInfobar) {
pageData.content += await infobar.getScript();
}
const message = {
taskId: options.taskId,
insertTextBody: options.insertTextBody,
Expand Down
2 changes: 1 addition & 1 deletion src/core/content/content-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Source.
*/

/* global browser, globalThis, window, document, location, setTimeout, clearTimeout, XMLHttpRequest, Node, DOMParser */
/* global browser, globalThis, window, document, location, setTimeout, XMLHttpRequest, Node, DOMParser */

import * as yabson from "./../../lib/yabson/yabson.js";

Expand Down
39 changes: 0 additions & 39 deletions src/core/content/content-infobar.js

This file was deleted.

11 changes: 9 additions & 2 deletions src/ui/bg/ui-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,10 @@ function enableEditPage() {
function formatPage() {
formatPageButton.classList.remove("format-disabled");
updatedResources = {};
editorElement.contentWindow.postMessage(JSON.stringify({ method: tabData.options.applySystemTheme ? "formatPage" : "formatPageNoTheme" }), "*");
editorElement.contentWindow.postMessage(JSON.stringify({
method: "formatPage",
applySystemTheme: tabData.options.applySystemTheme
}), "*");
}

function cancelFormatPage() {
Expand All @@ -462,7 +465,11 @@ function enableCutOuterPage() {
}

function savePage() {
editorElement.contentWindow.postMessage(JSON.stringify({ method: "getContent", compressHTML: tabData.options.compressHTML, updatedResources }), "*");
editorElement.contentWindow.postMessage(JSON.stringify({
method: "getContent", compressHTML: tabData.options.compressHTML,
includeInfobar: tabData.options.includeInfobar,
updatedResources
}), "*");
}

function displayInfobar() {
Expand Down
39 changes: 0 additions & 39 deletions src/ui/content/content-ui-editor-helper-web.js

This file was deleted.

19 changes: 12 additions & 7 deletions src/ui/content/content-ui-editor-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ pre code {

let NOTES_WEB_STYLESHEET, MASK_WEB_STYLESHEET, HIGHLIGHTS_WEB_STYLESHEET;
let selectedNote, anchorElement, maskNoteElement, maskPageElement, highlightSelectionMode, removeHighlightMode, resizingNoteMode, movingNoteMode, highlightColor, collapseNoteTimeout, cuttingOuterMode, cuttingMode, cuttingTouchTarget, cuttingPath, cuttingPathIndex, previousContent;
let removedElements = [], removedElementIndex = 0, initScriptContent, pageResources, pageUrl;
let removedElements = [], removedElementIndex = 0, initScriptContent, pageResources, pageUrl, includeInfobar;

globalThis.zip = zip;
window.onmessage = async event => {
Expand Down Expand Up @@ -1025,10 +1025,7 @@ pre code {
onUpdate(false);
}
if (message.method == "formatPage") {
formatPage(true);
}
if (message.method == "formatPageNoTheme") {
formatPage(false);
formatPage(!message.applySystemTheme);
}
if (message.method == "cancelFormatPage") {
cancelFormatPage();
Expand Down Expand Up @@ -1071,6 +1068,7 @@ pre code {
}
if (message.method == "getContent") {
onUpdate(true);
includeInfobar = message.includeInfobar;
let content = getContent(message.compressHTML, message.updatedResources);
if (initScriptContent) {
content = content.replace(/<script data-template-shadow-root src.*?<\/script>/g, initScriptContent);
Expand All @@ -1089,7 +1087,7 @@ pre code {
printPage();
}
if (message.method == "displayInfobar") {
singlefile.infobar.displayIcon();
singlefile.helper.displayIcon(document, true);
}
};
window.onresize = reflowNotes;
Expand Down Expand Up @@ -1124,6 +1122,10 @@ pre code {
const contentDocument = (new DOMParser()).parseFromString(docContent, "text/html");
if (detectSavedPage(contentDocument)) {
await display(document, docContent, { disableFramePointerEvents: true });
const infobarElement = document.querySelector(singlefile.helper.INFOBAR_TAGNAME);
if (infobarElement) {
infobarElement.remove();
}
await initPage();
let icon;
const origContentDocument = (new DOMParser()).parseFromString(origDocContent, "text/html");
Expand Down Expand Up @@ -1930,7 +1932,10 @@ pre code {
element.textContent = element.getAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME);
element.removeAttribute(DISABLED_NOSCRIPT_ATTRIBUTE_NAME);
});
doc.querySelectorAll("." + MASK_CLASS + ", ." + REMOVED_CONTENT_CLASS).forEach(maskElement => maskElement.remove());
doc.querySelectorAll("." + MASK_CLASS + ", " + singlefile.helper.INFOBAR_TAGNAME + ", ." + REMOVED_CONTENT_CLASS).forEach(maskElement => maskElement.remove());
if (includeInfobar) {
singlefile.helper.appendInfobar(doc, singlefile.helper.extractInfobarData(doc));
}
doc.querySelectorAll("." + HIGHLIGHT_CLASS).forEach(noteElement => noteElement.classList.remove(HIGHLIGHT_HIDDEN_CLASS));
doc.querySelectorAll(`template[${SHADOWROOT_ATTRIBUTE_NAME}]`).forEach(templateElement => {
const noteElement = templateElement.querySelector("." + NOTE_CLASS);
Expand Down
3 changes: 1 addition & 2 deletions src/ui/pages/editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@
</div>
</div>
<iframe class="editor"
srcdoc="&lt;!DOCTYPE html&gt;&lt;body&gt;&lt;script src=/lib/single-file-extension-editor-helper.js&gt;&lt;/script&gt;&lt;script src=/lib/single-file-extension-editor.js&gt;&lt;/script&gt;&lt;script src=/lib/single-file-infobar.js&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability.js&gt;&lt;/script&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability-readerable.js&gt;&lt;/script&gt;&lt;/body&gt;"
srcdoc="&lt;!DOCTYPE html&gt;&lt;body&gt;&lt;script src=/lib/single-file-extension-editor-helper.js&gt;&lt;/script&gt;&lt;script src=/lib/single-file-extension-editor.js&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability.js&gt;&lt;/script&gt;&lt;/script&gt;&lt;script src=/src/lib/readability/Readability-readerable.js&gt;&lt;/script&gt;&lt;/body&gt;"
sandbox="allow-scripts allow-modals"></iframe>
<script src="/lib/chrome-browser-polyfill.js"></script>
<script src="/lib/single-file.js"></script>
<script src="/lib/single-file-extension-infobar.js"></script>
<script type="module" src="/src/ui/bg/ui-editor.js"></script>
</body>

Expand Down

0 comments on commit de8bf01

Please sign in to comment.