Skip to content

Commit

Permalink
Prevent repeat loads of js/css, fix xul loading
Browse files Browse the repository at this point in the history
- don't run if xml has already run (by setting global variable)
- ignore script cache (so that changes to scripts can show up on restart or new windows without removing cache).
- don't load already registered css (for new windows)
- fix loading of xul files by increasing delay (previously only the first xul file gets loaded)
  • Loading branch information
Sporif committed Dec 18, 2017
1 parent 6feebef commit 0eab4dc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions userChrome.xml
Expand Up @@ -9,6 +9,9 @@ https://opensource.org/licenses/MIT
<binding id="js" extends="chrome://global/content/bindings/toolbarbutton.xml#menu">
<implementation>
<constructor><![CDATA[
if(window.userChromeJsMod) return;
window.userChromeJsMod = true;
var chromeFiles = FileUtils.getDir("UChrm", []).directoryEntries;
var xulFiles = [];
var sss = Cc['@mozilla.org/content/style-sheet-service;1'].getService(Ci.nsIStyleSheetService);
Expand All @@ -19,24 +22,26 @@ https://opensource.org/licenses/MIT
if(file.isFile()) {
if(/(^userChrome|\.uc)\.js$/i.test(file.leafName)) {
Services.scriptloader.loadSubScript(fileURI.spec, window);
Services.scriptloader.loadSubScriptWithOptions(fileURI.spec, {target: window, ignoreCache: true});
}
else if(/(^userChrome|\.uc)\.xul$/i.test(file.leafName)) {
xulFiles.push(fileURI.spec);
}
else if(/\.as\.css$/i.test(file.leafName)) {
sss.loadAndRegisterSheet(fileURI, sss.AGENT_SHEET);
if(!sss.sheetRegistered(fileURI, sss.AGENT_SHEET))
sss.loadAndRegisterSheet(fileURI, sss.AGENT_SHEET);
}
else if(/^(?!(userChrome|userContent)\.css$).+\.css$/i.test(file.leafName)) {
sss.loadAndRegisterSheet(fileURI, sss.USER_SHEET);
if(!sss.sheetRegistered(fileURI, sss.USER_SHEET))
sss.loadAndRegisterSheet(fileURI, sss.USER_SHEET);
}
}
}
setTimeout(function loadXUL() {
if(xulFiles.length > 0) {
document.loadOverlay(xulFiles.shift(), null);
setTimeout(loadXUL, 0);
setTimeout(loadXUL, 5);
}
}, 0);
]]></constructor>
Expand Down

0 comments on commit 0eab4dc

Please sign in to comment.