forked from aminomancer/uc.css.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
autocompletePopupStyler.uc.js
47 lines (45 loc) · 2.42 KB
/
autocompletePopupStyler.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
// ==UserScript==
// @name Autocomplete Popup Styler
// @version 1.0
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description This mini-script adds an attribute to #PopupAutoComplete when it's opened on a panel in the chrome UI, rather than opened on an input field in the content area. The reason for this is that my style gives panels and menupopups the same background color. So without this, if the autocomplete popup opened on a panel (for example the password update notification popup) it would end up blending in with the panel which doesn't look great. When it opens inside the content area, we want it to keep its normal background color, var(--arrowpanel-background). But when it opens in a panel, we want to give it a brighter background color, var(--autocomplete-background). This is implemented in uc-popups.css by this rule: panel#PopupAutoComplete[type="autocomplete-richlistbox"][anchored-on-panel]{background-color: var(--autocomplete-background) !important;}
// ==/UserScript==
(function () {
class AutocompletePopupStyler {
constructor() {
this.autocomplete.addEventListener("popupshowing", this);
}
handleEvent(_e) {
this.autocomplete.toggleAttribute("anchored-on-panel", this.sameBG);
}
get sameBG() {
if (!this.autocomplete.anchorNode) return false;
return (
getComputedStyle(this.panelShadowContent).backgroundColor ===
getComputedStyle(this.autocomplete).backgroundColor
);
}
get autocomplete() {
return (
this._autocomplete ||
(this._autocomplete = document.getElementById("PopupAutoComplete"))
);
}
get panelShadowContent() {
return this.autocomplete.anchorNode
?.closest("panel")
.shadowRoot.querySelector(`[part="content"]`);
}
}
if (gBrowserInit.delayedStartupFinished) new AutocompletePopupStyler();
else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
new AutocompletePopupStyler();
}
};
Services.obs.addObserver(delayedListener, "browser-delayed-startup-finished");
}
})();