Added browser extension

This commit is contained in:
Shane M. Clements 2014-08-07 09:56:45 -04:00
parent 07bcff9252
commit ee12b14db0

45
browser_extension.js Normal file
View 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);
})({});