jikamens / userChromeJS

Re-implementation of the userChromeJS add-on for Thunderbird 60+
Mozilla Public License 2.0
11 stars 4 forks source link

[Feature Request] Load separate user scripts (*.js / *.us.js files) #2

Open ghost opened 5 years ago

ghost commented 5 years ago

Hello.

Is it possible to load and run all user scripts located in the chrome profile directory on program start? So there is no need to store all scripts in one single userChrome.js file?

Thanks!

jikamens commented 5 years ago

You can put this into your userChrome.js file to load all files in your chrome directory with names ending in ".uc.js".

This sample should make it clear how to load files with other names as you wish.

let protocolHandler = Services.io.getProtocolHandler("file").
    QueryInterface(Components.interfaces.nsIFileProtocolHandler);
let userChromeDirectory = Services.dirsvc.get("UChrm", Ci.nsIFile);
for (let file of userChromeDirectory.directoryEntries) {
    if (! file.leafName.endsWith(".uc.js"))
        continue;
    let url = protocolHandler.getURLSpecFromFile(file);
    Services.scriptloader.loadSubScriptWithOptions(url, {
        target: document.defaultView,
        charset: "UTF-8",
        ignoreCache: true
    });
}