Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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-2013 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 |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 if (elt.className) | 292 if (elt.className) |
293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); | 293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); |
294 | 294 |
295 clickHideFilters = new Array(); | 295 clickHideFilters = new Array(); |
296 selectorList = new Array(); | 296 selectorList = new Array(); |
297 if (elementId) | 297 if (elementId) |
298 { | 298 { |
299 clickHideFilters.push(document.domain + "###" + elementId); | 299 clickHideFilters.push(document.domain + "###" + elementId); |
300 selectorList.push("#" + elementId); | 300 selectorList.push("#" + elementId); |
301 } | 301 } |
302 if (elementClasses) | 302 if (elementClasses && elementClasses.length > 0) |
303 { | 303 { |
304 for(var i = 0; i < elementClasses.length; i++) | 304 var selector = elementClasses.map(function(elClass) |
305 { | 305 { |
306 clickHideFilters.push(document.domain + "##." + elementClasses[i]); | 306 return "." + elClass.replace(/([^\w-])/, "\\$1"); |
307 selectorList.push("." + elementClasses[i]); | 307 }).join(""); |
308 } | 308 |
309 clickHideFilters.push(document.domain + "##" + selector); | |
310 selectorList.push(selector); | |
309 } | 311 } |
310 if (url) | 312 if (url) |
311 { | 313 { |
312 clickHideFilters.push(relativeToAbsoluteUrl(url)); | 314 clickHideFilters.push(relativeToAbsoluteUrl(url)); |
313 selectorList.push(elt.localName + '[src="' + url + '"]'); | 315 selectorList.push(elt.localName + '[src="' + url + '"]'); |
314 } | 316 } |
315 | 317 |
316 // Show popup | 318 // Show popup |
317 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 319 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
318 | 320 |
(...skipping 25 matching lines...) Expand all Loading... | |
344 url = params[0].getAttribute("value"); | 346 url = params[0].getAttribute("value"); |
345 else { | 347 else { |
346 params = elt.querySelectorAll("param[name=\"src\"]"); | 348 params = elt.querySelectorAll("param[name=\"src\"]"); |
347 if(params[0]) | 349 if(params[0]) |
348 url = params[0].getAttribute("value"); | 350 url = params[0].getAttribute("value"); |
349 } | 351 } |
350 } else if(!url) { | 352 } else if(!url) { |
351 url = elt.getAttribute("src") || elt.getAttribute("href"); | 353 url = elt.getAttribute("src") || elt.getAttribute("href"); |
352 } | 354 } |
353 return url; | 355 return url; |
354 } | |
355 | |
356 // Converts relative to absolute URL | |
357 // e.g.: foo.swf on http://example.com/whatever/bar.html | |
358 // -> http://example.com/whatever/foo.swf | |
359 function relativeToAbsoluteUrl(url) | |
360 { | |
361 // If URL is already absolute, don't mess with it | |
362 if (!url || /^[\w\-]+:/i.test(url)) | |
363 return url; | |
364 | |
365 // Leading / means absolute path | |
366 // Leading // means network path | |
367 if (url[0] == '/') | |
368 { | |
369 if (url[1] == '/') | |
370 return document.location.protocol + url; | |
371 else | |
372 return document.location.protocol + "//" + document.location.host + url; | |
373 } | |
374 | |
375 // Remove filename and add relative URL to it | |
376 var base = document.baseURI.match(/.+\//); | |
377 if (!base) | |
378 return document.baseURI + "/" + url; | |
379 return base[0] + url; | |
380 } | 356 } |
381 | 357 |
382 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js | 358 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js |
383 // and licensed under the MIT license. See jquery-*.min.js for details. | 359 // and licensed under the MIT license. See jquery-*.min.js for details. |
384 function removeDotSegments(u) { | 360 function removeDotSegments(u) { |
385 var r = '', m = []; | 361 var r = '', m = []; |
386 if (/\./.test(u)) { | 362 if (/\./.test(u)) { |
387 while (u !== undefined && u !== '') { | 363 while (u !== undefined && u !== '') { |
388 if (u === '.' || u === '..') { | 364 if (u === '.' || u === '..') { |
389 u = ''; | 365 u = ''; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 clickHide_mouseClick(lastRightClickEvent); | 531 clickHide_mouseClick(lastRightClickEvent); |
556 } | 532 } |
557 else | 533 else |
558 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", msg.filter, url, lastRightClickEvent.target.src); | 534 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", msg.filter, url, lastRightClickEvent.target.src); |
559 break; | 535 break; |
560 case "clickhide-init": | 536 case "clickhide-init": |
561 if (clickHideFiltersDialog) | 537 if (clickHideFiltersDialog) |
562 { | 538 { |
563 sendResponse({filters: clickHide_filters}); | 539 sendResponse({filters: clickHide_filters}); |
564 | 540 |
565 clickHideFiltersDialog.style.width = (msg.width + 5) + "px"; | 541 clickHideFiltersDialog.style.width = msg.width + "px"; |
566 clickHideFiltersDialog.style.height = (msg.height + 5) + "px"; | 542 clickHideFiltersDialog.style.height = msg.height + "px"; |
567 clickHideFiltersDialog.style.visibility = "visible"; | 543 clickHideFiltersDialog.style.visibility = "visible"; |
568 } | 544 } |
569 break; | 545 break; |
570 case "clickhide-move": | 546 case "clickhide-move": |
571 if (clickHideFiltersDialog) | 547 if (clickHideFiltersDialog) |
572 { | 548 { |
573 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px"; | 549 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px"; |
574 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px"; | 550 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px"; |
575 } | 551 } |
576 break; | 552 break; |
577 case "clickhide-close": | 553 case "clickhide-close": |
578 if (clickHideFiltersDialog) | 554 if (clickHideFiltersDialog) |
Wladimir Palant
2014/01/10 16:28:56
You should add |&& currentElement| check here whic
| |
579 { | 555 { |
580 // Explicitly get rid of currentElement | 556 // Explicitly get rid of currentElement |
581 var element = currentElement; | 557 var filters = msg.filters; |
582 ext.backgroundPage.sendMessage({ | 558 if (filters) |
583 type: "should-collapse", | |
584 url: element.src, | |
585 documentUrl: document.URL, | |
586 mediatype: typeMap[element.localName] | |
587 }, function(response) | |
588 { | 559 { |
589 if (response && element.parentNode) | 560 var isHidden = false; |
590 element.parentNode.removeChild(element); | 561 var selectors = []; |
591 }); | 562 for (var i = 0; i < filters.length; i++) |
Wladimir Palant
2014/01/10 16:28:56
What if an element hiding filter was added? Not on
Sebastian Noack
2014/06/25 16:40:59
The problem is not (only) that the element is remo
Wladimir Palant
2014/06/25 18:49:34
We don't care, going through the entire document l
Sebastian Noack
2014/06/25 19:05:05
Actually we exactly do that already, when the matc
Thomas Greiner
2014/07/17 15:35:49
This issue only addresses the case when a filter d
Wladimir Palant
2014/07/17 15:55:10
That would be the best solution. If that's too com
| |
563 { | |
564 var selector = filters[i].match(/##(.*)$/); | |
565 if (selector) | |
566 { | |
567 if (currentElement.matches(selector[1])) | |
568 isHidden = true; | |
569 | |
570 selectors.push(selector[1]); | |
571 } | |
572 } | |
573 if (setElemhideCSSRules) | |
574 setElemhideCSSRules(selectors); | |
Wladimir Palant
2014/11/17 19:53:57
The code above has multiple issues:
* It doesn't
Thomas Greiner
2014/11/27 14:46:07
What we could do is instead of just forwarding the
| |
575 | |
576 if (!isHidden) | |
577 { | |
578 var element = currentElement; | |
579 ext.backgroundPage.sendMessage({ | |
580 type: "should-collapse", | |
581 url: element.src, | |
582 documentUrl: document.URL, | |
583 mediatype: typeMap[element.localName] | |
584 }, function(response) | |
585 { | |
586 if (response && element.parentNode) | |
587 element.style.setProperty("display", "none", "important"); | |
Wladimir Palant
2014/11/17 19:53:57
We don't need to check the element's parent node i
Sebastian Noack
2014/11/27 12:43:40
What is if element collapsing is disabled in the o
Thomas Greiner
2014/11/27 14:46:07
That's a valid comment and it doesn't seem like we
Sebastian Noack
2014/11/27 15:15:48
If that is sufficient, fine for me.
| |
588 }); | |
589 } | |
590 } | |
592 | 591 |
593 clickHide_deactivate(); | 592 clickHide_deactivate(); |
594 } | 593 } |
595 break; | 594 break; |
596 default: | 595 default: |
597 sendResponse({}); | 596 sendResponse({}); |
598 break; | 597 break; |
599 } | 598 } |
600 }); | 599 }); |
601 } | 600 } |
LEFT | RIGHT |