| 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 | |
| 19 // | |
| 20 // This file has been generated automatically from Adblock Plus source code | |
| 21 // | |
| 22 | |
| 23 (function (_patchFunc0) { | |
| 24 var filterByKey = { | |
| 25 __proto__: null | |
| 26 }; | |
| 27 var styleURL = null; | |
| 28 var ElemHide = { | |
| 29 isDirty: false, | |
| 30 applied: false, | |
| 31 keyByFilter: { | |
| 32 __proto__: null | |
| 33 }, | |
| 34 init: function () { | |
| 35 Prefs.addListener(function (name) { | |
| 36 if (name == "enabled") | |
| 37 ElemHide.apply(); | |
| 38 } | |
| 39 ); | |
| 40 var styleFile = Utils.resolveFilePath(Prefs.data_directory); | |
| 41 styleFile.append("elemhide.css"); | |
| 42 styleURL = Utils.ioService.newFileURI(styleFile).QueryInterface(Ci.nsIFile
URL); | |
| 43 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar
); | |
| 44 registrar.registerFactory(ElemHidePrivate.classID, ElemHidePrivate.classDe
scription, "@mozilla.org/network/protocol/about;1?what=" + ElemHidePrivate.about
Prefix, ElemHidePrivate); | |
| 45 } | |
| 46 , | |
| 47 clear: function () { | |
| 48 filterByKey = { | |
| 49 __proto__: null | |
| 50 }; | |
| 51 ElemHide.keyByFilter = { | |
| 52 __proto__: null | |
| 53 }; | |
| 54 ElemHide.isDirty = false; | |
| 55 ElemHide.unapply(); | |
| 56 } | |
| 57 , | |
| 58 add: function (filter) { | |
| 59 if (filter.text in ElemHide.keyByFilter) | |
| 60 return ; | |
| 61 var key; | |
| 62 do { | |
| 63 key = Math.random().toFixed(15).substr(5); | |
| 64 } | |
| 65 while (key in filterByKey); | |
| 66 filterByKey[key] = filter.text; | |
| 67 ElemHide.keyByFilter[filter.text] = key; | |
| 68 ElemHide.isDirty = true; | |
| 69 } | |
| 70 , | |
| 71 remove: function (filter) { | |
| 72 if (!(filter.text in ElemHide.keyByFilter)) | |
| 73 return ; | |
| 74 var key = ElemHide.keyByFilter[filter.text]; | |
| 75 delete filterByKey[key]; | |
| 76 delete ElemHide.keyByFilter[filter.text]; | |
| 77 ElemHide.isDirty = true; | |
| 78 } | |
| 79 , | |
| 80 apply: function () { | |
| 81 if (ElemHide.applied) | |
| 82 ElemHide.unapply(); | |
| 83 try { | |
| 84 if (!Prefs.enabled) { | |
| 85 return ; | |
| 86 } | |
| 87 if (ElemHide.isDirty) { | |
| 88 ElemHide.isDirty = false; | |
| 89 var domains = { | |
| 90 __proto__: null | |
| 91 }; | |
| 92 var hasFilters = false; | |
| 93 for (var key in filterByKey) { | |
| 94 var filter = Filter.knownFilters[filterByKey[key]]; | |
| 95 if (!filter) { | |
| 96 delete filterByKey[key]; | |
| 97 continue; | |
| 98 } | |
| 99 var domain = filter.selectorDomain || ""; | |
| 100 var list; | |
| 101 if (domain in domains) | |
| 102 list = domains[domain]; | |
| 103 else { | |
| 104 list = { | |
| 105 __proto__: null | |
| 106 }; | |
| 107 domains[domain] = list; | |
| 108 } | |
| 109 list[filter.selector] = key; | |
| 110 hasFilters = true; | |
| 111 } | |
| 112 if (!hasFilters) { | |
| 113 return ; | |
| 114 } | |
| 115 try { | |
| 116 styleURL.file.parent.create(Ci.nsIFile.DIRECTORY_TYPE, 493); | |
| 117 } | |
| 118 catch (e){} | |
| 119 var stream; | |
| 120 try { | |
| 121 stream = Cc["@mozilla.org/network/safe-file-output-stream;1"].create
Instance(Ci.nsIFileOutputStream); | |
| 122 stream.init(styleURL.file, 2 | 8 | 32, 420, 0); | |
| 123 } | |
| 124 catch (e){ | |
| 125 Cu.reportError(e); | |
| 126 return ; | |
| 127 } | |
| 128 var buf = []; | |
| 129 var maxBufLen = 1024; | |
| 130 function escapeChar(match) { | |
| 131 return "\\" + match.charCodeAt(0).toString(16) + " "; | |
| 132 } | |
| 133 function writeString(str, forceWrite) { | |
| 134 buf.push(str); | |
| 135 if (buf.length >= maxBufLen || forceWrite) { | |
| 136 var output = buf.join("").replace(/[^\x01-\x7F]/g, escapeChar); | |
| 137 stream.write(output, output.length); | |
| 138 buf.splice(0, buf.length); | |
| 139 } | |
| 140 } | |
| 141 var cssTemplate = "-moz-binding: url(about:" + ElemHidePrivate.aboutPr
efix + "?%ID%#dummy) !important;"; | |
| 142 for (var domain in domains) { | |
| 143 var rules = []; | |
| 144 var list = domains[domain]; | |
| 145 if (domain) | |
| 146 writeString("@-moz-document domain(\"" + domain.split(",").join("\
"),domain(\"") + "\"){\n"); | |
| 147 else { | |
| 148 writeString("@-moz-document url-prefix(\"http://\"),url-prefix(\"h
ttps://\"),url-prefix(\"mailbox://\"),url-prefix(\"imap://\"),url-prefix(\"news:
//\"),url-prefix(\"snews://\"){\n"); | |
| 149 } | |
| 150 for (var selector in list) | |
| 151 writeString(selector + "{" + cssTemplate.replace("%ID%", list[sele
ctor]) + "}\n"); | |
| 152 writeString("}\n"); | |
| 153 } | |
| 154 writeString("", true); | |
| 155 try { | |
| 156 stream.QueryInterface(Ci.nsISafeOutputStream).finish(); | |
| 157 } | |
| 158 catch (e){ | |
| 159 Cu.reportError(e); | |
| 160 return ; | |
| 161 } | |
| 162 } | |
| 163 try { | |
| 164 Utils.styleService.loadAndRegisterSheet(styleURL, Ci.nsIStyleSheetServ
ice.USER_SHEET); | |
| 165 ElemHide.applied = true; | |
| 166 } | |
| 167 catch (e){ | |
| 168 Cu.reportError(e); | |
| 169 } | |
| 170 } | |
| 171 finally { | |
| 172 FilterNotifier.triggerListeners("elemhideupdate"); | |
| 173 } | |
| 174 } | |
| 175 , | |
| 176 unapply: function () { | |
| 177 if (ElemHide.applied) { | |
| 178 try { | |
| 179 Utils.styleService.unregisterSheet(styleURL, Ci.nsIStyleSheetService.U
SER_SHEET); | |
| 180 } | |
| 181 catch (e){ | |
| 182 Cu.reportError(e); | |
| 183 } | |
| 184 ElemHide.applied = false; | |
| 185 } | |
| 186 } | |
| 187 , | |
| 188 get styleURL() { | |
| 189 return ElemHide.applied ? styleURL.spec : null; | |
| 190 }, | |
| 191 getFilterByKey: function (key) { | |
| 192 return (key in filterByKey ? Filter.knownFilters[filterByKey[key]] : null)
; | |
| 193 } | |
| 194 , | |
| 195 toCache: function (cache) { | |
| 196 cache.elemhide = { | |
| 197 filterByKey: filterByKey | |
| 198 }; | |
| 199 } | |
| 200 , | |
| 201 fromCache: function (cache) { | |
| 202 filterByKey = cache.elemhide.filterByKey; | |
| 203 filterByKey.__proto__ = null; | |
| 204 delete ElemHide.keyByFilter; | |
| 205 ElemHide.__defineGetter__("keyByFilter", function () { | |
| 206 var result = { | |
| 207 __proto__: null | |
| 208 }; | |
| 209 for (var k in filterByKey) | |
| 210 result[filterByKey[k]] = k; | |
| 211 return ElemHide.keyByFilter = result; | |
| 212 } | |
| 213 ); | |
| 214 ElemHide.__defineSetter__("keyByFilter", function (value) { | |
| 215 delete ElemHide.keyByFilter; | |
| 216 return ElemHide.keyByFilter = value; | |
| 217 } | |
| 218 ); | |
| 219 } | |
| 220 | |
| 221 }; | |
| 222 var ElemHidePrivate = { | |
| 223 classID: Components.ID("{55fb7be0-1dd2-11b2-98e6-9e97caf8ba67}"), | |
| 224 classDescription: "Element hiding hit registration protocol handler", | |
| 225 aboutPrefix: "abp-elemhidehit", | |
| 226 createInstance: function (outer, iid) { | |
| 227 if (outer != null) | |
| 228 throw Cr.NS_ERROR_NO_AGGREGATION; | |
| 229 return this.QueryInterface(iid); | |
| 230 } | |
| 231 , | |
| 232 getURIFlags: function (uri) { | |
| 233 return ("HIDE_FROM_ABOUTABOUT" in Ci.nsIAboutModule ? Ci.nsIAboutModule.HI
DE_FROM_ABOUTABOUT : 0); | |
| 234 } | |
| 235 , | |
| 236 newChannel: function (uri) { | |
| 237 if (!/\?(\d+)/.test(uri.path)) | |
| 238 throw Cr.NS_ERROR_FAILURE; | |
| 239 return new HitRegistrationChannel(uri, RegExp["$1"]); | |
| 240 } | |
| 241 , | |
| 242 QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory, Ci.nsIAboutModule]) | |
| 243 }; | |
| 244 function HitRegistrationChannel(uri, key) { | |
| 245 this.key = key; | |
| 246 this.URI = this.originalURI = uri; | |
| 247 } | |
| 248 HitRegistrationChannel.prototype = { | |
| 249 key: null, | |
| 250 URI: null, | |
| 251 originalURI: null, | |
| 252 contentCharset: "utf-8", | |
| 253 contentLength: 0, | |
| 254 contentType: "text/xml", | |
| 255 owner: Utils.systemPrincipal, | |
| 256 securityInfo: null, | |
| 257 notificationCallbacks: null, | |
| 258 loadFlags: 0, | |
| 259 loadGroup: null, | |
| 260 name: null, | |
| 261 status: Cr.NS_OK, | |
| 262 asyncOpen: function (listener, context) { | |
| 263 var stream = this.open(); | |
| 264 Utils.runAsync(function () { | |
| 265 try { | |
| 266 listener.onStartRequest(this, context); | |
| 267 } | |
| 268 catch (e){} | |
| 269 try { | |
| 270 listener.onDataAvailable(this, context, stream, 0, stream.available())
; | |
| 271 } | |
| 272 catch (e){} | |
| 273 try { | |
| 274 listener.onStopRequest(this, context, Cr.NS_OK); | |
| 275 } | |
| 276 catch (e){} | |
| 277 } | |
| 278 , this); | |
| 279 } | |
| 280 , | |
| 281 open: function () { | |
| 282 var data = "<bindings xmlns='http://www.mozilla.org/xbl'><binding id='dumm
y'/></bindings>"; | |
| 283 if (this.key in filterByKey) { | |
| 284 var wnd = Utils.getRequestWindow(this); | |
| 285 if (wnd && wnd.document && !Policy.processNode(wnd, wnd.document, Policy
.type.ELEMHIDE, Filter.knownFilters[filterByKey[this.key]])) | |
| 286 data = "<bindings xmlns='http://www.mozilla.org/xbl'/>"; | |
| 287 } | |
| 288 var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci
.nsIStringInputStream); | |
| 289 stream.setData(data, data.length); | |
| 290 return stream; | |
| 291 } | |
| 292 , | |
| 293 isPending: function () { | |
| 294 return false; | |
| 295 } | |
| 296 , | |
| 297 cancel: function () { | |
| 298 throw Cr.NS_ERROR_NOT_IMPLEMENTED; | |
| 299 } | |
| 300 , | |
| 301 suspend: function () { | |
| 302 throw Cr.NS_ERROR_NOT_IMPLEMENTED; | |
| 303 } | |
| 304 , | |
| 305 resume: function () { | |
| 306 throw Cr.NS_ERROR_NOT_IMPLEMENTED; | |
| 307 } | |
| 308 , | |
| 309 QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel, Ci.nsIRequest]) | |
| 310 }; | |
| 311 if (typeof _patchFunc0 != "undefined") | |
| 312 eval("(" + _patchFunc0.toString() + ")()"); | |
| 313 window.ElemHide = ElemHide; | |
| 314 } | |
| 315 )(window.ElemHidePatch); | |
| OLD | NEW |