Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 highlightedElementsSelector = null; | 22 var highlightedElementsSelector = null; |
23 var clickHideFiltersDialog = null; | 23 var clickHideFiltersDialog = null; |
24 var lastRightClickEvent = null; | 24 var lastRightClickEvent = null; |
25 var lastRightClickEventRandom = null; | 25 var lastRightClickEventValid = false; |
26 | 26 |
27 function escapeChar(chr) | 27 function escapeChar(chr) |
28 { | 28 { |
29 var code = chr.charCodeAt(0); | 29 var code = chr.charCodeAt(0); |
30 | 30 |
31 // Control characters and leading digits must be escaped based on | 31 // Control characters and leading digits must be escaped based on |
32 // their char code in CSS. Moreover, curly brackets aren't allowed | 32 // their char code in CSS. Moreover, curly brackets aren't allowed |
33 // in elemhide filters, and therefore must be escaped based on their | 33 // in elemhide filters, and therefore must be escaped based on their |
34 // char code as well. | 34 // char code as well. |
35 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) | 35 if (code <= 0x1F || code == 0x7F || /[\d\{\}]/.test(chr)) |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
468 // popup asks for them. | 468 // popup asks for them. |
469 function clickHide_mouseClick(e) | 469 function clickHide_mouseClick(e) |
470 { | 470 { |
471 if (!currentElement || !clickHide_activated) | 471 if (!currentElement || !clickHide_activated) |
472 return; | 472 return; |
473 | 473 |
474 var elt = currentElement; | 474 var elt = currentElement; |
475 if (currentElement.classList.contains("__adblockplus__overlay")) | 475 if (currentElement.classList.contains("__adblockplus__overlay")) |
476 elt = currentElement.prisoner; | 476 elt = currentElement.prisoner; |
477 | 477 |
478 var clickHideFilters = new Array(); | 478 var clickHideFilters = []; |
479 var selectorList = new Array(); | 479 var selectorList = []; |
480 | 480 |
481 var addSelector = function(selector) | 481 var addSelector = function(selector) |
482 { | 482 { |
483 if (selectorList.indexOf(selector) != -1) | 483 if (selectorList.indexOf(selector) != -1) |
484 return; | 484 return; |
485 | 485 |
486 clickHideFilters.push(document.domain + "##" + selector); | 486 clickHideFilters.push(document.domain + "##" + selector); |
487 selectorList.push(selector); | 487 selectorList.push(selector); |
488 }; | 488 }; |
489 | 489 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
526 if (style) | 526 if (style) |
527 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']'); | 527 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']'); |
528 } | 528 } |
529 | 529 |
530 // Show popup, or if inside frame tell the parent to do it | 530 // Show popup, or if inside frame tell the parent to do it |
531 if (window.self == window.top) | 531 if (window.self == window.top) |
532 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 532 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
533 else | 533 else |
534 ext.backgroundPage.sendMessage( | 534 ext.backgroundPage.sendMessage( |
535 { | 535 { |
536 type: "clickHide-showDialog", | 536 type: "forward", |
537 screenX: e.screenX, | 537 payload: |
538 screenY: e.screenY, | 538 { |
539 clickHideFilters: clickHideFilters | 539 type: "clickhide-show-dialog", |
540 screenX: e.screenX, | |
541 screenY: e.screenY, | |
542 clickHideFilters: clickHideFilters | |
543 } | |
540 }); | 544 }); |
541 | 545 |
542 // Highlight the elements specified by selector in yellow | 546 // Highlight the elements specified by selector in yellow |
543 if (selectorList.length > 0) | 547 if (selectorList.length > 0) |
544 highlightElements(selectorList.join(",")); | 548 highlightElements(selectorList.join(",")); |
545 // Now, actually highlight the element the user clicked on in red | 549 // Now, actually highlight the element the user clicked on in red |
546 highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 550 highlightElement(currentElement, "#fd1708", "#f6a1b5"); |
547 | 551 |
548 // Make sure the browser doesn't handle this click | 552 // Make sure the browser doesn't handle this click |
549 e.preventDefault(); | 553 e.preventDefault(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 if ("ext" in window && document instanceof HTMLDocument) | 590 if ("ext" in window && document instanceof HTMLDocument) |
587 { | 591 { |
588 // Use a contextmenu handler to save the last element the user right-clicked o n. | 592 // Use a contextmenu handler to save the last element the user right-clicked o n. |
589 // To make things easier, we actually save the DOM event. | 593 // To make things easier, we actually save the DOM event. |
590 // We have to do this because the contextMenu API only provides a URL, not the actual | 594 // We have to do this because the contextMenu API only provides a URL, not the actual |
591 // DOM element. | 595 // DOM element. |
592 document.addEventListener('contextmenu', function(e) | 596 document.addEventListener('contextmenu', function(e) |
593 { | 597 { |
594 lastRightClickEvent = e; | 598 lastRightClickEvent = e; |
595 // We also need to ensure any old lastRightClickEvent variables in other | 599 // We also need to ensure any old lastRightClickEvent variables in other |
596 // frames are cleared. So we store a random number, send a message to all | 600 // frames are cleared. |
597 // frames that they should clear lastRightClickEvent unless the number match es | 601 lastRightClickEventValid = true; |
598 lastRightClickEventRandom = Math.random(); | |
Sebastian Noack
2015/01/16 22:45:31
I don't really like the approach here to generate
kzar
2015/01/16 23:03:45
Done.
| |
599 ext.backgroundPage.sendMessage( | 602 ext.backgroundPage.sendMessage( |
600 { | 603 { |
601 type: "clickHide-clear-lastRightClickEvent", | 604 type: "forward", |
602 random: lastRightClickEventRandom | 605 payload: |
606 { | |
607 type: "clickhide-clear-last-right-click-event" | |
608 } | |
603 }); | 609 }); |
604 }, true); | 610 }, true); |
605 | 611 |
606 document.addEventListener("click", function(event) | 612 document.addEventListener("click", function(event) |
607 { | 613 { |
608 // Ignore right-clicks | 614 // Ignore right-clicks |
609 if (event.button == 2) | 615 if (event.button == 2) |
610 return; | 616 return; |
611 | 617 |
612 // Search the link associated with the click | 618 // Search the link associated with the click |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 case "clickhide-close": | 711 case "clickhide-close": |
706 if (currentElement && msg.remove) | 712 if (currentElement && msg.remove) |
707 { | 713 { |
708 // Explicitly get rid of currentElement | 714 // Explicitly get rid of currentElement |
709 var element = currentElement.prisoner || currentElement; | 715 var element = currentElement.prisoner || currentElement; |
710 if (element && element.parentNode) | 716 if (element && element.parentNode) |
711 element.parentNode.removeChild(element); | 717 element.parentNode.removeChild(element); |
712 } | 718 } |
713 clickHide_deactivate(); | 719 clickHide_deactivate(); |
714 break; | 720 break; |
715 case "clickHide-showDialog": | 721 case "clickhide-show-dialog": |
Sebastian Noack
2015/01/16 22:45:31
For consistency with the message types implemented
kzar
2015/01/16 23:03:45
Done.
| |
716 if (window.self == window.top) | 722 if (window.self == window.top) |
717 clickHide_showDialog(msg.screenX + window.pageXOffset, | 723 clickHide_showDialog(msg.screenX + window.pageXOffset, |
718 msg.screenY + window.pageYOffset, | 724 msg.screenY + window.pageYOffset, |
719 msg.clickHideFilters); | 725 msg.clickHideFilters); |
720 break; | 726 break; |
721 case "clickHide-clear-lastRightClickEvent": | 727 case "clickhide-clear-last-right-click-event": |
722 if (msg.random != lastRightClickEventRandom) | 728 if (lastRightClickEventValid) |
729 lastRightClickEventValid = false; | |
730 else | |
723 lastRightClickEvent = null; | 731 lastRightClickEvent = null; |
724 lastRightClickEventRandom = null; | |
725 break; | 732 break; |
726 } | 733 } |
727 }); | 734 }); |
728 | 735 |
729 if (window == window.top) | 736 if (window == window.top) |
730 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 737 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
731 } | 738 } |
LEFT | RIGHT |