Extract SingleFile config so we can share with connector

This commit is contained in:
Fletcher Hazlehurst 2020-10-11 16:49:07 -06:00
parent 37cdba6f40
commit dadc64e0d5
2 changed files with 100 additions and 62 deletions

View file

@ -0,0 +1,88 @@
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2020 Corporation for Digital Scholarship
Vienna, Virginia, USA
https://www.zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
Zotero.SingleFile = {
// These are defaults from SingleFileZ
// Located in: zotero/resources/SingleFileZ/extension/core/bg/config.js
CONFIG: {
removeHiddenElements: true,
removeUnusedStyles: true,
removeUnusedFonts: true,
removeFrames: true,
removeImports: true,
removeScripts: true,
compressHTML: true,
compressCSS: false,
loadDeferredImages: true,
loadDeferredImagesMaxIdleTime: 1500,
loadDeferredImagesBlockCookies: false,
loadDeferredImagesBlockStorage: false,
loadDeferredImagesKeepZoomLevel: false,
filenameTemplate: "{page-title} ({date-iso} {time-locale}).html",
infobarTemplate: "",
includeInfobar: false,
confirmInfobarContent: false,
autoClose: false,
confirmFilename: false,
filenameConflictAction: "uniquify",
filenameMaxLength: 192,
filenameReplacedCharacters: ["~", "+", "\\\\", "?", "%", "*", ":", "|", "\"", "<", ">", "\x00-\x1f", "\x7F"],
filenameReplacementCharacter: "_",
contextMenuEnabled: true,
tabMenuEnabled: true,
browserActionMenuEnabled: true,
shadowEnabled: true,
logsEnabled: true,
progressBarEnabled: true,
maxResourceSizeEnabled: false,
maxResourceSize: 10,
removeAudioSrc: true,
removeVideoSrc: true,
displayInfobar: true,
displayStats: false,
backgroundSave: true,
autoSaveDelay: 1,
autoSaveLoad: false,
autoSaveUnload: false,
autoSaveLoadOrUnload: true,
autoSaveRepeat: false,
autoSaveRepeatDelay: 10,
removeAlternativeFonts: true,
removeAlternativeMedias: true,
removeAlternativeImages: true,
saveRawPage: false,
saveToGDrive: false,
forceWebAuthFlow: false,
extractAuthCode: true,
insertTextBody: true,
resolveFragmentIdentifierURLs: false,
userScriptEnabled: false,
saveCreatedBookmarks: false,
ignoredBookmarkFolders: [],
replaceBookmarkURL: true,
saveFavicon: true,
includeBOM: false
}
};

View file

@ -677,74 +677,24 @@ Zotero.Utilities.Internal = {
SCRIPTS.forEach(
script => loadSubScript('resource://zotero/SingleFileZ/' + script, sandbox)
);
// Import config and user scripts
loadSubScript('chrome://zotero/content/xpcom/singlefile.js', sandbox);
// In the client we turn off this auto-zooming feature because it does not work
// since the hidden browser does not have a clientHeight.
Components.utils.evalInSandbox(
'Zotero.SingleFile.CONFIG.loadDeferredImagesKeepZoomLevel = true;',
sandbox
);
await Zotero.Promise.delay(1500);
// Use SingleFile to retrieve the html
// These are defaults from SingleFileZ
// Located in: resources/SingleFileZ/extension/core/bg/config.js
// Only change is removeFrames to true (often ads that take a long time)
const pageData = await Components.utils.evalInSandbox(
`this.singlefile.lib.getPageData({
removeHiddenElements: true,
removeUnusedStyles: true,
removeUnusedFonts: true,
removeFrames: true,
removeImports: true,
removeScripts: true,
compressHTML: true,
compressCSS: false,
loadDeferredImages: true,
loadDeferredImagesMaxIdleTime: 1500,
loadDeferredImagesBlockCookies: false,
loadDeferredImagesBlockStorage: false,
loadDeferredImagesKeepZoomLevel: true,
filenameTemplate: "{page-title} ({date-iso} {time-locale}).html",
infobarTemplate: "",
includeInfobar: false,
confirmInfobarContent: false,
autoClose: false,
confirmFilename: false,
filenameConflictAction: "uniquify",
filenameMaxLength: 192,
filenameReplacementCharacter: "_",
contextMenuEnabled: true,
tabMenuEnabled: true,
browserActionMenuEnabled: true,
shadowEnabled: true,
logsEnabled: true,
progressBarEnabled: true,
maxResourceSizeEnabled: false,
maxResourceSize: 10,
removeAudioSrc: true,
removeVideoSrc: true,
displayInfobar: true,
displayStats: false,
backgroundSave: true,
autoSaveDelay: 1,
autoSaveLoad: false,
autoSaveUnload: false,
autoSaveLoadOrUnload: true,
autoSaveRepeat: false,
autoSaveRepeatDelay: 10,
removeAlternativeFonts: true,
removeAlternativeMedias: true,
removeAlternativeImages: true,
saveRawPage: false,
saveToGDrive: false,
forceWebAuthFlow: false,
extractAuthCode: true,
insertTextBody: true,
resolveFragmentIdentifierURLs: false,
userScriptEnabled: false,
saveCreatedBookmarks: false,
ignoredBookmarkFolders: [],
replaceBookmarkURL: true,
saveFavicon: true,
includeBOM: false
},
`this.singlefile.lib.getPageData(
Zotero.SingleFile.CONFIG,
{ fetch: ZoteroFetch }
)`,
);`,
sandbox
);