|
20 | 20 | var declaredVars = {}; |
21 | 21 |
|
22 | 22 | function xlateArgument(value) { |
23 | | - value = value.replace(/^\s+/, ''); |
24 | | - value = value.replace(/\s+$/, ''); |
25 | | - var r; |
26 | | - var r2; |
27 | | - var parts = []; |
28 | | - if ((r = /\$\{/.exec(value))) { |
29 | | - var regexp = /\$\{(.*?)\}/g; |
30 | | - var lastIndex = 0; |
31 | | - while ( (r2 = regexp.exec(value)) ) { |
32 | | - if (declaredVars[r2[1]]) { |
33 | | - if (r2.index - lastIndex > 0) { |
34 | | - parts.push(string(value.substring(lastIndex, r2.index))); |
35 | | - } |
36 | | - parts.push(declaredVars[r2[1]]); |
37 | | - lastIndex = regexp.lastIndex; |
38 | | - } else if (r2[1] == "nbsp") { |
39 | | - if (r2.index - lastIndex > 0) { |
40 | | - parts.push(declaredVars[string(value.substring(lastIndex, r2.index))]); |
41 | | - } |
42 | | - parts.push(nonBreakingSpace()); |
43 | | - lastIndex = regexp.lastIndex; |
44 | | - } |
| 23 | + value = value.replace(/^\s+/, ""); |
| 24 | + value = value.replace(/\s+$/, ""); |
| 25 | + var r; |
| 26 | + var r2; |
| 27 | + var parts = []; |
| 28 | + if ((r = /\$\{/.exec(value))) { |
| 29 | + var regexp = /\$\{(.*?)\}/g; |
| 30 | + var lastIndex = 0; |
| 31 | + while ((r2 = regexp.exec(value))) { |
| 32 | + if (declaredVars[r2[1]]) { |
| 33 | + if (r2.index - lastIndex > 0) { |
| 34 | + parts.push(string(value.substring(lastIndex, r2.index))); |
45 | 35 | } |
46 | | - if (lastIndex < value.length) { |
47 | | - parts.push(string(value.substring(lastIndex, value.length))); |
| 36 | + parts.push(declaredVars[r2[1]]); |
| 37 | + lastIndex = regexp.lastIndex; |
| 38 | + } else if (r2[1] == "nbsp") { |
| 39 | + if (r2.index - lastIndex > 0) { |
| 40 | + parts.push(declaredVars[string(value.substring(lastIndex, r2.index))]); |
48 | 41 | } |
49 | | - return parts.join(""); |
50 | | - } else { |
51 | | - return string(value); |
| 42 | + parts.push(nonBreakingSpace()); |
| 43 | + lastIndex = regexp.lastIndex; |
| 44 | + } |
52 | 45 | } |
| 46 | + if (lastIndex < value.length) { |
| 47 | + parts.push(string(value.substring(lastIndex, value.length))); |
| 48 | + } |
| 49 | + return parts.join(""); |
| 50 | + } else { |
| 51 | + return string(value); |
| 52 | + } |
53 | 53 | } |
54 | 54 |
|
55 | 55 | function string(value) { |
56 | | - if (value != null) { |
57 | | - value = value.replace(/\\/g, '\\\\'); |
58 | | - value = value.replace(/\"/g, '\\"'); |
59 | | - value = value.replace(/\r/g, '\\r'); |
60 | | - value = value.replace(/\n/g, '\\n'); |
61 | | - return value; |
62 | | - } else { |
63 | | - return ''; |
64 | | - } |
| 56 | + if (value != null) { |
| 57 | + value = value.replace(/\\\\/g, "\\"); |
| 58 | + value = value.replace(/\\r/g, "\r"); |
| 59 | + value = value.replace(/\\n/g, "\n"); |
| 60 | + return value; |
| 61 | + } else { |
| 62 | + return ""; |
| 63 | + } |
65 | 64 | } |
66 | 65 |
|
67 | | -function handleFormatCommand(message, sender, response) { |
68 | | - if (message.storeStr) { |
69 | | - declaredVars[message.storeVar] = message.storeStr; |
70 | | - } else if (message.echoStr) { |
71 | | - window.addLog("echo: " + message.echoStr); |
72 | | - } |
| 66 | +function handleFormatCommand(message) { |
| 67 | + if (message.storeStr) { |
| 68 | + declaredVars[message.storeVar] = message.storeStr; |
| 69 | + } else if (message.echoStr) { |
| 70 | + window.addLog("echo: " + message.echoStr); |
| 71 | + } |
73 | 72 | } |
74 | 73 |
|
75 | 74 | browser.runtime.onMessage.addListener(handleFormatCommand); |
| 75 | + |
0 commit comments