MrOtherGuy / fx-autoconfig

Load custom javascript in browser context
Mozilla Public License 2.0
169 stars 10 forks source link

Help installing - I already have some of these files/folders? #2

Closed e-t-l closed 3 years ago

e-t-l commented 3 years ago

I already have a config.js in the Program folder and a chrome folder in the Firefox root folder. chrome doesn't have any subdirectories, but it does already contain a chrome.manifest and boot.jsm (as well as a UserChrome.css that I have been actively using to tweak css). I don't particularly remember adding the config.js or boot.jsm, so in order to install this Fx Autoconfig, do I need to replace or append the code in the existing files? And do I need to add the folder structure that's missing (i.e. JS, resources, and utils)?

The contents of my existing files are below, so you can hopefully advise whether they need to be merged/replaced or whether they'll function as-is:

config.js

// skip 1st line
try {

  let Cu = Components.utils;
  Cu.import('resource://gre/modules/osfile.jsm');
  Cu.import(OS.Path.toFileURI(OS.Constants.Path.profileDir)+ '/chrome/utils/boot.jsm');

} catch(ex) {};

boot.jsm

let EXPORTED_SYMBOLS = [];

let {
  classes: Cc,
  interfaces: Ci,
  manager: Cm
} = Components;

var cmanifest = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties).get('UChrm', Ci.nsIFile);
cmanifest.append('utils');
cmanifest.append('chrome.manifest');
Cm.QueryInterface(Ci.nsIComponentRegistrar).autoRegister(cmanifest);

ChromeUtils.import('chrome://userchromejs/content/userChrome.jsm');

chrome.manifest

content userchromejs ./
resource userchromejs ../
MrOtherGuy commented 3 years ago

That suggests that you already have one autoconfig based loader. boot.jsm seems to be loading, userChrome.jsm from somewhere - that somewhere is defined in chrome.manifest but it's probably somewhere inside the "chrome" folder.

Nonetheless, you should definitely NOT use both this and your existing loader at the same time. So if you want to use this one, then remove the old one. My loader loads the individual .js scripts from a /chrome/JS folder, so yes you must create that or modify (my) boot.jsm to load the scripts from somewhere else if you plan on loading any .js scripts.

You don't strictly speaking need to copy the resources folder, it exists purely to create "standard" folder where custom scripts can store their resource files like images for example.

e-t-l commented 3 years ago

Thanks. I realized I forgot to include the contents of chrome.manifest so I updated my initial comment.

Based on what you're seeing here, does it look like I should just be able to drop a script with .uc.js filetype in my chrome folder and it should run?

MrOtherGuy commented 3 years ago

I don't know. In your current setup it goes like this:

  1. config.js makes firefox run boot.jsm
  2. boot.jsm looks for chrome.manifest to set some paths and loads userChrome.jsm from the same folder where it is at.
  3. userChrome.jsm does something

I don't know what that something is, so I can't tell where it looks for those .uc.js files (or some other files?) if it even loads any files.

Now, my loader does basically the same thing, except that it combines boot.jsm and userChrome.jsm into same file. And I can tell you that my loader does NOT load .uc.js files from chrome folder. It loads them from chrome/JS folder.

e-t-l commented 3 years ago

Thanks, I appreciate all your help. I did some digging and realized years ago I'd installed a script from https://github.com/xiaoxiaoflood/firefox-scripts/ that's responsible for this. I know I've been asking you to troubleshoot someone else's code, and I appreciate your patience. If I have trouble with scripts in the future, I'll go make noise in their issues section (or maybe I'll just delete their autoconfig and switch to yours instead).

e-t-l commented 3 years ago

@MrOtherGuy I decided to replace xiaoxiaoflood's loader with yours, and I'm just wondering, what purpose do userChrome_as_css.uc.js and userChrome_as_css_module.uc.js serve? I couldn't find any explanation in the Readme or commented in the files themselves.

MrOtherGuy commented 3 years ago

They are example script files that don't have any visible effect on their own. They try to register new stylesheet from file userChrome.as.css which would be loaded from the location where userChrome.css is. If the file doesn't exist they don't do anything except log an error to say the file could not be loaded.

Now that you mention it though, it would be better if they don't try to load the same file. And also, I should write a comment into both to explain what they do.

MrOtherGuy commented 3 years ago

If you are wondering why to load such a file in the first place, well userChrome.css is loaded as user style sheet. But there are some things you can't do with user style sheet, so they exist as a way to load new style sheet as agent style sheet.

e-t-l commented 3 years ago

That makes sense, thank you!

MrOtherGuy commented 3 years ago

So, FYI, I made a few changes to those example files. There is now two separate .uc.js files. The first one loads userChrome.ag.css and the other userChrome.au.css. These are now loaded from the chrome/resources/ folder, not the main chrome folder.