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 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 case "get-clickhide-state": | 671 case "get-clickhide-state": |
672 sendResponse({active: clickHide_activated}); | 672 sendResponse({active: clickHide_activated}); |
673 break; | 673 break; |
674 case "clickhide-activate": | 674 case "clickhide-activate": |
675 clickHide_activate(); | 675 clickHide_activate(); |
676 break; | 676 break; |
677 case "clickhide-deactivate": | 677 case "clickhide-deactivate": |
678 clickHide_deactivate(); | 678 clickHide_deactivate(); |
679 break; | 679 break; |
680 case "clickhide-new-filter": | 680 case "clickhide-new-filter": |
681 // The request is received by all frames, so ignore it if we're not the
frame the | 681 if(lastRightClickEvent) |
682 // user right-clicked in | |
683 if(!lastRightClickEvent) | |
684 return; | |
685 // We hope the URL we are given is the same as the one in the element re
ferenced | |
686 // by lastRightClickEvent.target. If not, we just discard | |
687 var target = lastRightClickEvent.target; | |
688 var url = target.src; | |
689 // If we don't have the element with a src URL same as the filter, look
for it. | |
690 // Chrome's context menu API is terrible. Why can't it give us the frigg
in' element | |
691 // to start with? | |
692 if(msg.filter !== url) | |
693 { | 682 { |
694 // Grab all elements with a src attribute. | |
695 // This won't work for all object/embed tags, but the context menu API
doesn't | |
696 // work on those, so we're OK for now. | |
697 var elts = document.querySelectorAll('[src]'); | |
698 for(var i=0; i<elts.length; i++) { | |
699 url = elts[i].src; | |
700 if(msg.filter === url) | |
701 { | |
702 // This is hopefully our element. In case of multiple elements | |
703 // with the same src, only one will be highlighted. | |
704 target = elts[i]; | |
705 break; | |
706 } | |
707 } | |
708 } | |
709 // Following test will be true if we found the element with the filter U
RL | |
710 if(msg.filter === url) | |
711 { | |
712 // This request would have come from the chrome.contextMenu handler, s
o we | |
713 // simulate the user having chosen the element to get rid of via the u
sual means. | |
714 clickHide_activated = true; | 683 clickHide_activated = true; |
715 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s
o why set it? | 684 currentElement = addElementOverlay(lastRightClickEvent.target); |
716 clickHideFilters = [msg.filter]; | |
717 // Coerce red highlighted overlay on top of element to remove. | |
718 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta
fix it sometime | |
719 currentElement = addElementOverlay(target); | |
720 // clickHide_mouseOver(lastRightClickEvent); | |
721 clickHide_mouseClick(lastRightClickEvent); | 685 clickHide_mouseClick(lastRightClickEvent); |
722 } | 686 } |
723 else | |
724 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha
t element.", msg.filter, url, lastRightClickEvent.target.src); | |
725 break; | 687 break; |
726 case "clickhide-init": | 688 case "clickhide-init": |
727 if (clickHideFiltersDialog) | 689 if (clickHideFiltersDialog) |
728 { | 690 { |
729 sendResponse({filters: clickHide_filters}); | 691 sendResponse({filters: clickHide_filters}); |
730 | 692 |
731 clickHideFiltersDialog.style.width = msg.width + "px"; | 693 clickHideFiltersDialog.style.width = msg.width + "px"; |
732 clickHideFiltersDialog.style.height = msg.height + "px"; | 694 clickHideFiltersDialog.style.height = msg.height + "px"; |
733 clickHideFiltersDialog.style.visibility = "visible"; | 695 clickHideFiltersDialog.style.visibility = "visible"; |
734 } | 696 } |
(...skipping 16 matching lines...) Expand all Loading... |
751 break; | 713 break; |
752 default: | 714 default: |
753 sendResponse({}); | 715 sendResponse({}); |
754 break; | 716 break; |
755 } | 717 } |
756 }); | 718 }); |
757 | 719 |
758 if (window == window.top) | 720 if (window == window.top) |
759 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 721 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
760 } | 722 } |
OLD | NEW |