-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigator.js
100 lines (96 loc) · 2.55 KB
/
navigator.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
(function(Scratch) {
'use strict';
class NavigatorInfo {
getInfo () {
return {
id: 'navigatorinfo',
name: 'Navigator Info',
blocks: [
{
opcode: 'getOS',
blockType: Scratch.BlockType.REPORTER,
text: 'operating system'
},
{
opcode: 'getBrowser',
blockType: Scratch.BlockType.REPORTER,
text: 'browser'
},
{
opcode: 'getMemory',
blockType: Scratch.BlockType.REPORTER,
text: 'device memory'
},
{
opcode: 'getMonitorSizeW',
blockType: Scratch.BlockType.REPORTER,
text: 'monitor width'
},
{
opcode: 'getMonitorSizeH',
blockType: Scratch.BlockType.REPORTER,
text: 'monitor height'
},
{
opcode: 'getCanvasSizeW',
blockType: Scratch.BlockType.REPORTER,
text: 'canvas width'
},
{
opcode: 'getCanvasSizeH',
blockType: Scratch.BlockType.REPORTER,
text: 'canvas height'
},
]
};
}
getOS () {
const userAgent = navigator.userAgent;
if (userAgent.includes('Windows')) {
return 'Windows';
} else if (userAgent.includes('Android')) {
return 'Android';
} else if (userAgent.includes('iPhone') || userAgent.includes('iPod') || userAgent.includes('iPad')) {
return 'iOS';
} else if (userAgent.includes('Linux')) {
return 'Linux';
} else if (userAgent.includes('CrOS')) {
return 'ChromeOS';
} else if (userAgent.includes('Mac OS')) {
return 'macOS';
}
return 'Other';
}
getBrowser () {
const userAgent = navigator.userAgent;
if (userAgent.includes('Chrome')) {
return 'Chrome';
} else if (userAgent.includes('Firefox')) {
return 'Firefox';
} else if (userAgent.includes('Safari')) {
return 'Safari';
}
return 'Other';
}
getMemory(){
if (navigator.deviceMemory == undefined) {
return 'Unsupported';
} else {
return navigator.deviceMemory;
}
}
getMonitorSizeW(){
return window.screen.width;
}
getMonitorSizeH(){
return window.screen.height;
}
getCanvasSizeW(){
return vm.renderer.canvas.width
}
getCanvasSizeH(){
return vm.renderer.canvas.height
}
}
Scratch.extensions.register(new NavigatorInfo());
}(Scratch));