OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 "readingDirection", | 58 "readingDirection", |
59 {value: direction, enumerable: true} | 59 {value: direction, enumerable: true} |
60 ); | 60 ); |
61 return this.readingDirection; | 61 return this.readingDirection; |
62 }, | 62 }, |
63 generateChecksum(lines) | 63 generateChecksum(lines) |
64 { | 64 { |
65 // We cannot calculate MD5 checksums yet :-( | 65 // We cannot calculate MD5 checksums yet :-( |
66 return null; | 66 return null; |
67 }, | 67 }, |
68 checkLocalePrefixMatch(prefixes) | |
69 { | |
70 if (!prefixes) | |
71 return null; | |
72 | |
73 for (let prefix of prefixes.split(",")) | |
74 { | |
75 if (new RegExp("^" + prefix + "\\b").test(this.appLocale)) | |
76 return prefix; | |
77 } | |
78 | |
79 return null; | |
80 }, | |
81 | |
82 chooseFilterSubscription(subscriptions) | |
83 { | |
84 let selectedItem = null; | |
85 let selectedPrefix = null; | |
86 let matchCount = 0; | |
87 for (let subscription of subscriptions) | |
88 { | |
89 if (!selectedItem) | |
90 selectedItem = subscription; | |
91 | |
92 let prefix = Utils.checkLocalePrefixMatch( | |
93 subscription.getAttribute("prefixes") | |
94 ); | |
95 if (prefix) | |
96 { | |
97 if (!selectedPrefix || selectedPrefix.length < prefix.length) | |
98 { | |
99 selectedItem = subscription; | |
100 selectedPrefix = prefix; | |
101 matchCount = 1; | |
102 } | |
103 else if (selectedPrefix && selectedPrefix.length == prefix.length) | |
104 { | |
105 matchCount++; | |
106 | |
107 // If multiple items have a matching prefix of the same length: | |
108 // Select one of the items randomly, probability should be the same | |
109 // for all items. So we replace the previous match here with | |
110 // probability 1/N (N being the number of matches). | |
111 if (Math.random() * matchCount < 1) | |
112 { | |
113 selectedItem = subscription; | |
114 selectedPrefix = prefix; | |
115 } | |
116 } | |
117 } | |
118 } | |
119 return selectedItem; | |
120 }, | |
121 | 68 |
122 getDocLink(linkID) | 69 getDocLink(linkID) |
123 { | 70 { |
124 let docLink = require("prefs").Prefs.documentation_link; | 71 let docLink = require("prefs").Prefs.documentation_link; |
125 return docLink.replace(/%LINK%/g, linkID) | 72 return docLink.replace(/%LINK%/g, linkID) |
126 .replace(/%LANG%/g, Utils.appLocale); | 73 .replace(/%LANG%/g, Utils.appLocale); |
127 }, | 74 }, |
128 | 75 |
129 yield() | 76 yield() |
130 { | 77 { |
131 } | 78 } |
132 }; | 79 }; |
OLD | NEW |