OLD | NEW |
1 /* | 1 /* |
2 * This Source Code is subject to the terms of the Mozilla Public License | 2 * This Source Code is subject to the terms of the Mozilla Public License |
3 * version 2.0 (the "License"). You can obtain a copy of the License at | 3 * version 2.0 (the "License"). You can obtain a copy of the License at |
4 * http://mozilla.org/MPL/2.0/. | 4 * http://mozilla.org/MPL/2.0/. |
5 */ | 5 */ |
6 | 6 |
7 Cu.import("resource://gre/modules/Services.jsm"); | 7 Cu.import("resource://gre/modules/Services.jsm"); |
8 | 8 |
9 let {Prefs} = require("prefs"); | 9 let {Prefs} = require("prefs"); |
10 Prefs.addListener(onPrefChange); | 10 Prefs.addListener(onPrefChange); |
(...skipping 29 matching lines...) Expand all Loading... |
40 let ruleListElement = E("custom_corrections"); | 40 let ruleListElement = E("custom_corrections"); |
41 let whitelistElement = E("whitelist"); | 41 let whitelistElement = E("whitelist"); |
42 | 42 |
43 // Remove existing list entries | 43 // Remove existing list entries |
44 for (let i = ruleListElement.getRowCount() - 1; i >= 0; i--) | 44 for (let i = ruleListElement.getRowCount() - 1; i >= 0; i--) |
45 ruleListElement.removeItemAt(i); | 45 ruleListElement.removeItemAt(i); |
46 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--) | 46 for (let i = whitelistElement.getRowCount() - 1; i >= 0; i--) |
47 whitelistElement.removeItemAt(i); | 47 whitelistElement.removeItemAt(i); |
48 | 48 |
49 // Build a list of custom rules and sort it alphabetically | 49 // Build a list of custom rules and sort it alphabetically |
50 let customRules = Prefs.custom_replace; | 50 let prefRulesList = Prefs.custom_replace; |
| 51 let prefWhitelist = Prefs.whitelist; |
51 let ruleList = []; | 52 let ruleList = []; |
52 let whitelist = []; | 53 let whitelist = []; |
53 for (let searchString in customRules) | 54 |
| 55 for (let searchString in prefRulesList) |
54 { | 56 { |
55 if(searchString == customRules[searchString]) | 57 ruleList.push([searchString, prefRulesList[searchString]]); |
56 { | 58 } |
57 whitelist.push(searchString); | 59 for (let searchString in prefWhitelist) |
58 } | 60 { |
59 else | 61 whitelist.push(searchString); |
60 { | |
61 ruleList.push([searchString, customRules[searchString]]); | |
62 } | |
63 } | 62 } |
64 | 63 |
65 ruleList.sort(function(a, b) | 64 ruleList.sort(function(a, b) |
66 { | 65 { |
67 if (a[0] < b[0]) | 66 if (a[0] < b[0]) |
68 return -1; | 67 return -1; |
69 else if (a[0] > b[0]) | 68 else if (a[0] > b[0]) |
70 return 1; | 69 return 1; |
71 else | 70 else |
72 return 0; | 71 return 0; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (searchString.length == 0) | 130 if (searchString.length == 0) |
132 return; | 131 return; |
133 | 132 |
134 Prefs.custom_replace[searchString] = replacement; | 133 Prefs.custom_replace[searchString] = replacement; |
135 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); | 134 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); |
136 | 135 |
137 E("find").value = E("replace").value = ""; | 136 E("find").value = E("replace").value = ""; |
138 E("find").oninput(); | 137 E("find").oninput(); |
139 } | 138 } |
140 | 139 |
141 function removeRule(btn) | 140 function removeRule(btn, pref) |
142 { | 141 { |
143 let list = E(btn.getAttribute("_list")); | 142 let list = E(btn.getAttribute("_list")); |
144 let items = list.selectedItems; | 143 let items = list.selectedItems; |
145 | 144 |
146 for (let i = items.length - 1; i >= 0; i--) | 145 for (let i = items.length - 1; i >= 0; i--) |
147 { | 146 { |
148 let searchString = items[i].getAttribute("value"); | 147 let searchString = items[i].getAttribute("value"); |
149 delete Prefs.custom_replace[searchString]; | 148 delete Prefs[pref][searchString]; |
150 } | 149 } |
151 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); | 150 Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref])); |
152 } | 151 } |
OLD | NEW |