Repository navigation
Expand file tree
/
Copy pathwhatishappening.js
More file actions
83 lines (64 loc) · 1.9 KB
/
Copy pathwhatishappening.js
File metadata and controls
83 lines (64 loc) · 1.9 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
72
73
74
75
76
77
78
79
80
81
82
83
const icon = "";
class SBlox {
constructor() {}
getInfo() {
return {
id: 'sblox',
name: 'SBlox',
color1: '#8BC34A',
color2: '#7CB342',
color3: '#689F38',
menuIconURI: icon,
blocks: [
{
opcode: 'fetchThis',
blockType: Scratch.BlockType.REPORTER,
text: 'fetch content of URL [URL]',
arguments: {
URL: {
type: Scratch.ArgumentType.STRING,
defaultValue: ''
}
}
},
{
opcode: 'getToJSON',
blockType: Scratch.BlockType.REPORTER,
text: '[t] of JSON [e]',
arguments: {
t: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'version/checksum'
},
e: {
type: Scratch.ArgumentType.STRING,
defaultValue: '{"version": {"checksum": "hash", "version_of_project": 26.9}, "precise_version": "26.9.8194.103"}'
}
}
},
{
opcode: 'runJS',
blockType: Scratch.BlockType.STACK,
text: 'run JS anonymous function [a]'
arguments: {
a: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'alert("Hello World!");'
}
}
}
}
]
}
}
fetchThis({URL}) {
return fetch(URL).then(res=>res.text()).catch(err => 'error');
}
getToJSON({t,e}){
try{const n=t.toString().split("/").map(t=>decodeURIComponent(t));let r;""===n[0]&&n.splice(0,1),""===n[n.length-1]&&n.splice(-1,1);try{r=JSON.parse(" "+e)}catch(t){return t.message}return n.forEach(t=>r=r[t]),null===r?"null":void 0===r?"":"object"==typeof r?JSON.stringify(r):r.toString()}catch(t){return""}
}
runJS({a}){
running=Function(a); running();
}
}
Scratch.extensions.register(new SBlox());