forked from aminomancer/uc.css.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
userChromeAgentAuthorSheetLoader.uc.js
63 lines (61 loc) · 2.62 KB
/
userChromeAgentAuthorSheetLoader.uc.js
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
// ==UserScript==
// @name Agent/Author Sheet Loader
// @version 2.6
// @author aminomancer
// @homepage 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 or userContent.css in the browser toolbox. For that you will need userChromeDevtoolsSheetLoader.uc.js instead.
// @backgroundmodule
// ==/UserScript==
let EXPORTED_SYMBOLS = [];
(function () {
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
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) return;
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}`);
} catch (e) {
console.error(`Could not load ${name}: ${e.name}`);
}
}
}
})();