-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline.js
More file actions
69 lines (62 loc) · 2.12 KB
/
offline.js
File metadata and controls
69 lines (62 loc) · 2.12 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
$(function(){
var worker = new Worker("js/worker.js");
chrome.storage.local.set({"all-code": []});
var init = function(){
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/python");
editor.setFontSize(14);//set default font size to 14
editor.commands.addCommand({
name: 'Submit',
bindKey: {win: 'Shift-Enter', mac: 'Shift-Enter'},
exec: function(editor){
var code = editor.getValue();
chrome.storage.local.get("all-code", function(data){
if (chrome.runtime.lastError) {
return;
}
chrome.storage.local.set({"all-code": [].concat(data["all-code"], code)});
});
evalPythonCode(code);
}
});
editor.commands.addCommand({
name: 'Enter',
bindKey: {win: 'Enter', mac: 'Enter'},
exec: function(editor){
chrome.storage.local.set({"offline-python": editor.getValue()});
editor.insert("\n");//hack insert a new line
}
});
return editor;
};
//update the output
var updateOutput= function(output){
$(".output").append(output.data);
};
var evalPythonCode = function(code){
worker.addEventListener('message', updateOutput, false);
worker.postMessage(code);
};
var editor = init();
chrome.storage.local.get("offline-python", function(data) {
if (chrome.runtime.lastError) {
return;
}
editor.setValue(data["offline-python"]);
});
//theme change
$("#theme").on('change', function(){
console.log($("#theme").val());
editor.setTheme($("#theme").val());
});
//fontsize
$("#fontsize").on("change", function(){
console.log($("#fontsize").val());
editor.setFontSize($("#fontsize").val());
});
//clear output
$("#clear-output").on("click enter", function(){
$(".output").html("");
});
});