-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathanimateContextMenus.uc.js
92 lines (90 loc) · 3.58 KB
/
animateContextMenus.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// ==UserScript==
// @name Animate Context Menus
// @version 1.0.4
// @author aminomancer
// @homepage https://github.com/aminomancer/uc.css.js
// @description Give all context menus the same opening animation that panel popups like the app menu have — the menu slides down 70px and fades in opacity at the same time. It's a cool effect that doesn't trigger a reflow since it uses transform, but it does repaint the menu, so I wouldn't recommend using this on weak hardware.
// @downloadURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/animateContextMenus.uc.js
// @updateURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/animateContextMenus.uc.js
// @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.
// @include *
// ==/UserScript==
class AnimateContextMenus {
constructor() {
document.documentElement.setAttribute("animate-menupopups", true);
addEventListener("popupshowing", this);
addEventListener("popupshown", this);
addEventListener("popuphidden", this);
let css = `:root[animate-menupopups]
:not(menulist)
> menupopup:not([position], [type="arrow"], [animate="false"]) {
opacity: 0;
transform: translateY(-70px) scaleX(0.95) scaleY(0.5);
transform-origin: top;
transition-property: transform, opacity;
transition-duration: 0.18s, 0.18s;
transition-timing-function: var(--animation-easing-function, cubic-bezier(0.07, 0.95, 0, 1)),
ease-out;
transform-style: flat;
backface-visibility: hidden;
}
:root[animate-menupopups]
:not(menulist)
> menupopup:not([position], [type="arrow"])[animate][animate="open"] {
opacity: 1;
transition-duration: 0.18s, 0.18s;
transform: none !important;
transition-timing-function: var(--animation-easing-function, cubic-bezier(0.07, 0.95, 0, 1)),
ease-in-out;
}
:root[animate-menupopups]
:not(menulist)
> menupopup:not([position], [type="arrow"])[animate][animate="cancel"] {
transform: none;
}
:root[animate-menupopups] :not(menulist) > menupopup:not([position], [type="arrow"])[animating] {
pointer-events: none;
}`;
let sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(
Ci.nsIStyleSheetService
);
let uri = Services.io.newURI(
`data:text/css;charset=UTF=8,${encodeURIComponent(css)}`
);
if (!sss.sheetRegistered(uri, sss.AUTHOR_SHEET)) {
sss.loadAndRegisterSheet(uri, sss.AUTHOR_SHEET);
}
}
handleEvent(e) {
if (e.target.tagName !== "menupopup") return;
if (e.target.hasAttribute("position")) return;
if (e.target.getAttribute("type") == "arrow") return;
if (e.target.parentElement) {
if (e.target.parentElement.tagName == "menulist") return;
}
if (
e.target.shadowRoot &&
e.target.shadowRoot.firstElementChild.classList.contains(
"panel-arrowcontainer"
)
) {
return;
}
this[`on_${e.type}`](e);
}
on_popupshowing(e) {
if (e.target.getAttribute("animate") != "false") {
e.target.setAttribute("animate", "open");
e.target.setAttribute("animating", "true");
}
}
on_popupshown(e) {
e.target.removeAttribute("animating");
}
on_popuphidden(e) {
if (e.target.getAttribute("animate") != "false") {
e.target.removeAttribute("animate");
}
}
}
new AnimateContextMenus();