Remove crossorigin attributes in snapshots.

When loading a snapshot locally, same-origin of null will not load them
This commit is contained in:
Fletcher Hazlehurst 2020-10-11 17:26:05 -06:00
parent dadc64e0d5
commit ed304b56e0
3 changed files with 25 additions and 4 deletions

View file

@ -78,11 +78,30 @@ Zotero.SingleFile = {
extractAuthCode: true,
insertTextBody: true,
resolveFragmentIdentifierURLs: false,
userScriptEnabled: 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);
});
});
}
};

View file

@ -691,7 +691,8 @@ Zotero.Utilities.Internal = {
// Use SingleFile to retrieve the html
const pageData = await Components.utils.evalInSandbox(
`this.singlefile.lib.getPageData(
`Zotero.SingleFile.runUserScripts();
this.singlefile.lib.getPageData(
Zotero.SingleFile.CONFIG,
{ fetch: ZoteroFetch }
);`,

View file

@ -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