-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwinsize.mozcmd
65 lines (60 loc) · 1.81 KB
/
winsize.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
59
60
61
62
63
64
65
/*
* 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)
*/
[
{
name: "winsize",
description: "Resize browser window. If no parameters entered, display current window size.",
params: [
{
name: "width",
type: "number",
defaultValue: null,
description: "Browser width"
},
{
name: "height",
type: "number",
defaultValue: null,
description: "Browser height"
},
{
name: "center",
type: "boolean",
description: "Center window on screen"
}
],
returnType: "string",
exec: function(args, context) {
let environment = context.environment;
let chromeWin = environment.chromeWindow || environment.chromeDocument.defaultView;
let chromeDoc = environment.chromeDocument;
let browserWin = chromeDoc.documentElement;
let screen = chromeWin.screen;
function centerScreen() {
chromeWin.moveTo((screen.availWidth - browserWin.width) / 2,
(screen.availHeight - browserWin.height) / 2);
}
let width = args.width, height = args.height, center = args.center;
if (width && height) {
chromeWin.resizeTo(width, height);
if (center)
centerScreen();
return "Resized to " + width + "x" + height;
}
if (center)
centerScreen();
switch (chromeWin.windowState) {
case 3: // normal
return browserWin.width + "x" + browserWin.height;
case 1: // maximized
return browserWin.clientWidth + "x" + browserWin.clientHeight;
}
}
}
]