-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (33 loc) · 932 Bytes
/
index.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
require('./index.css');
var keymage = require('keymage');
var nanoModal = require('nanomodal');
keymage('ctrl-shift-c', function() {
var Marty = window.Marty;
if (!Marty) {
console.warn('Marty not found on page');
return;
}
nanoModal("Marty State").onShow(function (modal) {
modal.setContent(content());
function content() {
var state = Marty.dehydrate();
var textarea = document.createElement("textarea")
textarea.cols = 50
textarea.rows = 5;
textarea.value = JSON.stringify(state);
textarea.onchange = updateState;
textarea.onkeyup = updateState;
textarea.onpaste = updateState;
function updateState() {
try {
var json = JSON.parse(textarea.value);
Marty.rehydrate(json);
} catch (e) {
console.error('Invalid JSON');
}
}
return textarea;
}
}).show();
return false;
});