-
Notifications
You must be signed in to change notification settings - Fork 0
/
navigator.js
56 lines (52 loc) · 1.48 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
(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'
}
]
};
}
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';
}
}
Scratch.extensions.register(new NavigatorInfo());
}(Scratch));