Merge pull request #1896 from fletcherhaz/snapshot
Fix CORS issues in SingleFile
This commit is contained in:
commit
1ac79c0974
3 changed files with 123 additions and 64 deletions
107
chrome/content/zotero/xpcom/singlefile.js
Normal file
107
chrome/content/zotero/xpcom/singlefile.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
/*
|
||||
***** 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: true,
|
||||
saveCreatedBookmarks: false,
|
||||
ignoredBookmarkFolders: [],
|
||||
replaceBookmarkURL: true,
|
||||
saveFavicon: true,
|
||||
includeBOM: false
|
||||
},
|
||||
|
||||
runUserScripts: function () {
|
||||
let modifiedElements = [];
|
||||
window.dispatchEvent(new CustomEvent('single-filez-user-script-init'));
|
||||
|
||||
window.addEventListener('single-filez-on-before-capture-request', () => {
|
||||
const elements = document.querySelectorAll("img[crossorigin], link[crossorigin]");
|
||||
elements.forEach((element) => {
|
||||
modifiedElements.push([element, element.getAttribute('crossorigin')]);
|
||||
element.removeAttribute('crossorigin');
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener('single-filez-on-after-capture-request', () => {
|
||||
modifiedElements.forEach(([element, attribute]) => {
|
||||
element.setAttribute('crossorigin', attribute);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
|
@ -677,74 +677,25 @@ 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
|
||||
},
|
||||
`Zotero.SingleFile.runUserScripts();
|
||||
this.singlefile.lib.getPageData(
|
||||
Zotero.SingleFile.CONFIG,
|
||||
{ fetch: ZoteroFetch }
|
||||
)`,
|
||||
);`,
|
||||
sandbox
|
||||
);
|
||||
|
||||
|
|
|
@ -55,8 +55,9 @@ async function babelWorker(ev) {
|
|||
|
||||
// Patch single-file-helper
|
||||
else if (sourcefile === 'resource/SingleFileZ/lib/single-file/single-file-helper.js') {
|
||||
transformed = contents.replace('addEventListener("single-filez-user-script-init"',
|
||||
'window.addEventListener("single-filez-user-script-init"');
|
||||
transformed = contents
|
||||
.replace('dispatchEvent(', 'window.dispatchEvent(')
|
||||
.replace(/addEventListener\(/g, 'window.addEventListener(');
|
||||
}
|
||||
|
||||
// Patch index.js - This is a SingleFileZ issue. SingleFileZ does not typically use
|
||||
|
|
Loading…
Add table
Reference in a new issue