OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH |
| 4 * |
| 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 |
| 7 * published by the Free Software Foundation. |
| 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. |
| 13 * |
| 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/>. |
| 16 */ |
| 17 |
| 18 (function(global) |
| 19 { |
| 20 function updateFromURL(data) |
| 21 { |
| 22 if (window.location.search) |
| 23 { |
| 24 var params = window.location.search.substr(1).split("&"); |
| 25 for (var i = 0; i < params.length; i++) |
| 26 { |
| 27 var parts = params[i].split("=", 2); |
| 28 if (parts.length == 2 && parts[0] in data) |
| 29 data[parts[0]] = decodeURIComponent(parts[1]); |
| 30 } |
| 31 } |
| 32 } |
| 33 |
| 34 var subscriptions =[ |
| 35 "https://easylist-downloads.adblockplus.org/easylistgermany+easylist.txt", |
| 36 "https://easylist-downloads.adblockplus.org/exceptionrules.txt", |
| 37 "https://easylist-downloads.adblockplus.org/fanboy-social.txt" |
| 38 ]; |
| 39 |
| 40 global.Utils = { |
| 41 getDocLink: function(link) |
| 42 { |
| 43 return "https://adblockplus.org/redirect?link=" + encodeURIComponent(link)
; |
| 44 } |
| 45 }; |
| 46 |
| 47 global.Subscription = function(url) |
| 48 { |
| 49 this.url = url; |
| 50 this.title = "Subscription " + url; |
| 51 this.disabled = false; |
| 52 this.lastDownload = 1234; |
| 53 }; |
| 54 |
| 55 global.Subscription.fromURL = function(url) |
| 56 { |
| 57 return new global.Subscription(url); |
| 58 }; |
| 59 |
| 60 global.DownloadableSubscription = global.Subscription; |
| 61 global.SpecialSubscription = function() {}; |
| 62 |
| 63 global.FilterStorage = { |
| 64 get subscriptions() |
| 65 { |
| 66 return subscriptions.map(global.Subscription.fromURL); |
| 67 }, |
| 68 |
| 69 get knownSubscriptions() |
| 70 { |
| 71 var result = {}; |
| 72 for (var i = 0; i < subscriptions.length; i++) |
| 73 result[subscriptions[i]] = global.Subscription.fromURL(subscriptions[i])
; |
| 74 return result; |
| 75 }, |
| 76 |
| 77 addSubscription: function(subscription) |
| 78 { |
| 79 var index = subscriptions.indexOf(subscription.url); |
| 80 if (index < 0) |
| 81 { |
| 82 subscriptions.push(subscription.url); |
| 83 global.FilterNotifier.triggerListeners("subscription.added", subscriptio
n); |
| 84 } |
| 85 }, |
| 86 |
| 87 removeSubscription: function(subscription) |
| 88 { |
| 89 var index = subscriptions.indexOf(subscription.url); |
| 90 if (index >= 0) |
| 91 { |
| 92 subscriptions.splice(index, 1); |
| 93 global.FilterNotifier.triggerListeners("subscription.removed", subscript
ion); |
| 94 } |
| 95 } |
| 96 }; |
| 97 |
| 98 global.BlockingFilter = function() {}; |
| 99 |
| 100 global.defaultMatcher = { |
| 101 matchesAny: function(url, requestType, docDomain, thirdParty) |
| 102 { |
| 103 var params = {blockedURLs: ""}; |
| 104 updateFromURL(params); |
| 105 var blocked = params.blockedURLs.split(","); |
| 106 if (blocked.indexOf(url) >= 0) |
| 107 return new global.BlockingFilter(); |
| 108 else |
| 109 return null; |
| 110 } |
| 111 }; |
| 112 |
| 113 var notifierListeners = []; |
| 114 global.FilterNotifier = { |
| 115 addListener: function(listener) |
| 116 { |
| 117 if (notifierListeners.indexOf(listener) < 0) |
| 118 notifierListeners.push(listener); |
| 119 }, |
| 120 |
| 121 removeListener: function(listener) |
| 122 { |
| 123 var index = notifierListeners.indexOf(listener); |
| 124 if (index >= 0) |
| 125 notifierListeners.splice(index, 1); |
| 126 }, |
| 127 |
| 128 triggerListeners: function() |
| 129 { |
| 130 var args = Array.prototype.slice.apply(arguments); |
| 131 var listeners = notifierListeners.slice(); |
| 132 for (var i = 0; i < listeners.length; i++) |
| 133 listeners[i].apply(null, args); |
| 134 } |
| 135 }; |
| 136 |
| 137 global.require = function(module) |
| 138 { |
| 139 if (module == "info") |
| 140 { |
| 141 var result = { |
| 142 platform: "gecko", |
| 143 platformVersion: "34.0", |
| 144 application: "firefox", |
| 145 applicationVersion: "34.0" |
| 146 }; |
| 147 updateFromURL(result); |
| 148 return result; |
| 149 } |
| 150 else |
| 151 return undefined; |
| 152 } |
| 153 |
| 154 global.openOptions = function() |
| 155 { |
| 156 window.open("http://example.com/options.html", "_blank"); |
| 157 }; |
| 158 |
| 159 global.Services = { |
| 160 vc: { |
| 161 compare: function(v1, v2) |
| 162 { |
| 163 return parseFloat(v1) - parseFloat(v2); |
| 164 } |
| 165 } |
| 166 }; |
| 167 |
| 168 var issues = {seenDataCorruption: false, filterlistsReinitialized: false}; |
| 169 updateFromURL(issues); |
| 170 global.seenDataCorruption = issues.seenDataCorruption; |
| 171 global.filterlistsReinitialized = issues.filterlistsReinitialized; |
| 172 })(this); |
OLD | NEW |