-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.js
40 lines (36 loc) · 1016 Bytes
/
inject.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
var var_regex = /\(\?(.+?)\)/m;
var esc_regex = /\(\\(\\*)\?/;
$(document).ready(function() {
setInterval(checkForButton, 500);
$('body').mouseup(mouseUp);
$('body').mousemove(mouseMove);
});
function checkForButton() {
var element = $('.toolbar .draw');
if (element.length > 0) {
if ($('#notebook-button').length == 0) {
element.after(createNotebookButton());
}
} else if ($('#notebook-dialog').length > 0) {
closeNotebookDialog();
}
}
function variableReplace(text, noprompt) {
console.log('text: ' + text);
var variables = {};
var value = '';
var match = var_regex.exec(text);
while (match) {
if (!variables[match[1]]) {
if (noprompt) {
variables[match[1]] = match[1];
} else {
variables[match[1]] = prompt(match[1]) || match[1];
}
}
text = text.replace(var_regex, variables[match[1]]);
match = var_regex.exec(text);
}
text = text.replace(esc_regex, '($1?');
return text;
}