forked from aminomancer/uc.css.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackingProtectionMiddleClickToggle.uc.js
101 lines (100 loc) · 3.54 KB
/
trackingProtectionMiddleClickToggle.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
93
94
95
96
97
98
99
100
101
// ==UserScript==
// @name Tracking Protection Middle Click Toggle
// @version 1.0.2
// @author aminomancer
// @homepageURL https://github.com/aminomancer/uc.css.js
// @description Middle click the tracking protection icon in the urlbar to enable/disable tracking protection on the active tab. A minor change, but it's faster than left-clicking to open the panel, then clicking the actual toggle switch.
// @downloadURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/trackingProtectionMiddleClickToggle.uc.js
// @updateURL https://cdn.jsdelivr.net/gh/aminomancer/uc.css.js@master/JS/trackingProtectionMiddleClickToggle.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.
// ==/UserScript==
(function () {
function init() {
gProtectionsHandler.handleProtectionsButtonEvent = function (event) {
event.stopPropagation();
let box = gProtectionsHandler.iconBox;
switch (event.type) {
case "click":
switch (event.button) {
case 1:
gProtectionsHandler.onTPSwitchCommand();
if (
window.matchMedia("(prefers-reduced-motion: no-preference)")
.matches
) {
box.addEventListener(
"animationend",
() => box.removeAttribute("animate"),
{
once: true,
}
);
box.setAttribute("animate", "true");
}
// fall through
case 2:
return;
}
break;
case "keypress":
if (
event.charCode != KeyEvent.DOM_VK_SPACE &&
event.keyCode != KeyEvent.DOM_VK_RETURN
) {
return;
}
break;
}
this.showProtectionsPopup({ event });
};
}
if (window.matchMedia("(prefers-reduced-motion: no-preference)").matches) {
let styleSvc = Cc["@mozilla.org/content/style-sheet-service;1"].getService(
Ci.nsIStyleSheetService
);
let css = /* css */ `@media (prefers-reduced-motion: no-preference) {
#tracking-protection-icon-box[animate] #tracking-protection-icon {
animation-name: uc-scale-pulse;
animation-duration: 200ms;
animation-iteration-count: 1;
animation-timing-function: ease-in-out;
transform-style: flat;
backface-visibility: hidden;
}
#tracking-protection-icon-box[animate] {
overflow: visible;
}
}
@keyframes uc-scale-pulse {
from {
transform: scale(1);
}
40% {
transform: scale(0.8);
}
to {
transform: scale(1);
}
}`;
let styleURI = makeURI(
`data:text/css;charset=UTF=8,${encodeURIComponent(css)}`
);
if (!styleSvc.sheetRegistered(styleURI, styleSvc.AUTHOR_SHEET)) {
styleSvc.loadAndRegisterSheet(styleURI, styleSvc.AUTHOR_SHEET);
}
}
if (gBrowserInit.delayedStartupFinished) {
init();
} else {
let delayedListener = (subject, topic) => {
if (topic == "browser-delayed-startup-finished" && subject == window) {
Services.obs.removeObserver(delayedListener, topic);
init();
}
};
Services.obs.addObserver(
delayedListener,
"browser-delayed-startup-finished"
);
}
})();