forked from PenguinMod/penguinmod.github.io
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from redspacecat/develop
Adding Browser and OS Info extension
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Browser & OS Info | ||
// Created by @redspacecat | ||
|
||
(function(Scratch) { | ||
'use strict'; | ||
let newScript = document.createElement("script") | ||
newScript.src = "https://cdn.jsdelivr.net/npm/bowser@latest/bundled.js" | ||
document.getElementsByTagName("head")[0].appendChild(newScript) | ||
|
||
class BrowserAndOSInfo { | ||
getInfo() { | ||
return { | ||
id: "browserinfo", | ||
name: "Browser & OS Info", | ||
color1: "#449462", | ||
color2: "#35754d", | ||
color3: "#35754d", | ||
blocks: [ | ||
{ | ||
opcode: 'getBrowserName', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'get browser name', | ||
disableMonitor: true, | ||
}, | ||
{ | ||
opcode: 'getBrowserVersion', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'get browser version', | ||
disableMonitor: true, | ||
}, | ||
{ | ||
opcode: 'getOSName', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'get OS name', | ||
disableMonitor: true, | ||
}, | ||
{ | ||
opcode: 'getOSVersion', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'get OS version', | ||
disableMonitor: true, | ||
}, | ||
{ | ||
opcode: 'getPlatform', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'get platform', | ||
disableMonitor: true, | ||
}, | ||
{ | ||
opcode: 'getRenderingEngine', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'get rendering engine', | ||
disableMonitor: true, | ||
} | ||
] | ||
}; | ||
} | ||
|
||
getBowser() { | ||
try { | ||
let b = bowser.getParser(window.navigator.userAgent) | ||
return b | ||
} | ||
catch { | ||
return "script still loading!" | ||
} | ||
} | ||
|
||
getBrowserName() { | ||
const browser = this.getBowser() | ||
return browser.getBrowserName() | ||
} | ||
|
||
getBrowserVersion() { | ||
const browser = this.getBowser() | ||
return browser.getBrowserVersion() | ||
} | ||
|
||
getOSName() { | ||
const browser = this.getBowser() | ||
return browser.getOSName() | ||
} | ||
|
||
getOSVersion() { | ||
const browser = this.getBowser() | ||
return browser.getOS().versionName | ||
} | ||
|
||
getPlatform() { | ||
const browser = this.getBowser() | ||
return browser.getPlatformType() | ||
} | ||
|
||
getRenderingEngine() { | ||
const browser = this.getBowser() | ||
return browser.getEngineName() | ||
} | ||
} | ||
|
||
Scratch.extensions.register(new BrowserAndOSInfo()); | ||
})(Scratch); |