-
Notifications
You must be signed in to change notification settings - Fork 27
/
userChromeAgentAuthorSheetLoader.sys.mjs
65 lines (63 loc) · 3.02 KB
/
userChromeAgentAuthorSheetLoader.sys.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// ==UserScript==
// @name Agent/Author Sheet Loader
// @version 2.6.4
// @author aminomancer
// @homepageURL https://github.com/aminomancer
// @description Load `*.ag.css` files as agent sheets and `*.au.css` files as author sheets. Will also load `*.us.css` files as user sheets, in case you ever need that for some reason. This loader is capable of loading stylesheets into browser toolbox windows, but it will not try to load [userChrome.css](https://github.com/aminomancer/uc.css.js/blob/master/userChrome.css) or [userContent.css](https://github.com/aminomancer/uc.css.js/blob/master/userContent.css) in the browser toolbox. For that you will need [userChromeDevtoolsSheetLoader.sys.mjs](https://github.com/aminomancer/uc.css.js#browser-toolbox-stylesheet-loader) instead.
// @downloadURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/userChromeAgentAuthorSheetLoader.sys.mjs
// @updateURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/userChromeAgentAuthorSheetLoader.sys.mjs
// @license This Source Code Form is subject to the terms of the Creative Commons Attribution-NonCommercial-ShareAlike International License, v. 4.0. If a copy of the CC BY-NC-SA 4.0 was not distributed with this file, You can obtain one at http://creativecommons.org/licenses/by-nc-sa/4.0/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
// @backgroundmodule
// ==/UserScript==
let sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(
Ci.nsIStyleSheetService
);
function traverseToMainProfile(str) {
let dir = Services.dirsvc.get(str, Ci.nsIFile);
if (!dir.exists()) {
let toAddChrome = false;
while (dir.target.includes("chrome_debugger_profile")) {
dir = dir.parent;
toAddChrome = true;
}
if (toAddChrome) dir.append("chrome");
}
return dir;
}
let chromeDir = traverseToMainProfile("UChrm");
let files = chromeDir.directoryEntries.QueryInterface(Ci.nsISimpleEnumerator);
if (files) {
while (files.hasMoreElements()) {
let file = files.getNext().QueryInterface(Ci.nsIFile);
let name = file.leafName;
if (!file.isFile()) continue;
if (/\.(?:au||ag||us)\.css$/i.test(name)) {
let typePrefix = name.split(".")[1];
let type, typeString;
switch (typePrefix) {
case "au":
type = sss.AUTHOR_SHEET;
typeString = "author sheet";
break;
case "ag":
type = sss.AGENT_SHEET;
typeString = "agent sheet";
break;
case "us":
type = sss.USER_SHEET;
typeString = "user sheet";
break;
}
let uri = Services.io
.getProtocolHandler("file")
.QueryInterface(Ci.nsIFileProtocolHandler)
.getURLSpecFromDir(chromeDir);
try {
sss.loadAndRegisterSheet(Services.io.newURI(uri + name), type);
console.info(`Loaded ${typeString}: ${name}`); // eslint-disable-line no-console
} catch (e) {
console.error(`Could not load ${name}: ${e.name}`);
}
}
}
}