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 |
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 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 // Click-to-hide stuff | 18 // Click-to-hide stuff |
19 var clickHide_activated = false; | 19 var clickHide_activated = false; |
20 var clickHide_filters = null; | 20 var clickHide_filters = null; |
21 var currentElement = null; | 21 var currentElement = null; |
22 var clickHideFilters = null; | 22 var clickHideFilters = null; |
23 var highlightedElementsSelector = null; | 23 var highlightedElementsSelector = null; |
24 var clickHideFiltersDialog = null; | 24 var clickHideFiltersDialog = null; |
25 var lastRightClickEvent = null; | 25 var lastRightClickEvent = null; |
26 | 26 |
27 function quote(value) | |
28 { | |
29 return '"' + value.replace(/(["\\])/g, "\\$1") + '"'; | |
30 } | |
31 | |
27 function supportsShadowRoot(element) | 32 function supportsShadowRoot(element) |
28 { | 33 { |
29 if (!("createShadowRoot" in element)) | 34 if (!("createShadowRoot" in element)) |
30 return false; | 35 return false; |
31 | 36 |
32 // There are some elements (e.g. <textarea>), which don't | 37 // There are some elements (e.g. <textarea>), which don't |
33 // support author created shadow roots and throw an exception. | 38 // support author created shadow roots and throw an exception. |
34 var clone = element.cloneNode(false); | 39 var clone = element.cloneNode(false); |
35 try | 40 try |
36 { | 41 { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 clickHide_mouseClick(ev); | 307 clickHide_mouseClick(ev); |
303 } | 308 } |
304 | 309 |
305 // Hovering over an element so highlight it | 310 // Hovering over an element so highlight it |
306 function clickHide_mouseOver(e) | 311 function clickHide_mouseOver(e) |
307 { | 312 { |
308 if (clickHide_activated == false) | 313 if (clickHide_activated == false) |
309 return; | 314 return; |
310 | 315 |
311 var target = e.target; | 316 var target = e.target; |
312 while (target.parentNode && !(target.id || target.className || target.src)) | 317 while (target.parentNode && !(target.id || target.className || target.src || / :.+:/.test(target.getAttribute("style")))) |
313 target = target.parentNode; | 318 target = target.parentNode; |
314 if (target == document.documentElement || target == document.body) | 319 if (target == document.documentElement || target == document.body) |
315 target = null; | 320 target = null; |
316 | 321 |
317 if (target && target instanceof HTMLElement) | 322 if (target && target instanceof HTMLElement) |
318 { | 323 { |
319 currentElement = target; | 324 currentElement = target; |
320 | 325 |
321 highlightElement(target, "#d6d84b", "#f8fa47"); | 326 highlightElement(target, "#d6d84b", "#f8fa47"); |
322 target.addEventListener("contextmenu", clickHide_elementClickHandler, false) ; | 327 target.addEventListener("contextmenu", clickHide_elementClickHandler, false) ; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 // Construct filters. The popup will retrieve these. | 379 // Construct filters. The popup will retrieve these. |
375 // Only one ID | 380 // Only one ID |
376 var elementId = elt.id ? elt.id.split(' ').join('') : null; | 381 var elementId = elt.id ? elt.id.split(' ').join('') : null; |
377 // Can have multiple classes, and there might be extraneous whitespace | 382 // Can have multiple classes, and there might be extraneous whitespace |
378 var elementClasses = null; | 383 var elementClasses = null; |
379 if (elt.className) | 384 if (elt.className) |
380 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); | 385 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); |
381 | 386 |
382 clickHideFilters = new Array(); | 387 clickHideFilters = new Array(); |
383 selectorList = new Array(); | 388 selectorList = new Array(); |
389 | |
390 var addSelector = function(selector) | |
391 { | |
392 clickHideFilters.push(document.domain + "##" + selector); | |
393 selectorList.push(selector); | |
394 }; | |
395 | |
384 if (elementId) | 396 if (elementId) |
385 { | 397 addSelector("#" + elementId); |
386 clickHideFilters.push(document.domain + "###" + elementId); | 398 |
387 selectorList.push("#" + elementId); | |
388 } | |
389 if (elementClasses && elementClasses.length > 0) | 399 if (elementClasses && elementClasses.length > 0) |
390 { | 400 { |
391 var selector = elementClasses.map(function(elClass) | 401 var selector = ""; |
392 { | |
393 return "." + elClass.replace(/([^\w-])/, "\\$1"); | |
394 }).join(""); | |
395 | 402 |
396 clickHideFilters.push(document.domain + "##" + selector); | 403 for (var i = 0; i < elt.classList.length; i++) |
Thomas Greiner
2014/11/04 09:53:21
It's certainly not wrong to use elt.classList here
Sebastian Noack
2014/11/04 14:51:07
The patch has already been merged, but I might fil
Thomas Greiner
2014/11/04 15:15:53
That's totally fine with me. Looks like the origin
Sebastian Noack
2014/11/04 15:44:54
For reference, https://issues.adblockplus.org/tick
| |
397 selectorList.push(selector); | 404 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); |
Wladimir Palant
2014/11/03 18:11:33
Somehow I feel that changing Array.map() into a lo
| |
405 | |
406 addSelector(selector); | |
398 } | 407 } |
408 | |
399 if (url) | 409 if (url) |
400 { | 410 { |
401 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); | 411 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); |
402 selectorList.push('[src="' + elt.getAttribute("src") + '"]'); | 412 |
413 var src = elt.getAttribute("src"); | |
414 if (src) | |
415 selectorList.push('[src=' + quote(src) + ']'); | |
416 } | |
417 | |
418 // restore the original style, before generating the fallback filter that | |
419 // will include the style, and to prevent highlightElements from saving those | |
420 unhighlightElement(currentElement); | |
421 | |
422 // as last resort, create a filter based on inline styles | |
423 if (clickHideFilters.length == 0) | |
424 { | |
425 var style = elt.getAttribute("style"); | |
426 if (style) | |
427 addSelector(elt.localName + '[style=' + quote(style) + ']'); | |
403 } | 428 } |
404 | 429 |
405 // Show popup | 430 // Show popup |
406 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 431 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
407 | 432 |
408 // Highlight the unlucky elements | |
409 // Restore currentElement's box-shadow and bgcolor so that highlightElements w on't save those | |
410 unhighlightElement(currentElement); | |
411 // Highlight the elements specified by selector in yellow | 433 // Highlight the elements specified by selector in yellow |
412 highlightElements(selectorList.join(",")); | 434 highlightElements(selectorList.join(",")); |
413 // Now, actually highlight the element the user clicked on in red | 435 // Now, actually highlight the element the user clicked on in red |
414 highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 436 highlightElement(currentElement, "#fd1708", "#f6a1b5"); |
415 | 437 |
416 // Make sure the browser doesn't handle this click | 438 // Make sure the browser doesn't handle this click |
417 e.preventDefault(); | 439 e.preventDefault(); |
418 e.stopPropagation(); | 440 e.stopPropagation(); |
419 } | 441 } |
420 | 442 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 break; | 652 break; |
631 default: | 653 default: |
632 sendResponse({}); | 654 sendResponse({}); |
633 break; | 655 break; |
634 } | 656 } |
635 }); | 657 }); |
636 | 658 |
637 if (window == window.top) | 659 if (window == window.top) |
638 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 660 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
639 } | 661 } |
OLD | NEW |