Added browser extension
This commit is contained in:
parent
07bcff9252
commit
ee12b14db0
1 changed files with 45 additions and 0 deletions
45
browser_extension.js
Normal file
45
browser_extension.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Scratch Extension to demonstrate some simple web browser functionality
|
||||
// 2014 Shane M. Clements
|
||||
|
||||
(function(ext) {
|
||||
ext.alert = function(message) {
|
||||
alert(message);
|
||||
};
|
||||
|
||||
ext.confirm = function(question) {
|
||||
return confirm(question);
|
||||
};
|
||||
|
||||
ext.ask = function(question) {
|
||||
return prompt(question);
|
||||
};
|
||||
|
||||
ext.setTitle = function(title) {
|
||||
window.document.title = title;
|
||||
};
|
||||
|
||||
ext.openTab = function(location) {
|
||||
window.open(location, '_blank');
|
||||
};
|
||||
|
||||
ext._shutdown = function() {
|
||||
console.log('Shutting down...');
|
||||
};
|
||||
|
||||
ext._getStatus = function() {
|
||||
return {status: 2, msg: 'Ready'};
|
||||
};
|
||||
|
||||
var descriptor = {
|
||||
blocks: [
|
||||
[' ', 'alert %s', 'alert', ''],
|
||||
['r', 'confirm %s', 'confirm', 'Are you sure?'],
|
||||
['r', 'ask %s', 'ask', 'How are you?'],
|
||||
[' ', 'set window title to %s', 'setTitle', 'title'],
|
||||
[' ', 'open tab with %s', 'openTab', 'https://twitter.com/scratchteam']
|
||||
]
|
||||
};
|
||||
|
||||
ScratchExtensions.register('Browser Stuff', descriptor, ext);
|
||||
})({});
|
||||
|
Reference in a new issue