scratch-extension-docs/browser_extension.js
2014-08-07 09:56:52 -04:00

45 lines
1.1 KiB
JavaScript

// 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);
})({});