| 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-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 |
| 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; |
| 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 91 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; |
| 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}"]`); |
| 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) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 217 { | 219 { |
| 218 delete dialog.dataset.error; | 220 delete dialog.dataset.error; |
| 219 } | 221 } |
| 220 } | 222 } |
| 221 | 223 |
| 222 function populateLists() | 224 function populateLists() |
| 223 { | 225 { |
| 224 Promise.all([getInstalled(), getRecommendedAds()]) | 226 Promise.all([getInstalled(), getRecommendedAds()]) |
| 225 .then(([installed, recommended]) => | 227 .then(([installed, recommended]) => |
| 226 { | 228 { |
| 227 let listRecommended = get("#subscriptions-recommended"); | 229 let listRecommended = get(`#${idRecommended}`); |
| 228 for (let {title, url} of recommended) | 230 for (let {title, url} of recommended) |
| 229 { | 231 { |
| 230 create(listRecommended, "li", title, {"data-url": url}, | 232 create(listRecommended, "li", title, {"data-url": url}, |
| 231 (ev) => | 233 (ev) => |
| 232 { | 234 { |
| 233 if (ev.target.classList.contains("installed")) | 235 if (ev.target.classList.contains("installed")) |
| 234 return; | 236 return; |
| 235 | 237 |
| 236 setDialog(dialogSubscribe, {title, url}); | 238 setDialog(dialogSubscribe, {title, url}); |
| 237 } | 239 } |
| 238 ); | 240 ); |
| 239 } | 241 } |
| 240 | 242 |
| 241 for (let subscription of installed) | 243 for (let subscription of installed) |
| 242 { | 244 { |
| 243 if (subscription.disabled) | 245 if (subscription.disabled) |
| 244 continue; | 246 continue; |
| 245 | 247 |
| 246 setSubscription(subscription, true); | 248 setSubscription(subscription, true); |
| 247 } | 249 } |
| 248 }) | 250 }) |
| 249 .catch((err) => console.error(err)); | 251 .catch((err) => console.error(err)); |
| 250 } | 252 } |
| 251 | 253 |
| 252 /* Listeners */ | 254 /* Listeners */ |
| 253 | 255 |
| 254 function onChange(ev) | 256 function onChange(ev) |
| 255 { | 257 { |
| 256 if (ev.target.id != "acceptableAds") | 258 if (ev.target.id != idAcceptableAds) |
| 257 return; | 259 return; |
| 258 | 260 |
| 259 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => | 261 promisedAcceptableAdsUrl.then((acceptableAdsUrl) => |
| 260 { | 262 { |
| 261 if (ev.target.checked) | 263 if (ev.target.checked) |
| 262 { | 264 { |
| 263 installSubscription(acceptableAdsUrl, null); | 265 installSubscription(acceptableAdsUrl, null); |
| 264 } | 266 } |
| 265 else | 267 else |
| 266 { | 268 { |
| 267 uninstallSubscription(acceptableAdsUrl); | 269 uninstallSubscription(acceptableAdsUrl); |
| 268 } | 270 } |
| 269 }); | 271 }); |
| 270 } | 272 } |
| 271 document.addEventListener("change", onChange); | 273 document.addEventListener("change", onChange); |
| 272 | 274 |
| 273 function toggleWhitelistFilter(toggle) | 275 function toggleWhitelistFilter(toggle) |
| 274 { | 276 { |
| 275 if (whitelistFilter) | 277 if (whitelistFilter) |
| 276 { | 278 { |
| 277 ext.backgroundPage.sendMessage( | 279 ext.backgroundPage.sendMessage( |
| 278 { | 280 { |
| 279 type: (toggle.checked) ? "filters.remove" : "filters.add", | 281 type: (toggle.checked) ? "filters.remove" : "filters.add", |
| 280 text: whitelistFilter | 282 text: whitelistFilter |
| 281 }, (errors) => | 283 }, |
| 284 (errors) => |
| 282 { | 285 { |
| 283 if (errors.length < 1) | 286 if (errors.length < 1) |
| 284 return; | 287 return; |
| 285 | 288 |
| 286 console.error(errors); | 289 console.error(errors); |
| 287 toggle.checked = !toggle.checked; | 290 toggle.checked = !toggle.checked; |
| 288 } | 291 } |
| 289 ); | 292 ); |
| 290 } | 293 } |
| 291 else | 294 else |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 get("#dialog-subscribe [name='title']").setAttribute( | 438 get("#dialog-subscribe [name='title']").setAttribute( |
| 436 "placeholder", | 439 "placeholder", |
| 437 getMessage("mops_subscribe_title") | 440 getMessage("mops_subscribe_title") |
| 438 ); | 441 ); |
| 439 | 442 |
| 440 get("#dialog-subscribe [name='url']").setAttribute( | 443 get("#dialog-subscribe [name='url']").setAttribute( |
| 441 "placeholder", | 444 "placeholder", |
| 442 getMessage("mops_subscribe_url") | 445 getMessage("mops_subscribe_url") |
| 443 ); | 446 ); |
| 444 } | 447 } |
| LEFT | RIGHT |