-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
56 lines (53 loc) · 1.64 KB
/
timer.js
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
(function(Scratch) {
'use strict';
const vm = Scratch.vm;
let timer = {};
class Moretimer {
getInfo () {
return {
color1:"#7f7f7f",
id:"timer",
name:"more timer",
blocks:[
{
opcode:"clear_all",
blockType:Scratch.BlockType.COMMAND,
text:"clear all timer"
},
{
opcode:"clear",
blockType:Scratch.BlockType.COMMAND,
text:"start or reset timer[T]",
arguments:{
T:{
type:Scratch.ArgumentType.STRING,
defaultValue: "mytimer",
}
}
},
{
opcode:"get",
blockType:Scratch.BlockType.REPORTER,
text:"timer[T]",
arguments:{
T:{
type:Scratch.ArgumentType.STRING,
defaultValue:"mytimer",
}
}
}
]
};
}
clear_all(args, util){
timer = {};
}
clear(args, util){
timer[args.T.toString()] = Date.now();
}
get(args, util){
return (Date.now() - timer[args.T.toString()]) / 1000;
}
}
Scratch.extensions.register(new Moretimer());
})(Scratch);