| Left: | ||
| Right: |
| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 var elt = currentElement; | 272 var elt = currentElement; |
| 273 var url = null; | 273 var url = null; |
| 274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay") | 274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay") |
| 275 { | 275 { |
| 276 elt = currentElement.prisoner; | 276 elt = currentElement.prisoner; |
| 277 url = currentElement.prisonerURL; | 277 url = currentElement.prisonerURL; |
| 278 } | 278 } |
| 279 else if (elt.src) | 279 else if (elt.src) |
| 280 url = elt.src; | 280 url = elt.src; |
| 281 | 281 |
| 282 // Only normalize when the element contains a URL (issue 328.) | |
| 283 // The URL is not always normalized, so do it here | |
| 284 if (url) | |
| 285 url = normalizeURL(relativeToAbsoluteUrl(url)); | |
| 286 | |
| 287 // Construct filters. The popup will retrieve these. | 282 // Construct filters. The popup will retrieve these. |
| 288 // Only one ID | 283 // Only one ID |
| 289 var elementId = elt.id ? elt.id.split(' ').join('') : null; | 284 var elementId = elt.id ? elt.id.split(' ').join('') : null; |
| 290 // Can have multiple classes, and there might be extraneous whitespace | 285 // Can have multiple classes, and there might be extraneous whitespace |
| 291 var elementClasses = null; | 286 var elementClasses = null; |
| 292 if (elt.className) | 287 if (elt.className) |
| 293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); | 288 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); |
| 294 | 289 |
| 295 clickHideFilters = new Array(); | 290 clickHideFilters = new Array(); |
| 296 selectorList = new Array(); | 291 selectorList = new Array(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 309 var selector = ""; | 304 var selector = ""; |
| 310 | 305 |
| 311 for (var i = 0; i < elt.classList.length; i++) | 306 for (var i = 0; i < elt.classList.length; i++) |
| 312 selector += "." + elt.classList[i].replace(/([^\w-])/g, "\\$1"); | 307 selector += "." + elt.classList[i].replace(/([^\w-])/g, "\\$1"); |
| 313 | 308 |
| 314 addSelector(selector); | 309 addSelector(selector); |
| 315 } | 310 } |
| 316 | 311 |
| 317 if (url) | 312 if (url) |
| 318 { | 313 { |
| 319 clickHideFilters.push(relativeToAbsoluteUrl(url)); | 314 url = relativeToAbsoluteUrl(url); |
| 315 | |
| 316 clickHideFilters.push(normalizeURL(url)); | |
|
Wladimir Palant
2014/06/27 07:30:53
I wonder what will happen to src="about:blank" or
Sebastian Noack
2014/06/28 09:42:50
See http://codereview.adblockplus.org/594587757104
| |
| 320 selectorList.push(elt.localName + '[src="' + url + '"]'); | 317 selectorList.push(elt.localName + '[src="' + url + '"]'); |
|
Wladimir Palant
2014/06/27 07:30:53
Just noticed - this one won't work correctly, it n
Sebastian Noack
2014/06/28 09:42:50
Done.
| |
| 321 } | 318 } |
| 322 | 319 |
| 323 // restore the original style, before generating the fallback filter that | 320 // restore the original style, before generating the fallback filter that |
| 324 // will include the style, and to prevent highlightElements from saving those | 321 // will include the style, and to prevent highlightElements from saving those |
| 325 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); | 322 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); |
| 326 currentElement.style.backgroundColor = currentElement_backgroundColor; | 323 currentElement.style.backgroundColor = currentElement_backgroundColor; |
| 327 | 324 |
| 328 // as last resort, create a filter based on inline styles | 325 // as last resort, create a filter based on inline styles |
| 329 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) | 326 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) |
| 330 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/ "/g, '\\"') + '"]'); | 327 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/ "/g, '\\"') + '"]'); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 } | 387 } |
| 391 return r; | 388 return r; |
| 392 } else { | 389 } else { |
| 393 return u; | 390 return u; |
| 394 } | 391 } |
| 395 } | 392 } |
| 396 | 393 |
| 397 // Does some degree of URL normalization | 394 // Does some degree of URL normalization |
| 398 function normalizeURL(url) | 395 function normalizeURL(url) |
| 399 { | 396 { |
| 400 var components = url.match(/(.+:\/\/.+?)\/(.*)/); | 397 var components = url.match(/(.+:\/\/)(.+?)\/(.*)/); |
|
Wladimir Palant
2014/06/27 07:30:53
We should really start using the URI class from ba
Sebastian Noack
2014/06/28 09:42:50
Any reasons why we "normalize" the URL in the firs
Sebastian Noack
2014/09/25 08:36:25
As discussed in http://codereview.adblockplus.org/
| |
| 401 if(!components) | 398 if(!components) |
| 402 return url; | 399 return url; |
| 403 var newPath = removeDotSegments(components[2]); | 400 var newPath = removeDotSegments(components[3]); |
| 404 if(newPath.length == 0) | 401 if(newPath != '' && newPath[0] != '/') |
|
Wladimir Palant
2014/06/27 07:30:53
It should actually be: newPath == "" || newPath[0]
Sebastian Noack
2014/06/28 09:42:50
Then you can just check for newPath[0] != "/" with
| |
| 405 return components[1]; | |
| 406 if(newPath[0] != '/') | |
| 407 newPath = '/' + newPath; | 402 newPath = '/' + newPath; |
| 408 return components[1] + newPath; | 403 return '||' + components[2] + newPath; |
| 409 } | 404 } |
| 410 | 405 |
| 411 // Content scripts are apparently invoked on non-HTML documents, so we have to | 406 // Content scripts are apparently invoked on non-HTML documents, so we have to |
| 412 // check for that before doing stuff. |document instanceof HTMLDocument| check | 407 // check for that before doing stuff. |document instanceof HTMLDocument| check |
| 413 // will fail on some sites like planet.mozilla.org because WebKit creates | 408 // will fail on some sites like planet.mozilla.org because WebKit creates |
| 414 // Document instances for XHTML documents, have to test the root element. | 409 // Document instances for XHTML documents, have to test the root element. |
| 415 if (document.documentElement instanceof HTMLElement) | 410 if (document.documentElement instanceof HTMLElement) |
| 416 { | 411 { |
| 417 // Use a contextmenu handler to save the last element the user right-clicked o n. | 412 // Use a contextmenu handler to save the last element the user right-clicked o n. |
| 418 // To make things easier, we actually save the DOM event. | 413 // To make things easier, we actually save the DOM event. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 | 564 |
| 570 clickHide_deactivate(); | 565 clickHide_deactivate(); |
| 571 } | 566 } |
| 572 break; | 567 break; |
| 573 default: | 568 default: |
| 574 sendResponse({}); | 569 sendResponse({}); |
| 575 break; | 570 break; |
| 576 } | 571 } |
| 577 }); | 572 }); |
| 578 } | 573 } |
| OLD | NEW |