<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="favicon.png">
<title></title>
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" />
<style>
</style>
</head>
<body>
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
<script src="script.js"></script>
</body>
</html>
var toolbox = {
"kind": "categoryToolbox",
"contents": [
{
"kind": "category",
"name": "Control",
"contents": [
{
"kind": "block",
"type": "controls_if"
},
{
"kind": "block",
"type": "controls_repeat_ext"
},
]
},
{
"kind": "category",
"name": "Logic",
"contents": [
{
"kind": "block",
"type": "logic_compare"
},
{
"kind": "block",
"type": "logic_operation"
},
{
"kind": "block",
"type": "logic_boolean"
}
]
},
{
"kind": "category",
"name": "Math",
"contents": [
{
"kind": "block",
"type": "math_number"
},
{
"kind": "block",
"type": "math_arithmetic"
}
]
},
{
"kind": "category",
"name": "Text",
"contents": [
{
"kind": "block",
"type": "text"
},
{
"kind": "block",
"type": "text_print"
},
{
"kind": "block",
"type": "text_indexOf"
},
{
"kind": "block",
"type": "text_charAt"
},
]
},
{
"kind": "category",
"name": "Lists",
"contents": [
{
"kind": "block",
"type": "lists_create_empty"
},
{
"kind": "block",
"type": "lists_length"
}
]
},
{
"kind": "category",
"name": "Variables",
"contents": [
{
"kind": "block",
"type": "variables_set"
},
{
"kind": "block",
"type": "variables_get"
}
]
},
]
}
var blocklyDiv = document.getElementById('blocklyDiv');
blocklyDiv.style.height = (window.innerHeight-16)+"px";
blocklyDiv.style.width = (window.innerWidth-16)+"px";
var workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
function save() {
var json = Blockly.serialization.workspaces.save(workspace);
console.log(JSON.stringify(json));
window.localStorage.set('workspace',JSON.stringify(json));
}
function load(input) {
var json;
if (input){
json = JSON.parse(input);
workspace.clear();
Blockly.serialization.workspaces.load(json, workspace);
}
else if (window.localStorage.get('workspace')){
json = JSON.parse(window.localStorage.get('workspace'));
workspace.clear();
Blockly.serialization.workspaces.load(json, workspace);
}
}