Skip to content

Commit

Permalink
Merge pull request #108 from TurboWarp/navigator
Browse files Browse the repository at this point in the history
New extension: Navigator Info
  • Loading branch information
GarboMuffin authored Dec 30, 2022
2 parents 186f58c + 8deca4d commit a38a408
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions extensions/navigator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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));

0 comments on commit a38a408

Please sign in to comment.