diff --git a/edit/edit.js b/edit/edit.js index f5e57319..34b8eadd 100644 --- a/edit/edit.js +++ b/edit/edit.js @@ -1,6 +1,7 @@ /* eslint brace-style: 0, operator-linebreak: 0 */ /* global CodeMirror parserlib */ -/* global exports onDOMscripted */ +/* global onDOMscripted */ +/* global css_beautify */ /* global CSSLint initLint linterConfig updateLintReport renderLintReport updateLinter */ 'use strict'; @@ -1080,9 +1081,14 @@ function getEditorInSight(nearbyElement) { } function beautify(event) { - const script = $('script[src*="beautify-css-mod"]') ? - [] : ['vendor-overwrites/beautify/beautify-css-mod.js']; - onDOMscripted(script).then(doBeautify); + onDOMscripted([ + 'vendor-overwrites/beautify/beautify-css-mod.js', + () => { + if (!window.css_beautify && window.exports) { + window.css_beautify = window.exports.css_beautify; + } + }, + ]).then(doBeautify); function doBeautify() { const tabs = prefs.get('editor.indentWithTabs'); @@ -1127,7 +1133,7 @@ function beautify(event) { [].concat.apply([], cm.doc.sel.ranges.map(r => [Object.assign({}, r.anchor), Object.assign({}, r.head)])); const text = cm.getValue(); - const newText = exports.css_beautify(text, options); + const newText = css_beautify(text, options); if (newText !== text) { if (!cm.beautifyChange || !cm.beautifyChange[cm.changeGeneration()]) { // clear the list if last change wasn't a css-beautify diff --git a/js/dom.js b/js/dom.js index a4d90489..b5c2bc3c 100644 --- a/js/dom.js +++ b/js/dom.js @@ -122,6 +122,14 @@ function injectScript(properties) { if (!properties || !properties.src) { return; } + if (injectScript.cache) { + if (injectScript.cache.has(properties.src)) { + return Promise.resolve(); + } + } else { + injectScript.cache = new Set(); + } + injectScript.cache.add(properties.src); const script = document.head.appendChild(document.createElement('script')); Object.assign(script, properties); if (!properties.onload) {