forked from LouCypher/mozcmd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
darken.mozcmd
58 lines (55 loc) · 1.57 KB
/
darken.mozcmd
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
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Contributor(s):
* - LouCypher (original code)
*/
/*
Based on 'Global - Pseudo Brightness Control' userstyle
http://userstyles.org/styles/45663
by luckymouse
http://userstyles.org/users/14255
License under Public Domain Dedication
http://creativecommons.org/publicdomain/zero/1.0/
*/
[
{
name: "darken",
description: "Darken content area.",
runAt: "client",
params: [
{
name: "Dark level",
type: {
name: "number",
min: 0,
max: 100,
},
defaultValue: 15,
description: "0 = normal; 100 = pitch dark"
}
],
exec: function(args, context) {
let darkLevel = args["Dark level"];
if (darkLevel < 0) darkLevel = 0;
if (darkLevel > 100) darkLevel = 100;
let opacity = 0;
if (darkLevel === 50)
opacity = darkLevel / 100;
else
opacity = (100 - darkLevel) / 100;
let browser = context.environment.chromeDocument.getElementById("browser");
let gBrowser = context.environment.chromeDocument.getElementById("content");
if (opacity === 1 || gBrowser.style.opacity === opacity.toString()) {
browser.style.backgroundColor = "";
gBrowser.style.opacity = "";
}
else {
browser.style.backgroundColor = "black";
gBrowser.style.opacity = opacity;
}
}
}
]