diff --git a/chrome/content/zotero/tools/cslpreview.js b/chrome/content/zotero/tools/cslpreview.js index dc177dd966..6fb87dee4a 100644 --- a/chrome/content/zotero/tools/cslpreview.js +++ b/chrome/content/zotero/tools/cslpreview.js @@ -24,25 +24,27 @@ Contributed by Julian Onions */ -var Zotero_CSL_Preview = new function() { - this.init = init; - this.refresh = refresh; - this.generateBibliography = generateBibliography; +// eslint-disable-next-line no-unused-vars +var Zotero_CSL_Preview = new function () { + this.lastContent = null; - function init() { + this.init = function () { var menulist = document.getElementById("locale-menu"); Zotero.Styles.populateLocaleList(menulist); - menulist.value = Zotero.Prefs.get('export.lastLocale');; + menulist.value = Zotero.Prefs.get('export.lastLocale'); - var iframe = document.getElementById('zotero-csl-preview-box'); - iframe.contentDocument.documentElement.innerHTML = '
' + Zotero.getString('styles.preview.instructions') + '
'; - } - function refresh() { - var iframe = document.getElementById('zotero-csl-preview-box'); + this.updateIframe(Zotero.getString('styles.preview.instructions')); + + window.matchMedia('(prefers-color-scheme: dark)').addEventListener("change", () => { + this.updateIframe(this.lastContent.content, this.lastContent.containerClass); + }); + }; + + this.refresh = function () { var items = Zotero.getActiveZoteroPane().getSelectedItems(); if (items.length === 0) { - iframe.contentDocument.documentElement.innerHTML = '' + Zotero.getString('styles.editor.warning.noItems') + '
'; + this.updateIframe(Zotero.getString('styles.editor.warning.noItems'), 'warning'); return; } var progressWin = new Zotero.ProgressWindow(); @@ -52,11 +54,12 @@ var Zotero_CSL_Preview = new function() { progressWin.addLines(document.title, icon); progressWin.show(); progressWin.startCloseTimer(); - var f = function() { + // Give progress window time to appear + setTimeout(() => { var d = new Date(); var styles = Zotero.Styles.getVisible(); // XXX needs its own string really for the title! - var str = '' + citations + '
' + bibliography; - } - - + }; + + this.updateIframe = function (content, containerClass = 'preview') { + this.lastContent = { content, containerClass }; + const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; + let iframe = document.getElementById('zotero-csl-preview-box'); + iframe.contentDocument.documentElement.innerHTML = ` + +