Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. (function(ext) {
  2. // TODO: public repo + documentation + samples
  3. // GH pages
  4. $.ajax({
  5.  
  6. async:false,
  7.  
  8. type:'GET',
  9.  
  10. url:'https://cdn.firebase.com/js/client/2.2.4/firebase.js',
  11.  
  12. data:null,
  13.  
  14. success: function(){fb = new Firebase('https://scratchx.firebaseio.com');console.log('ok');}, //Create a firebase reference
  15.  
  16. dataType:'script'
  17.  
  18. });
  19. window['temp'] = 0; // init
  20.  
  21. // Cleanup function when the extension is unloaded
  22. ext._shutdown = function() {};
  23.  
  24. // Status reporting code
  25. // Use this to report missing hardware, plugin or unsupported browser
  26. ext._getStatus = function() {
  27. return {status: 2, msg: 'Ready'};
  28. };
  29.  
  30. ext.broadcast = function(name) {
  31. if (name.length > 0){ // blank broadcasts break firebase - not nice.
  32. window['sent-' + name] = Math.random(); // HUGE thanks to the folks at White Mountain Science for fixing the multiple broadcast bug! (lines 32-40)
  33. fb.child('broadcasts/' + name).set(window['sent-' + name]); //Change value of broadcast so other clients get an update
  34. }
  35. };
  36.  
  37. ext.mesh_hat = function(name) {
  38. fb.child('broadcasts/' + name).on('value', function(snap){window['new-' + name] = snap.val();console.log(name);}); // Make sure broadcasts are unique (don't activate twice)
  39. if(window['last-' + name] != window['new-' + name] && window['new-' + name] != window['sent-' + name]){
  40. window['last-' + name] = window['new-' + name];
  41. return true;
  42. } else {
  43. return false;
  44. }
  45. }
  46. // Block and block menu descriptions
  47. var descriptor = {
  48. blocks: [
  49. [' ', 'mesh broadcast %s', 'broadcast'],
  50. ['h', 'when I receive mesh %s', 'mesh_hat']
  51. ],
  52. url: 'http://technoboy10.tk/mesh'
  53. };
  54.  
  55.  
  56. // Register the extension
  57. ScratchExtensions.register('Mesh', descriptor, ext);
  58. })({});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement