-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
260 lines (243 loc) · 8.81 KB
/
index.html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<html>
<title>Business Graphs</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="w3/w3.css">
<link rel="icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="codemirror/codemirror.css">
<link rel="stylesheet" href="codemirror/foldgutter.css">
<script src="w3/w3.js"></script>
<script src="codemirror/codemirror.js"></script>
<script src="codemirror/matchbrackets.js"></script>
<script src="codemirror/continuecomment.js"></script>
<script src="codemirror/comment.js"></script>
<script src="codemirror/foldcode.js"></script>
<script src="codemirror/javascript.js"></script>
<script src="codemirror/sql.js"></script>
<script src="codemirror/markdown.js"></script>
<script src="codemirror/meta.js"></script>
<script src="codemirror/overlay.js"></script>
<script src="codemirror/gfm.js"></script>
<script src="codemirror/foldgutter.js"></script>
<script src="codemirror/brace-fold.js"></script>
<script lang="javascript" src="libs/jquery.min.js"></script>
<script lang="javascript" src="libs/jszip.min.js"></script>
<script lang="javascript" src="libs/filesaver.min.js"></script>
<script lang="javascript" src="dist/pptxgen.js"></script>
<script lang="javascript" src="dist/pptxgen.shapes.js"></script>
<script type="text/javascript" src="libs/aes.js"></script>
<script type="text/javascript" src="libs/FileSaver.js"></script>
<style type="text/css">
.border {
border: 1px solid #d7d4f0;
}
.custom-upload input {
left: -9999px;
position: absolute;
}
</style>
<body>
<!--
<nav class="w3-sidenav w3-light-grey" style="display:none" id="mySidenav">
<a href="javascript:void(0)"
onclick="w3_close()"
class="w3-closenav w3-large">Close ×</a>
</nav>
-->
<header class="w3-container w3-teal">
<!-- <span class="w3-opennav w3-xlarge w3-layout-cell" onclick="w3_open()">☰</span> -->
<h1 class="w3-layout-cell" > Business Graph PowerPoint Generator</h1>
</header>
<div class="w3-container">
<div class="w3-panel w3-card-2">
<nav class="w3-navbar" >
<small>
<a id="a_error" href="#" onclick="toggleShow('error');return false;" class="w3-btn w3-grey w3-text-white">{{error}}</a>
</small>
</nav>
<!-- errors output -->
<div id="error" class="w3-container border">
</div>
</div>
<div class="w3-panel w3-card-2">
<nav class="w3-navbar" >
<small>
<a id="a_jsonm" href="#" onclick="toggleShow('jsonm');return false;" class="w3-btn w3-grey w3-text-white">{{jsonm}}</a>
<label class="custom-upload w3-btn w3-grey w3-text-white"><input type="file" id="jsonfile">Input File to Render</label>
<label class="custom-upload w3-btn w3-grey w3-text-white"><input type="file" id="keyfile">load key</label>
<a id="a_encode" href="#" onclick="encode();return false;" class="w3-btn w3-grey w3-text-white">Encode</a>
<a id="a_decode" href="#" onclick="decode();return false;" class="w3-btn w3-grey w3-text-white">Decode</a>
<a id="a_genkey" href="#" onclick="genkey();return false;" class="w3-btn w3-grey w3-text-white">Generate Key</a>
<a id="a_dowload" href="#" onclick="do_download();return false;" class="w3-btn w3-grey w3-text-white">Download File</a>
</small>
</nav>
<!-- json marimekko editor (read from file) -->
<div id="d_jsonm" class="w3-container">
<textarea id="jsonm" cols='150' rows='25'>
</textarea>
</div>
</div>
<div class="w3-panel w3-card-2">
<nav class="w3-navbar" >
<small>
<a id="a_jscode" href="#" onclick="toggleShow('jscode');return false;" class="w3-btn w3-grey w3-text-white">{{jscode}}</a>
<label class="custom-upload w3-btn w3-grey w3-text-white"><input type="file" id="codefile">Input File to Execute</label>
<a id="a_refresh" href="#" onclick="execute_code();return false;" class="w3-btn w3-grey w3-text-white">execute code</a>
</small>
</nav>
<!-- javascript code to generate pptx -->
<div id="d_jscode" class="w3-container">
<textarea id="jscode" cols='150' rows='25'>
</textarea>
</div>
</div>
</div>
<footer class="w3-container w3-teal">
<small>Copyright © Gilbert Brault 2016,2017
license <a href="https://creativecommons.org/licenses/by/4.0/"><img src="images/cc.logo.white.svg" width="5%"/></a>
</small>
</footer>
<script>
var graphfile="marimekko.json"
var codefile="jscode.js"
if(window.location.search.length!=0){
var tokens = window.location.search.substr(1).split("&");
for(var i=0; i<tokens.length;i++){
var token = tokens[i].split("=");
if(token.length>1){
if(token[0]=="code"){
codefile = token[1];
} else if (token[0]=="file"){
graphfile=token[1];
}
}
}
}
var derror=true;
w3.displayObject("a_error",{error:"hide Error panel"});
var div_error=document.getElementById("error");
window.e_jsonm = CodeMirror.fromTextArea(document.getElementById("jsonm"), {
mode: "javascript",
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
continueComments: "Enter",
});
w3.getHttpData(graphfile, function(text){
window.e_jsonm.getDoc().setValue(text);
});
w3.displayObject("a_jsonm",{jsonm:"hide file json file Editor"});
var jsonm=true;
window.e_jscode = CodeMirror.fromTextArea(document.getElementById("jscode"), {
mode: "javascript",
lineNumbers: true,
lineWrapping: true,
matchBrackets: true,
foldGutter: false,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
continueComments: "Enter",
});
w3.getHttpData(codefile, function(text){
window.e_jscode.getDoc().setValue(text);
});
w3.displayObject("a_jscode",{jscode:"hide javascript Editor"});
var jscode=true;
function toggleShow(id){
switch(id){
case 'error':
w3.toggleShow("#d_"+id);
derror = !derror;
if(derror){
w3.displayObject("a_"+id,{error:"hide Error panel"});
} else {
w3.displayObject("a_"+id,{error:"show Error panel"});
}
break;
case 'jsonm':
w3.toggleShow("#d_"+id);
jsonm = !jsonm;
if(jsonm){
w3.displayObject("a_"+id,{jsonm:"hide json Editor"});
} else {
w3.displayObject("a_"+id,{jsonm:"show json Editor"});
}
break;
case 'jscode':
w3.toggleShow("#d_"+id);
jscode = !jscode;
if(jscode){
w3.displayObject("a_"+id,{jscode:"hide javascript Editor"});
} else {
w3.displayObject("a_"+id,{jscode:"show javascript Editor"});
}
break;
}
}
function execute_code(){
eval(window.e_jscode.getDoc().getValue());
}
var jsonfile = document.getElementById('jsonfile');
jsonfile.addEventListener('change', function(e) {
var file = jsonfile.files[0];
var reader = new FileReader();
reader.onload = function(e) {
window.e_jsonm.getDoc().setValue(e.target.result);
}
reader.readAsText(file);
});
var codefile = document.getElementById('codefile');
codefile.addEventListener('change', function(e) {
var file = codefile.files[0];
var reader = new FileReader();
reader.onload = function(e) {
window.e_jscode.getDoc().setValue(e.target.result);
}
reader.readAsText(file);
});
var keyfile = document.getElementById('keyfile');
keyfile.addEventListener('change', function(e) {
var file = keyfile.files[0];
var reader = new FileReader();
reader.onload = function(e) {
window.keyfile=JSON.parse(e.target.result);
}
reader.readAsText(file);
});
function encode(){
var aesCtr = new aesjs.ModeOfOperation.ctr(window.keyfile.key, new aesjs.Counter(5));
var text = window.e_jsonm.getDoc().getValue();
var textBytes = aesjs.utils.utf8.toBytes(text);
var encryptedBytes = aesCtr.encrypt(textBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
window.e_jsonm.getDoc().setValue(encryptedHex);
}
function decode(){
var encryptedBytes = aesjs.utils.hex.toBytes(window.e_jsonm.getDoc().getValue());
var aesCtr = new aesjs.ModeOfOperation.ctr(window.keyfile.key, new aesjs.Counter(5));
var decryptedBytes = aesCtr.decrypt(encryptedBytes);
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
window.e_jsonm.getDoc().setValue(decryptedText);
}
function genkey(){
var key = new Uint8Array(32);
window.crypto.getRandomValues(key);
var jsonkey = JSON.stringify({key:Array.from(key)});
var d = new Date();
var n = d.toString();
var blob = new Blob([jsonkey], {type: "text/plain;charset=utf-8"});
saveAs(blob, "key_"+n+".txt");
}
function do_download(){
var blob = new Blob([window.e_jsonm.getDoc().getValue()], {type: "text/plain;charset=utf-8"});
var d = new Date();
var n = d.toString();
saveAs(blob, "file_"+n+".json");
}
</script>
</body>
</html>