| 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; | 
|   73   }); |   72   }); | 
|   74   whitelist.sort(); |   73   whitelist.sort(); | 
|   75  |   74  | 
|   76   // Add the rules to the list |   75   // Add the rules to the list | 
|   77   if(ruleList.length > 0) |   76   if (ruleList.length > 0) | 
|   78   { |   77   { | 
|   79     for (let i = 0; i < ruleList.length; i++) |   78     for (let i = 0; i < ruleList.length; i++) | 
|   80     { |   79     { | 
|   81       let [searchString, replacement] = ruleList[i]; |   80       let [searchString, replacement] = ruleList[i]; | 
|   82  |   81  | 
|   83       let option = document.createElement('listitem'); |   82       let option = document.createElement('listitem'); | 
|   84       option.setAttribute("value", searchString); |   83       option.setAttribute("value", searchString); | 
|   85  |   84  | 
|   86       let cell1 = document.createElement('listcell'); |   85       let cell1 = document.createElement('listcell'); | 
|   87       cell1.setAttribute("label", searchString); |   86       cell1.setAttribute("label", searchString); | 
|   88       option.appendChild(cell1); |   87       option.appendChild(cell1); | 
|   89  |   88  | 
|   90       let cell2 = document.createElement('listcell'); |   89       let cell2 = document.createElement('listcell'); | 
|   91       cell2.setAttribute("label", replacement); |   90       cell2.setAttribute("label", replacement); | 
|   92       option.appendChild(cell2); |   91       option.appendChild(cell2); | 
|   93  |   92  | 
|   94       ruleListElement.appendChild(option); |   93       ruleListElement.appendChild(option); | 
|   95     } |   94     } | 
|   96   } |   95   } | 
|   97   else |   96   else | 
|   98   { |   97   { | 
|   99     let option = document.createElement("listitem"); |   98     let option = document.createElement("listitem"); | 
|  100     option.setAttribute("class", "auto-entry"); |   99     option.setAttribute("class", "auto-entry"); | 
|  101     option.setAttribute("label", ruleListElement.getAttribute("_emptyLabel")); |  100     option.setAttribute("label", ruleListElement.getAttribute("_emptyLabel")); | 
|  102  |  101  | 
|  103     ruleListElement.appendChild(option); |  102     ruleListElement.appendChild(option); | 
|  104   } |  103   } | 
|  105  |  104  | 
|  106   if(whitelist.length > 0) |  105   if (whitelist.length > 0) | 
|  107   { |  106   { | 
|  108     for (let i = 0; i < whitelist.length; i++) |  107     for (let i = 0; i < whitelist.length; i++) | 
|  109     { |  108     { | 
|  110       let option = document.createElement("listitem"); |  109       let option = document.createElement("listitem"); | 
|  111       option.setAttribute("value", whitelist[i]); |  110       option.setAttribute("value", whitelist[i]); | 
|  112       option.setAttribute("label", whitelist[i]) |  111       option.setAttribute("label", whitelist[i]) | 
|  113  |  112  | 
|  114       whitelistElement.appendChild(option); |  113       whitelistElement.appendChild(option); | 
|  115     } |  114     } | 
|  116   } |  115   } | 
| (...skipping 14 matching lines...) Expand all  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  | 
 |  145   let {onWhitelistEntryRemoved} = require("rules"); | 
 |  146  | 
|  146   for (let i = items.length - 1; i >= 0; i--) |  147   for (let i = items.length - 1; i >= 0; i--) | 
|  147   { |  148   { | 
|  148     let searchString = items[i].getAttribute("value"); |  149     let searchString = items[i].getAttribute("value"); | 
|  149     delete Prefs.custom_replace[searchString]; |  150     delete Prefs[pref][searchString]; | 
 |  151  | 
 |  152     if (pref == "whitelist") | 
 |  153       onWhitelistEntryRemoved(searchString); | 
|  150   } |  154   } | 
|  151   Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); |  155   Prefs[pref] = JSON.parse(JSON.stringify(Prefs[pref])); | 
|  152 } |  156 } | 
| OLD | NEW |