| 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-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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // Display jQuery UI elements | 134 // Display jQuery UI elements |
| 135 $("#tabs").tabs(); | 135 $("#tabs").tabs(); |
| 136 $("button").button(); | 136 $("button").button(); |
| 137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); | 137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); |
| 138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); | 138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); |
| 139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); | 139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); |
| 140 | 140 |
| 141 // Popuplate option checkboxes | 141 // Popuplate option checkboxes |
| 142 initCheckbox("shouldShowBlockElementMenu"); | 142 initCheckbox("shouldShowBlockElementMenu"); |
| 143 initCheckbox("show_devtools_panel"); | 143 initCheckbox("show_devtools_panel"); |
| 144 initCheckbox("shouldShowNotifications", { | 144 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories"); |
| 145 key: "notifications_ignoredcategories", | 145 initCheckbox("safariContentBlocker"); |
| 146 get: function(ignoredcategories) | |
| 147 { | |
| 148 return ignoredcategories.indexOf("*") == -1; | |
| 149 } | |
| 150 }); | |
| 151 initCheckbox("safariContentBlocker", {onChange: function(checkbox) | |
| 152 { | |
| 153 var restartMessage = document.getElementById("restart-safari"); | |
| 154 restartMessage.hidden = true; | |
| 155 | |
| 156 // When the user has chosen to use the legacy APIs but Safari has disabled | |
| 157 // them we need to show a "Please restart Safari" message. | |
| 158 if (!checkbox.checked) | |
| 159 { | |
| 160 ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"}, | |
| 161 function (contentBlockingActive) | |
| 162 { | |
| 163 if (contentBlockingActive) | |
| 164 restartMessage.hidden = false; | |
| 165 }); | |
| 166 } | |
| 167 }}); | |
| 168 | 146 |
| 169 getInfo("features", function(features) | 147 getInfo("features", function(features) |
| 170 { | 148 { |
| 171 if (!features.devToolsPanel) | 149 if (!features.devToolsPanel) |
| 172 document.getElementById("showDevtoolsPanelContainer").hidden = true; | 150 document.getElementById("showDevtoolsPanelContainer").hidden = true; |
| 173 | 151 |
| 174 // Only show the option for Safari content blocking API if the user is | 152 // Only show the option for Safari content blocking API if the user is |
| 175 // running Safari and both the legacy and content blocking APIs are | 153 // running Safari and both the legacy and content blocking APIs are |
| 176 // available. | 154 // available. |
| 177 document.getElementById("safariContentBlockerContainer").hidden = !( | 155 document.getElementById("safariContentBlockerContainer").hidden = !( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 getSubscriptions(false, true, function(subscriptions) | 236 getSubscriptions(false, true, function(subscriptions) |
| 259 { | 237 { |
| 260 clearListBox("userFiltersBox"); | 238 clearListBox("userFiltersBox"); |
| 261 clearListBox("excludedDomainsBox"); | 239 clearListBox("excludedDomainsBox"); |
| 262 | 240 |
| 263 for (var i = 0; i < subscriptions.length; i++) | 241 for (var i = 0; i < subscriptions.length; i++) |
| 264 convertSpecialSubscription(subscriptions[i]); | 242 convertSpecialSubscription(subscriptions[i]); |
| 265 }); | 243 }); |
| 266 } | 244 } |
| 267 | 245 |
| 268 function initCheckbox(id, descriptor) | 246 function initCheckbox(id, key) |
| 269 { | 247 { |
| 248 key = key || id; |
| 270 var checkbox = document.getElementById(id); | 249 var checkbox = document.getElementById(id); |
| 271 var key = descriptor && descriptor.key || id; | 250 |
| 272 var onChange; | |
| 273 if (descriptor && descriptor.onChange) | |
| 274 onChange = descriptor.onChange.bind(undefined, checkbox); | |
| 275 getPref(key, function(value) | 251 getPref(key, function(value) |
| 276 { | 252 { |
| 277 if (descriptor && descriptor.get) | 253 onPrefMessage(key, value); |
| 278 checkbox.checked = descriptor.get(value); | |
| 279 else | |
| 280 checkbox.checked = value; | |
| 281 | |
| 282 if (onChange) | |
| 283 onChange(); | |
| 284 }); | 254 }); |
| 285 | 255 |
| 286 checkbox.addEventListener("click", function() | 256 checkbox.addEventListener("click", function() |
| 287 { | 257 { |
| 288 togglePref(key); | 258 togglePref(key); |
| 289 }, false); | 259 }, false); |
| 290 | |
| 291 if (onChange) | |
| 292 checkbox.addEventListener("change", onChange); | |
| 293 } | 260 } |
| 294 | 261 |
| 295 function loadRecommendations() | 262 function loadRecommendations() |
| 296 { | 263 { |
| 297 fetch("subscriptions.xml") | 264 fetch("subscriptions.xml") |
| 298 .then(function(response) | 265 .then(function(response) |
| 299 { | 266 { |
| 300 return response.text(); | 267 return response.text(); |
| 301 }) | 268 }) |
| 302 .then(function(text) | 269 .then(function(text) |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 { | 495 { |
| 529 switch (key) | 496 switch (key) |
| 530 { | 497 { |
| 531 case "notifications_showui": | 498 case "notifications_showui": |
| 532 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; | 499 document.getElementById("shouldShowNotificationsContainer").hidden = !valu
e; |
| 533 return; | 500 return; |
| 534 case "notifications_ignoredcategories": | 501 case "notifications_ignoredcategories": |
| 535 key = "shouldShowNotifications"; | 502 key = "shouldShowNotifications"; |
| 536 value = value.indexOf("*") == -1; | 503 value = value.indexOf("*") == -1; |
| 537 break; | 504 break; |
| 538 } | 505 case "safariContentBlocker": |
| 539 | 506 var restartMessage = document.getElementById("restart-safari"); |
| 507 restartMessage.hidden = true; |
| 508 // When the user has chosen to use the legacy APIs but Safari has disabled |
| 509 // them we need to show a "Please restart Safari" message. |
| 510 if (!value) |
| 511 { |
| 512 ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"}, |
| 513 function(contentBlockingActive) |
| 514 { |
| 515 if (contentBlockingActive) |
| 516 restartMessage.hidden = false; |
| 517 }); |
| 518 } |
| 519 } |
| 540 var checkbox = document.getElementById(key); | 520 var checkbox = document.getElementById(key); |
| 541 if (checkbox) | 521 if (checkbox) |
| 542 { | |
| 543 checkbox.checked = value; | 522 checkbox.checked = value; |
| 544 // Apparently modifying the checked attribute for a checkbox does not | |
| 545 // dispatch the change event automatically... | |
| 546 checkbox.dispatchEvent(new Event("change")); | |
| 547 } | |
| 548 } | 523 } |
| 549 | 524 |
| 550 function onFilterMessage(action, filter) | 525 function onFilterMessage(action, filter) |
| 551 { | 526 { |
| 552 switch (action) | 527 switch (action) |
| 553 { | 528 { |
| 554 case "loaded": | 529 case "loaded": |
| 555 reloadFilters(); | 530 reloadFilters(); |
| 556 break; | 531 break; |
| 557 case "added": | 532 case "added": |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 onFilterMessage(message.action, message.args[0]); | 762 onFilterMessage(message.action, message.args[0]); |
| 788 break; | 763 break; |
| 789 case "prefs.respond": | 764 case "prefs.respond": |
| 790 onPrefMessage(message.action, message.args[0]); | 765 onPrefMessage(message.action, message.args[0]); |
| 791 break; | 766 break; |
| 792 case "subscriptions.respond": | 767 case "subscriptions.respond": |
| 793 onSubscriptionMessage(message.action, message.args[0]); | 768 onSubscriptionMessage(message.action, message.args[0]); |
| 794 break; | 769 break; |
| 795 } | 770 } |
| 796 }); | 771 }); |
| LEFT | RIGHT |