Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/utils.js

Issue 29562595: Issue 2824 - Only consider ads subscriptions in chooseFilterSubscription (Closed)
Patch Set: Created Oct. 2, 2017, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/subscriptionInit.js ('K') | « lib/subscriptionInit.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 for (let prefix of prefixes.split(",")) 73 for (let prefix of prefixes.split(","))
74 { 74 {
75 if (new RegExp("^" + prefix + "\\b").test(this.appLocale)) 75 if (new RegExp("^" + prefix + "\\b").test(this.appLocale))
76 return prefix; 76 return prefix;
77 } 77 }
78 78
79 return null; 79 return null;
80 }, 80 },
81 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
122 getDocLink(linkID) 82 getDocLink(linkID)
123 { 83 {
124 let docLink = require("prefs").Prefs.documentation_link; 84 let docLink = require("prefs").Prefs.documentation_link;
125 return docLink.replace(/%LINK%/g, linkID) 85 return docLink.replace(/%LINK%/g, linkID)
126 .replace(/%LANG%/g, Utils.appLocale); 86 .replace(/%LANG%/g, Utils.appLocale);
127 }, 87 },
128 88
129 yield() 89 yield()
130 { 90 {
131 } 91 }
132 }; 92 };
OLDNEW
« lib/subscriptionInit.js ('K') | « lib/subscriptionInit.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld