forked from SideeX/sideex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
formatCommand.js
executable file
·57 lines (52 loc) · 1.72 KB
/
formatCommand.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Modified in remoteControl.js from selenium-IDE
var declaredVars = {};
function xlateArgument(value) {
value = value.replace(/^\s+/, '');
value = value.replace(/\s+$/, '');
var r;
var r2;
var parts = [];
if ((r = /\$\{/.exec(value))) {
var regexp = /\$\{(.*?)\}/g;
var lastIndex = 0;
while (r2 = regexp.exec(value)) {
if (declaredVars[r2[1]]) {
if (r2.index - lastIndex > 0) {
parts.push(string(value.substring(lastIndex, r2.index)));
}
parts.push(declaredVars[r2[1]]);
lastIndex = regexp.lastIndex;
} else if (r2[1] == "nbsp") {
if (r2.index - lastIndex > 0) {
parts.push(declaredVars[string(value.substring(lastIndex, r2.index))]);
}
parts.push(nonBreakingSpace());
lastIndex = regexp.lastIndex;
}
}
if (lastIndex < value.length) {
parts.push(string(value.substring(lastIndex, value.length)));
}
return parts.join("");
} else {
return string(value);
}
}
function string(value) {
if (value != null) {
value = value.replace(/\\/g, '\\\\');
value = value.replace(/\"/g, '\\"');
value = value.replace(/\r/g, '\\r');
value = value.replace(/\n/g, '\\n');
return value;
} else {
return '';
}
}
function handleFormatCommand(message, sender, response) {
if (message.storeStr) {
declaredVars[message.storeVar] = message.storeStr;
} else if (message.echoStr)
sideex_log.info("echo: " + message.echoStr);
}
browser.runtime.onMessage.addListener(handleFormatCommand);