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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 var selector = elementClasses.map(function(elClass) | 384 var selector = elementClasses.map(function(elClass) |
385 { | 385 { |
386 return "." + elClass.replace(/([^\w-])/, "\\$1"); | 386 return "." + elClass.replace(/([^\w-])/, "\\$1"); |
387 }).join(""); | 387 }).join(""); |
388 | 388 |
389 clickHideFilters.push(document.domain + "##" + selector); | 389 clickHideFilters.push(document.domain + "##" + selector); |
390 selectorList.push(selector); | 390 selectorList.push(selector); |
391 } | 391 } |
392 if (url) | 392 if (url) |
393 { | 393 { |
394 clickHideFilters.push(relativeToAbsoluteUrl(url)); | 394 clickHideFilters.push(url); |
395 selectorList.push(elt.localName + '[src="' + url + '"]'); | 395 selectorList.push(elt.localName + '[src="' + elt.getAttribute("src") + '"]')
; |
396 } | 396 } |
397 | 397 |
398 // Show popup | 398 // Show popup |
399 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 399 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
400 | 400 |
401 // Highlight the unlucky elements | 401 // Highlight the unlucky elements |
402 // Restore currentElement's box-shadow and bgcolor so that highlightElements w
on't save those | 402 // Restore currentElement's box-shadow and bgcolor so that highlightElements w
on't save those |
403 unhighlightElement(currentElement); | 403 unhighlightElement(currentElement); |
404 // Highlight the elements specified by selector in yellow | 404 // Highlight the elements specified by selector in yellow |
405 highlightElements(selectorList.join(",")); | 405 highlightElements(selectorList.join(",")); |
(...skipping 16 matching lines...) Expand all Loading... |
422 // This OBJECT could contain an EMBED we already nuked, in which case there'
s no URL | 422 // This OBJECT could contain an EMBED we already nuked, in which case there'
s no URL |
423 if(params[0]) | 423 if(params[0]) |
424 url = params[0].getAttribute("value"); | 424 url = params[0].getAttribute("value"); |
425 else { | 425 else { |
426 params = elt.querySelectorAll("param[name=\"src\"]"); | 426 params = elt.querySelectorAll("param[name=\"src\"]"); |
427 if(params[0]) | 427 if(params[0]) |
428 url = params[0].getAttribute("value"); | 428 url = params[0].getAttribute("value"); |
429 } | 429 } |
430 | 430 |
431 if (url) | 431 if (url) |
432 url = normalizeURL(relativeToAbsoluteUrl(url)); | 432 url = resolveURL(url); |
433 } else if(!url) { | 433 } else if(!url) { |
434 url = elt.src || elt.href; | 434 url = elt.src || elt.href; |
435 } | 435 } |
436 return url; | 436 return url; |
437 } | 437 } |
438 | 438 |
439 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js | 439 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js |
440 // and licensed under the MIT license. See jquery-*.min.js for details. | 440 // and licensed under the MIT license. See jquery-*.min.js for details. |
441 function removeDotSegments(u) { | 441 function removeDotSegments(u) { |
442 var r = '', m = []; | 442 var r = '', m = []; |
(...skipping 15 matching lines...) Expand all Loading... |
458 u = m[2]; | 458 u = m[2]; |
459 r = r + m[1]; | 459 r = r + m[1]; |
460 } | 460 } |
461 } | 461 } |
462 return r; | 462 return r; |
463 } else { | 463 } else { |
464 return u; | 464 return u; |
465 } | 465 } |
466 } | 466 } |
467 | 467 |
468 // Does some degree of URL normalization | |
469 function normalizeURL(url) | |
470 { | |
471 var components = url.match(/(.+:\/\/.+?)\/(.*)/); | |
472 if(!components) | |
473 return url; | |
474 var newPath = removeDotSegments(components[2]); | |
475 if(newPath.length == 0) | |
476 return components[1]; | |
477 if(newPath[0] != '/') | |
478 newPath = '/' + newPath; | |
479 return components[1] + newPath; | |
480 } | |
481 | |
482 // Content scripts are apparently invoked on non-HTML documents, so we have to | 468 // Content scripts are apparently invoked on non-HTML documents, so we have to |
483 // check for that before doing stuff. |document instanceof HTMLDocument| check | 469 // check for that before doing stuff. |document instanceof HTMLDocument| check |
484 // will fail on some sites like planet.mozilla.org because WebKit creates | 470 // will fail on some sites like planet.mozilla.org because WebKit creates |
485 // Document instances for XHTML documents, have to test the root element. | 471 // Document instances for XHTML documents, have to test the root element. |
486 if (document.documentElement instanceof HTMLElement) | 472 if (document.documentElement instanceof HTMLElement) |
487 { | 473 { |
488 // Use a contextmenu handler to save the last element the user right-clicked o
n. | 474 // Use a contextmenu handler to save the last element the user right-clicked o
n. |
489 // To make things easier, we actually save the DOM event. | 475 // To make things easier, we actually save the DOM event. |
490 // We have to do this because the contextMenu API only provides a URL, not the
actual | 476 // We have to do this because the contextMenu API only provides a URL, not the
actual |
491 // DOM element. | 477 // DOM element. |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 | 625 |
640 clickHide_deactivate(); | 626 clickHide_deactivate(); |
641 } | 627 } |
642 break; | 628 break; |
643 default: | 629 default: |
644 sendResponse({}); | 630 sendResponse({}); |
645 break; | 631 break; |
646 } | 632 } |
647 }); | 633 }); |
648 } | 634 } |
OLD | NEW |