mirror of
https://github.com/scratchfoundation/scratch-extension-docs.git
synced 2024-11-30 03:15:44 -05:00
39 lines
No EOL
1.2 KiB
JavaScript
39 lines
No EOL
1.2 KiB
JavaScript
/* Extension demonstrating a blocking reporter block */
|
|
/* Sayamindu Dasgupta <sayamindu@media.mit.edu>, May 2014 */
|
|
|
|
|
|
new (function() {
|
|
var ext = this;
|
|
|
|
// Cleanup function when the extension is unloaded
|
|
ext._shutdown = function() {};
|
|
|
|
// Status reporting code
|
|
// Use this to report missing hardware, plugin or unsupported browser
|
|
ext._getStatus = function() {
|
|
return {status: 2, msg: 'Ready'};
|
|
};
|
|
|
|
ext.get_temp = function(location, callback) {
|
|
// Make an AJAX call to the Open Weather Maps API
|
|
$.ajax({
|
|
url: 'http://api.openweathermap.org/data/2.5/weather?q='+location+'&units=imperial',
|
|
dataType: 'jsonp',
|
|
success: function( weather_data ) {
|
|
// Got the data - parse it and return the temperature
|
|
temperature = weather_data['main']['temp'];
|
|
callback(temperature);
|
|
}
|
|
});
|
|
};
|
|
|
|
// Block and block menu descriptions
|
|
var descriptor = {
|
|
blocks: [
|
|
['R', 'current temperature in city %s', 'get_temp', 'Boston, MA'],
|
|
]
|
|
};
|
|
|
|
// Register the extension
|
|
ScratchExtensions.register('Weather extension', descriptor, ext);
|
|
})(); |