-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea145ad
commit fa51c99
Showing
1 changed file
with
174 additions
and
174 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,209 +1,209 @@ | ||
(function(Scratch) { | ||
'use strict'; | ||
'use strict'; | ||
|
||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('Browser Utilities must run unsandboxed'); | ||
} | ||
if (!Scratch.extensions.unsandboxed) { | ||
throw new Error('Browser Utilities must run unsandboxed'); | ||
} | ||
|
||
class nkbrowserutils { | ||
getInfo() { | ||
return { | ||
id: 'nkbrowserutils', | ||
name: 'Browser Utilities', | ||
color1: '#504d6f', | ||
color2: '#36344b', | ||
blocks: [ | ||
{ | ||
opcode: 'isonline', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is online?' | ||
}, | ||
{ | ||
opcode: 'ismobile', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is mobile?' | ||
}, | ||
'---', | ||
{ | ||
opcode: 'getbrowser', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'user browser' | ||
}, | ||
{ | ||
opcode: 'geturl', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'current url' | ||
}, | ||
'---', | ||
{ | ||
opcode: 'setfavicon', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'set page favicon to [ICO]', | ||
arguments: { | ||
ICO: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'https://turbowarp.org/favicon.ico' | ||
} | ||
class BrowserUtils { | ||
getInfo() { | ||
return { | ||
id: 'nkbrowserutils', | ||
name: 'Browser Utilities', | ||
color1: '#504d6f', | ||
color2: '#36344b', | ||
blocks: [ | ||
{ | ||
opcode: 'isonline', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is online?' | ||
}, | ||
{ | ||
opcode: 'ismobile', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is mobile?' | ||
}, | ||
'---', | ||
{ | ||
opcode: 'getbrowser', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'user browser' | ||
}, | ||
{ | ||
opcode: 'geturl', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'current url' | ||
}, | ||
'---', | ||
{ | ||
opcode: 'setfavicon', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'set page favicon to [ICO]', | ||
arguments: { | ||
ICO: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'https://turbowarp.org/favicon.ico' | ||
} | ||
}, | ||
{ | ||
opcode: 'settitle', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'set page title to [TITLE]', | ||
arguments: { | ||
TITLE: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'My Page' | ||
} | ||
} | ||
}, | ||
{ | ||
opcode: 'settitle', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'set page title to [TITLE]', | ||
arguments: { | ||
TITLE: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: 'My Page' | ||
} | ||
}, | ||
{ | ||
opcode: 'reload', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'reload page', | ||
}, | ||
'---', | ||
{ | ||
opcode: 'tabactive', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is tab active?', | ||
}, | ||
{ | ||
opcode: 'darkmode', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is dark mode?', | ||
}, | ||
'---', | ||
{ | ||
opcode: 'alertBlock', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'alert [STRING]', | ||
arguments: { | ||
STRING: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: '' | ||
} | ||
} | ||
}, | ||
{ | ||
opcode: 'reload', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'reload page', | ||
}, | ||
'---', | ||
{ | ||
opcode: 'tabactive', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is tab active?', | ||
}, | ||
{ | ||
opcode: 'darkmode', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'is dark mode?', | ||
}, | ||
'---', | ||
{ | ||
opcode: 'alertBlock', | ||
blockType: Scratch.BlockType.COMMAND, | ||
text: 'alert [STRING]', | ||
arguments: { | ||
STRING: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: '' | ||
} | ||
}, | ||
{ | ||
opcode: 'inputPromptBlock', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'prompt [STRING]', | ||
disableMonitor: true, | ||
arguments: { | ||
STRING: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: '' | ||
} | ||
} | ||
}, | ||
{ | ||
opcode: 'inputPromptBlock', | ||
blockType: Scratch.BlockType.REPORTER, | ||
text: 'prompt [STRING]', | ||
disableMonitor: true, | ||
arguments: { | ||
STRING: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: '' | ||
} | ||
}, | ||
{ | ||
opcode: 'confirmationBlock', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'confirm [STRING]', | ||
arguments: { | ||
STRING: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: '' | ||
} | ||
} | ||
}, | ||
{ | ||
opcode: 'confirmationBlock', | ||
blockType: Scratch.BlockType.BOOLEAN, | ||
text: 'confirm [STRING]', | ||
arguments: { | ||
STRING: { | ||
type: Scratch.ArgumentType.STRING, | ||
defaultValue: '' | ||
} | ||
} | ||
] | ||
}; | ||
} | ||
async isonline() { | ||
try { | ||
const response = await Scratch.fetch('https://extensions.turbowarp.org/hello.txt'); | ||
return true; | ||
} catch (error){ | ||
return false; | ||
} | ||
} | ||
ismobile () { | ||
const userAgent = navigator.userAgent; | ||
return userAgent.includes('Android') || userAgent.includes('iPhone') || userAgent.includes('iPod') || userAgent.includes('iPad') || userAgent.includes('BlackBerry') || userAgent.includes('IEMobile') || userAgent.includes('Opera Mini'); | ||
} | ||
] | ||
}; | ||
} | ||
async isonline() { | ||
try { | ||
const response = await Scratch.fetch('https://extensions.turbowarp.org/hello.txt'); | ||
return true; | ||
} catch (error){ | ||
return false; | ||
} | ||
getbrowser () { | ||
const userAgent = navigator.userAgent; | ||
if (userAgent.includes('Edg')) { | ||
} | ||
ismobile () { | ||
const userAgent = navigator.userAgent; | ||
return userAgent.includes('Android') || userAgent.includes('iPhone') || userAgent.includes('iPod') || userAgent.includes('iPad') || userAgent.includes('BlackBerry') || userAgent.includes('IEMobile') || userAgent.includes('Opera Mini'); | ||
} | ||
getbrowser () { | ||
const userAgent = navigator.userAgent; | ||
if (userAgent.includes('Edg')) { | ||
return 'Microsoft Edge'; | ||
} else if (userAgent.includes('OPR')) { | ||
} else if (userAgent.includes('OPR')) { | ||
return 'Opera'; | ||
} else if (userAgent.includes('Firefox')) { | ||
} else if (userAgent.includes('Firefox')) { | ||
return 'Firefox'; | ||
} else if (userAgent.includes('Windows NT')) { | ||
} else if (userAgent.includes('Windows NT')) { | ||
return 'Internet Explorer'; | ||
} else if (userAgent.includes('Chrome')) { | ||
} else if (userAgent.includes('Chrome')) { | ||
return 'Chrome'; | ||
} else { | ||
} else { | ||
return 'Other'; | ||
} | ||
} | ||
geturl () { | ||
try { | ||
} | ||
geturl () { | ||
try { | ||
const currentUrl = window.location.href; | ||
return currentUrl; | ||
} catch (error){ | ||
return ''; | ||
} | ||
} catch (error){ | ||
return ''; | ||
} | ||
} | ||
|
||
settitle (args) { | ||
try { | ||
document.title = args.TITLE; | ||
} catch (error){ | ||
} | ||
settitle (args) { | ||
try { | ||
document.title = args.TITLE; | ||
} catch (error){ | ||
} | ||
} | ||
|
||
setfavicon (args) { | ||
try { | ||
// Not sure why this code shows up with errors in visual studio, however it works. | ||
var link = document.querySelector("link[rel~='icon']"); | ||
if (!link) { | ||
link = document.createElement('link'); | ||
link.rel = 'icon'; | ||
document.head.appendChild(link); | ||
} | ||
link.href = args.ICO; | ||
} catch (error){ | ||
setfavicon (args) { | ||
try { | ||
// Not sure why this code shows up with errors in visual studio, however it works. | ||
var link = document.querySelector("link[rel~='icon']"); | ||
if (!link) { | ||
link = document.createElement('link'); | ||
link.rel = 'icon'; | ||
document.head.appendChild(link); | ||
} | ||
link.href = args.ICO; | ||
} catch (error){ | ||
} | ||
} | ||
|
||
reload () { | ||
try { | ||
location.reload(); | ||
} catch (error){ | ||
} | ||
reload () { | ||
try { | ||
location.reload(); | ||
} catch (error){ | ||
} | ||
} | ||
|
||
tabactive () { | ||
try { | ||
return !document.hidden; | ||
} catch (error){ | ||
return true; | ||
} | ||
tabactive () { | ||
try { | ||
return !document.hidden; | ||
} catch (error){ | ||
return true; | ||
} | ||
} | ||
|
||
darkmode () { | ||
try { | ||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
} catch (error){ | ||
return false; | ||
} | ||
darkmode () { | ||
try { | ||
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches; | ||
} catch (error){ | ||
return false; | ||
} | ||
} | ||
|
||
// The following blocks were originally from LMS Utilities, repurposed with permission. | ||
alertBlock(args) { | ||
alert(args.STRING); | ||
} | ||
// The following blocks were originally from LMS Utilities, repurposed with permission. | ||
alertBlock(args) { | ||
alert(args.STRING); | ||
} | ||
|
||
inputPromptBlock(args) { | ||
return prompt(args.STRING); | ||
} | ||
inputPromptBlock(args) { | ||
return prompt(args.STRING); | ||
} | ||
|
||
confirmationBlock(args) { | ||
return confirm(args.STRING); | ||
} | ||
confirmationBlock(args) { | ||
return confirm(args.STRING); | ||
} | ||
Scratch.extensions.register(new nkbrowserutils()); | ||
})(Scratch); | ||
} | ||
Scratch.extensions.register(new BrowserUtils()); | ||
})(Scratch); |