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

Delta Between Two Patch Sets: lib/utils.js

Issue 29371763: Issue 4795 - Use modern JavaScript syntax (Closed)
Left Patch Set: Addressed feedback, used destructuring Created Jan. 17, 2017, 7:39 a.m.
Right Patch Set: Addressed some more feedback Created Jan. 18, 2017, 11:44 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/url.js ('k') | lib/whitelisting.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 29 matching lines...) Expand all
40 { 40 {
41 setTimeout(callback, 0); 41 setTimeout(callback, 0);
42 } 42 }
43 }, 43 },
44 get appLocale() 44 get appLocale()
45 { 45 {
46 let locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-"); 46 let locale = ext.i18n.getMessage("@@ui_locale").replace(/_/g, "-");
47 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true}); 47 Object.defineProperty(this, "appLocale", {value: locale, enumerable: true});
48 return this.appLocale; 48 return this.appLocale;
49 }, 49 },
50 // We cannot calculate MD5 checksums yet :-(
51 generateChecksum(lines) 50 generateChecksum(lines)
52 { 51 {
52 // We cannot calculate MD5 checksums yet :-(
53 return null; 53 return null;
54 }, 54 },
55 checkLocalePrefixMatch(prefixes) 55 checkLocalePrefixMatch(prefixes)
56 { 56 {
57 if (!prefixes) 57 if (!prefixes)
58 return null; 58 return null;
59 59
60 for (let prefix of prefixes.split(",")) 60 for (let prefix of prefixes.split(","))
61 if (new RegExp("^" + prefix + "\\b").test(this.appLocale)) 61 if (new RegExp("^" + prefix + "\\b").test(this.appLocale))
62 return prefix; 62 return prefix;
63 63
64 return null; 64 return null;
65 }, 65 },
66 66
67 chooseFilterSubscription(subscriptions) 67 chooseFilterSubscription(subscriptions)
68 { 68 {
69 let selectedItem = null; 69 let selectedItem = null;
70 let selectedPrefix = null; 70 let selectedPrefix = null;
71 let matchCount = 0; 71 let matchCount = 0;
72 for (let subscription of subscriptions) 72 for (let subscription of subscriptions)
73 { 73 {
74 if (!selectedItem) 74 if (!selectedItem)
75 selectedItem = subscription; 75 selectedItem = subscription;
76 76
77 let prefix = require("utils").Utils.checkLocalePrefixMatch(subscription.ge tAttribute("prefixes")); 77 let prefix = Utils.checkLocalePrefixMatch(subscription.getAttribute("prefi xes"));
78 if (prefix) 78 if (prefix)
79 { 79 {
80 if (!selectedPrefix || selectedPrefix.length < prefix.length) 80 if (!selectedPrefix || selectedPrefix.length < prefix.length)
81 { 81 {
82 selectedItem = subscription; 82 selectedItem = subscription;
83 selectedPrefix = prefix; 83 selectedPrefix = prefix;
84 matchCount = 1; 84 matchCount = 1;
85 } 85 }
86 else if (selectedPrefix && selectedPrefix.length == prefix.length) 86 else if (selectedPrefix && selectedPrefix.length == prefix.length)
87 { 87 {
88 matchCount++; 88 matchCount++;
89 89
90 // If multiple items have a matching prefix of the same length: 90 // If multiple items have a matching prefix of the same length:
91 // Select one of the items randomly, probability should be the same 91 // Select one of the items randomly, probability should be the same
92 // for all items. So we replace the previous match here with 92 // for all items. So we replace the previous match here with
93 // probability 1/N (N being the number of matches). 93 // probability 1/N (N being the number of matches).
94 if (Math.random() * matchCount < 1) 94 if (Math.random() * matchCount < 1)
95 { 95 {
96 selectedItem = subscription; 96 selectedItem = subscription;
97 selectedPrefix = prefix; 97 selectedPrefix = prefix;
98 } 98 }
99 } 99 }
100 } 100 }
101 } 101 }
102 return selectedItem; 102 return selectedItem;
103 }, 103 },
104 104
105 getDocLink(linkID) 105 getDocLink(linkID)
106 { 106 {
107 let {Prefs} = require("prefs"); 107 let docLink = require("prefs").Prefs.documentation_link;
108 let docLink = Prefs.documentation_link;
109 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale ); 108 return docLink.replace(/%LINK%/g, linkID).replace(/%LANG%/g, Utils.appLocale );
110 }, 109 },
111 110
112 yield() 111 yield()
113 { 112 {
114 } 113 }
115 }; 114 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld