| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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-2017 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /* globals getDocLink */ | 18 /* globals getDocLink */ |
| 19 | 19 |
| 20 "use strict"; | 20 "use strict"; |
| 21 | 21 |
| 22 { | 22 { |
| 23 const {getMessage} = ext.i18n; | 23 const {getMessage} = ext.i18n; |
|
saroyanm
2017/08/27 17:44:01
Shouldn't the "ext", be declared as global ?
The e
Thomas Greiner
2017/08/28 12:04:21
We define `ext` as a global in .eslintrc.json so n
saroyanm
2017/08/28 12:27:20
Acknowledged.
| |
| 24 | 24 |
| 25 const dialogSubscribe = "subscribe"; | 25 const dialogSubscribe = "subscribe"; |
| 26 const idAcceptableAds = "acceptableAds"; | |
| 27 const idRecommended = "subscriptions-recommended"; | |
| 26 let whitelistFilter = null; | 28 let whitelistFilter = null; |
| 27 let promisedAcceptableAdsUrl = getAcceptableAdsUrl(); | 29 let promisedAcceptableAdsUrl = getAcceptableAdsUrl(); |
| 28 | 30 |
| 29 /* Utility functions */ | 31 /* Utility functions */ |
| 30 | 32 |
| 31 function get(selector, origin) | 33 function get(selector, origin) |
| 32 { | 34 { |
| 33 return (origin || document).querySelector(selector); | 35 return (origin || document).querySelector(selector); |
| 34 } | 36 } |
| 35 | 37 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 48 } | 50 } |
| 49 | 51 |
| 50 if (attributes) | 52 if (attributes) |
| 51 { | 53 { |
| 52 for (let name in attributes) | 54 for (let name in attributes) |
| 53 { | 55 { |
| 54 element.setAttribute(name, attributes[name]); | 56 element.setAttribute(name, attributes[name]); |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 if (onclick) | 60 if (onclick) |
|
saroyanm
2017/08/27 17:44:02
Considering the fact that we have "onclick" functi
saroyanm
2017/08/28 08:15:28
Nevermind it will not, local scope will override t
| |
| 59 { | 61 { |
| 60 element.addEventListener("click", (ev) => | 62 element.addEventListener("click", (ev) => |
| 61 { | 63 { |
| 62 onclick(ev); | 64 onclick(ev); |
| 63 ev.stopPropagation(); | 65 ev.stopPropagation(); |
| 64 }); | 66 }); |
| 65 } | 67 } |
| 66 | 68 |
| 67 parent.appendChild(element); | 69 parent.appendChild(element); |
| 68 return element; | 70 return element; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 129 |
| 128 function setSubscription({disabled, title, url}, shouldAdd) | 130 function setSubscription({disabled, title, url}, shouldAdd) |
| 129 { | 131 { |
| 130 if (disabled) | 132 if (disabled) |
| 131 return; | 133 return; |
| 132 | 134 |
| 133 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => | 135 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => |
| 134 { | 136 { |
| 135 if (url == acceptableAdsUrl) | 137 if (url == acceptableAdsUrl) |
| 136 { | 138 { |
| 137 get("#acceptableAds").checked = true; | 139 get(`#${idAcceptableAds}`).checked = true; |
|
saroyanm
2017/08/27 17:44:01
Detail: this ID is used couple of times, if you wi
Thomas Greiner
2017/08/28 12:04:20
See other comment for the reply.
| |
| 138 return; | 140 return; |
| 139 } | 141 } |
| 140 | 142 |
| 141 let listInstalled = get("#subscriptions-installed"); | 143 let listInstalled = get("#subscriptions-installed"); |
| 142 let installed = get(`[data-url="${url}"]`, listInstalled); | 144 let installed = get(`[data-url="${url}"]`, listInstalled); |
| 143 | 145 |
| 144 if (installed) | 146 if (installed) |
| 145 { | 147 { |
| 146 let titleElement = get("span", installed); | 148 let titleElement = get("span", installed); |
| 147 titleElement.textContent = title || url; | 149 titleElement.textContent = title || url; |
| 148 } | 150 } |
| 149 else if (shouldAdd) | 151 else if (shouldAdd) |
| 150 { | 152 { |
| 151 let element = create(listInstalled, "li", null, {"data-url": url}); | 153 let element = create(listInstalled, "li", null, {"data-url": url}); |
| 152 create(element, "span", title || url); | 154 create(element, "span", title || url); |
| 153 create(element, "button", null, {class: "remove"}, | 155 create(element, "button", null, {class: "remove"}, |
| 154 () => uninstallSubscription(url) | 156 () => uninstallSubscription(url) |
| 155 ); | 157 ); |
| 156 | 158 |
| 157 let recommended = get(`#subscriptions-recommended [data-url="${url}"]`); | 159 let recommended = get(`#${idRecommended} [data-url="${url}"]`); |
|
saroyanm
2017/08/27 17:44:01
Detail: the "#subscriptions-recommended" ID is use
Thomas Greiner
2017/08/28 12:04:20
Not sure what the underlying argument is.
- If the
saroyanm
2017/08/28 12:27:19
Yes I was referring to this .
Thomas Greiner
2017/08/28 13:14:05
Acknowledged.
saroyanm
2017/08/28 13:52:05
Detail: this change didn't land, but it's trivial.
Thomas Greiner
2017/08/28 14:00:12
As I mentioned, throughout all of our code "we don
saroyanm
2017/08/28 14:05:24
I did commented under the line:
"If the issue is t
Thomas Greiner
2017/08/28 15:01:28
Ok, I only looked at the text below your message.
| |
| 158 if (recommended) | 160 if (recommended) |
| 159 { | 161 { |
| 160 recommended.classList.add("installed"); | 162 recommended.classList.add("installed"); |
| 161 } | 163 } |
| 162 } | 164 } |
| 163 }); | 165 }); |
| 164 } | 166 } |
| 165 | 167 |
| 166 function removeSubscription(url) | 168 function removeSubscription(url) |
| 167 { | 169 { |
| 168 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => | 170 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => |
| 169 { | 171 { |
| 170 if (url == acceptableAdsUrl) | 172 if (url == acceptableAdsUrl) |
| 171 { | 173 { |
| 172 get("#acceptableAds").checked = false; | 174 get(`#${idAcceptableAds}`).checked = false; |
| 173 return; | 175 return; |
| 174 } | 176 } |
| 175 | 177 |
| 176 let installed = get(`#subscriptions-installed [data-url="${url}"]`); | 178 let installed = get(`#subscriptions-installed [data-url="${url}"]`); |
| 177 if (installed) | 179 if (installed) |
| 178 { | 180 { |
| 179 installed.parentNode.removeChild(installed); | 181 installed.parentNode.removeChild(installed); |
| 180 } | 182 } |
| 181 | 183 |
| 182 let recommended = get(`#subscriptions-recommended [data-url="${url}"]`); | 184 let recommended = get(`#${idRecommended} [data-url="${url}"]`); |
| 183 if (recommended) | 185 if (recommended) |
| 184 { | 186 { |
| 185 recommended.classList.remove("installed"); | 187 recommended.classList.remove("installed"); |
| 186 } | 188 } |
| 187 }); | 189 }); |
| 188 } | 190 } |
| 189 | 191 |
| 190 function setDialog(id, options) | 192 function setDialog(id, options) |
| 191 { | 193 { |
| 192 if (!id) | 194 if (!id) |
| 193 { | 195 { |
| 194 delete document.body.dataset.dialog; | 196 delete document.body.dataset.dialog; |
| 195 return; | 197 return; |
| 196 } | 198 } |
| 197 | 199 |
| 198 let fields = getAll(`#dialog-${id} input`); | 200 let fields = getAll(`#dialog-${id} input`); |
| 199 for (let field of fields) | 201 for (let field of fields) |
| 200 { | 202 { |
| 201 field.value = (options && field.name in options) ? options[field.name] : " "; | 203 let {name} = field; |
|
saroyanm
2017/08/27 17:44:01
Detail: this exceeds the characters limit.
Thomas Greiner
2017/08/28 12:04:22
Done. As mentioned, I also fixed linter errors in
| |
| 204 field.value = (options && name in options) ? options[name] : ""; | |
| 202 } | 205 } |
| 203 setError(id, null); | 206 setError(id, null); |
| 204 | 207 |
| 205 document.body.dataset.dialog = id; | 208 document.body.dataset.dialog = id; |
| 206 } | 209 } |
| 207 | 210 |
| 208 function setError(dialogId, fieldName) | 211 function setError(dialogId, fieldName) |
| 209 { | 212 { |
| 210 let dialog = get(`#dialog-${dialogId}`); | 213 let dialog = get(`#dialog-${dialogId}`); |
| 211 if (fieldName) | 214 if (fieldName) |
| 212 { | 215 { |
| 213 dialog.dataset.error = fieldName; | 216 dialog.dataset.error = fieldName; |
| 214 } | 217 } |
| 215 else | 218 else |
| 216 { | 219 { |
| 217 delete dialog.dataset.error; | 220 delete dialog.dataset.error; |
| 218 } | 221 } |
| 219 } | 222 } |
| 220 | 223 |
| 221 function populateLists() | 224 function populateLists() |
| 222 { | 225 { |
| 223 Promise.all([getInstalled(), getRecommendedAds()]) | 226 Promise.all([getInstalled(), getRecommendedAds()]) |
| 224 .then(([installed, recommended]) => | 227 .then(([installed, recommended]) => |
| 225 { | 228 { |
| 226 let listRecommended = get("#subscriptions-recommended"); | 229 let listRecommended = get(`#${idRecommended}`); |
| 227 for (let {title, url} of recommended) | 230 for (let {title, url} of recommended) |
| 228 { | 231 { |
| 229 create(listRecommended, "li", title, {"data-url": url}, | 232 create(listRecommended, "li", title, {"data-url": url}, |
|
saroyanm
2017/08/27 17:44:00
Detail: I think we also should specify role="butto
Thomas Greiner
2017/08/28 12:04:22
We don't include Accessibility in the mobile optio
saroyanm
2017/08/28 12:27:20
Acknowledged.
| |
| 230 (ev) => | 233 (ev) => |
| 231 { | 234 { |
| 232 if (ev.target.classList.contains("installed")) | 235 if (ev.target.classList.contains("installed")) |
| 233 return; | 236 return; |
| 234 | 237 |
| 235 setDialog(dialogSubscribe, {title, url}); | 238 setDialog(dialogSubscribe, {title, url}); |
| 236 } | 239 } |
| 237 ); | 240 ); |
| 238 } | 241 } |
| 239 | 242 |
| 240 for (let subscription of installed) | 243 for (let subscription of installed) |
| 241 { | 244 { |
| 242 if (subscription.disabled) | 245 if (subscription.disabled) |
| 243 continue; | 246 continue; |
| 244 | 247 |
| 245 setSubscription(subscription, true); | 248 setSubscription(subscription, true); |
| 246 } | 249 } |
| 247 }) | 250 }) |
| 248 .catch((err) => console.error(err)); | 251 .catch((err) => console.error(err)); |
| 249 } | 252 } |
| 250 | 253 |
| 251 /* Listeners */ | 254 /* Listeners */ |
| 252 | 255 |
| 253 function onChange(ev) | 256 function onChange(ev) |
| 254 { | 257 { |
| 255 if (ev.target.id != "acceptableAds") | 258 if (ev.target.id != idAcceptableAds) |
| 256 return; | 259 return; |
| 257 | 260 |
| 258 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => | 261 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => |
| 259 { | 262 { |
| 260 if (ev.target.checked) | 263 if (ev.target.checked) |
| 261 { | 264 { |
| 262 installSubscription(acceptableAdsUrl, null); | 265 installSubscription(acceptableAdsUrl, null); |
| 263 } | 266 } |
| 264 else | 267 else |
| 265 { | 268 { |
| 266 uninstallSubscription(acceptableAdsUrl); | 269 uninstallSubscription(acceptableAdsUrl); |
| 267 } | 270 } |
| 268 }); | 271 }); |
| 269 } | 272 } |
| 270 document.addEventListener("change", onChange); | 273 document.addEventListener("change", onChange); |
| 271 | 274 |
| 272 function toggleWhitelistFilter(toggle) | 275 function toggleWhitelistFilter(toggle) |
| 273 { | 276 { |
| 274 if (whitelistFilter) | 277 if (whitelistFilter) |
| 275 { | 278 { |
| 276 ext.backgroundPage.sendMessage( | 279 ext.backgroundPage.sendMessage( |
| 277 { | 280 { |
| 278 type: (toggle.checked) ? "filters.remove" : "filters.add", | 281 type: (toggle.checked) ? "filters.remove" : "filters.add", |
| 279 text: whitelistFilter | 282 text: whitelistFilter |
| 280 }, (errors) => | 283 }, |
| 284 (errors) => | |
| 281 { | 285 { |
| 282 if (errors.length < 1) | 286 if (errors.length < 1) |
|
saroyanm
2017/08/27 17:44:02
This doesn't pass ESlint indentation chekck for so
Thomas Greiner
2017/08/28 12:04:21
I'm not getting an error here. What rule does it m
saroyanm
2017/08/28 12:27:19
Indent: "282:11 error Expected indentation of 8
Thomas Greiner
2017/08/28 13:14:04
Done. Seems like we updated eslint-config-eyeo. At
| |
| 283 return; | 287 return; |
| 284 | 288 |
| 285 console.error(errors); | 289 console.error(errors); |
| 286 toggle.checked = !toggle.checked; | 290 toggle.checked = !toggle.checked; |
| 287 } | 291 } |
| 288 ); | 292 ); |
| 289 } | 293 } |
| 290 else | 294 else |
| 291 { | 295 { |
| 292 console.error("Whitelist filter hasn't been initialized yet"); | 296 console.error("Whitelist filter hasn't been initialized yet"); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 } | 393 } |
| 390 else | 394 else |
| 391 { | 395 { |
| 392 setSubscription(subscription, true); | 396 setSubscription(subscription, true); |
| 393 } | 397 } |
| 394 break; | 398 break; |
| 395 case "removed": | 399 case "removed": |
| 396 removeSubscription(subscription.url); | 400 removeSubscription(subscription.url); |
| 397 break; | 401 break; |
| 398 case "title": | 402 case "title": |
| 399 // We're also receiving these messages for subscriptions that are no t | 403 // We're also receiving these messages for subscriptions that are |
|
saroyanm
2017/08/27 17:44:01
Detail: exceeding 80 chars.
Thomas Greiner
2017/08/28 12:04:20
Done.
| |
| 400 // installed so we shouldn't add those by accident | 404 // not installed so we shouldn't add those by accident |
| 401 setSubscription(subscription, false); | 405 setSubscription(subscription, false); |
| 402 break; | 406 break; |
| 403 } | 407 } |
| 404 break; | 408 break; |
| 405 } | 409 } |
| 406 } | 410 } |
| 407 } | 411 } |
| 408 ext.onMessage.addListener(onMessage); | 412 ext.onMessage.addListener(onMessage); |
| 409 | 413 |
| 410 ext.backgroundPage.sendMessage({ | 414 ext.backgroundPage.sendMessage({ |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 434 get("#dialog-subscribe [name='title']").setAttribute( | 438 get("#dialog-subscribe [name='title']").setAttribute( |
| 435 "placeholder", | 439 "placeholder", |
| 436 getMessage("mops_subscribe_title") | 440 getMessage("mops_subscribe_title") |
| 437 ); | 441 ); |
| 438 | 442 |
| 439 get("#dialog-subscribe [name='url']").setAttribute( | 443 get("#dialog-subscribe [name='url']").setAttribute( |
| 440 "placeholder", | 444 "placeholder", |
| 441 getMessage("mops_subscribe_url") | 445 getMessage("mops_subscribe_url") |
| 442 ); | 446 ); |
| 443 } | 447 } |
| LEFT | RIGHT |