Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.postload.js

Issue 5088751004942336: Issue 370 - Right-clicked element is removed independent of created filter (Closed)
Patch Set: Created July 18, 2014, 9:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« block.js ('K') | « block.js ('k') | include.preload.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 case "get-clickhide-state": 480 case "get-clickhide-state":
481 sendResponse({active: clickHide_activated}); 481 sendResponse({active: clickHide_activated});
482 break; 482 break;
483 case "clickhide-activate": 483 case "clickhide-activate":
484 clickHide_activate(); 484 clickHide_activate();
485 break; 485 break;
486 case "clickhide-deactivate": 486 case "clickhide-deactivate":
487 clickHide_deactivate(); 487 clickHide_deactivate();
488 break; 488 break;
489 case "clickhide-new-filter": 489 case "clickhide-new-filter":
490 // The request is received by all frames, so ignore it if we're not the frame the 490 // The message is received by all frames, so ignore it if we're not the frame the
491 // user right-clicked in 491 // user right-clicked in
492 if(!lastRightClickEvent) 492 if(!lastRightClickEvent)
493 return; 493 return;
494 // We hope the URL we are given is the same as the one in the element re ferenced 494 // We hope the URL we are given is the same as the one in the element re ferenced
495 // by lastRightClickEvent.target. If not, we just discard 495 // by lastRightClickEvent.target. If not, we just discard
496 var target = lastRightClickEvent.target; 496 var target = lastRightClickEvent.target;
497 var url = target.src; 497 var url = target.src;
498 // If we don't have the element with a src URL same as the filter, look for it. 498 // If we don't have the element with a src URL same as the filter, look for it.
499 // Chrome's context menu API is terrible. Why can't it give us the frigg in' element 499 // Chrome's context menu API is terrible. Why can't it give us the frigg in' element
500 // to start with? 500 // to start with?
(...skipping 10 matching lines...) Expand all
511 // This is hopefully our element. In case of multiple elements 511 // This is hopefully our element. In case of multiple elements
512 // with the same src, only one will be highlighted. 512 // with the same src, only one will be highlighted.
513 target = elts[i]; 513 target = elts[i];
514 break; 514 break;
515 } 515 }
516 } 516 }
517 } 517 }
518 // Following test will be true if we found the element with the filter U RL 518 // Following test will be true if we found the element with the filter U RL
519 if(msg.filter === url) 519 if(msg.filter === url)
520 { 520 {
521 // This request would have come from the chrome.contextMenu handler, s o we 521 // This message would have come from the chrome.contextMenu handler, s o we
522 // simulate the user having chosen the element to get rid of via the u sual means. 522 // simulate the user having chosen the element to get rid of via the u sual means.
523 clickHide_activated = true; 523 clickHide_activated = true;
524 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it? 524 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it?
525 clickHideFilters = [msg.filter]; 525 clickHideFilters = [msg.filter];
526 // Coerce red highlighted overlay on top of element to remove. 526 // Coerce red highlighted overlay on top of element to remove.
527 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime 527 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime
528 currentElement = addElementOverlay(target); 528 currentElement = addElementOverlay(target);
529 currentElement_backgroundColor = target.style.backgroundColor; 529 currentElement_backgroundColor = target.style.backgroundColor;
530 // clickHide_mouseOver(lastRightClickEvent); 530 // clickHide_mouseOver(lastRightClickEvent);
531 clickHide_mouseClick(lastRightClickEvent); 531 clickHide_mouseClick(lastRightClickEvent);
532 } 532 }
533 else 533 else
534 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", request.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);
535 break; 535 break;
536 case "clickhide-init": 536 case "clickhide-init":
537 if (clickHideFiltersDialog) 537 if (clickHideFiltersDialog)
538 { 538 {
539 sendResponse({filters: clickHide_filters}); 539 sendResponse({filters: clickHide_filters});
540 540
541 clickHideFiltersDialog.style.width = msg.width + "px"; 541 clickHideFiltersDialog.style.width = msg.width + "px";
542 clickHideFiltersDialog.style.height = msg.height + "px"; 542 clickHideFiltersDialog.style.height = msg.height + "px";
543 clickHideFiltersDialog.style.visibility = "visible"; 543 clickHideFiltersDialog.style.visibility = "visible";
544 } 544 }
545 break; 545 break;
546 case "clickhide-move": 546 case "clickhide-move":
547 if (clickHideFiltersDialog) 547 if (clickHideFiltersDialog)
548 { 548 {
549 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + request.x) + "px"; 549 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px";
550 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + request.y) + "px"; 550 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px";
551 } 551 }
552 break; 552 break;
553 case "clickhide-close": 553 case "clickhide-close":
554 if (clickHideFiltersDialog) 554 if (clickHideFiltersDialog)
555 { 555 {
556 // Explicitly get rid of currentElement 556 // Explicitly get rid of currentElement
557 if (msg.remove && currentElement && currentElement.parentNode) 557 var filters = msg.filters;
558 currentElement.parentNode.removeChild(currentElement); 558 if (filters)
559 {
560 var isHidden = false;
561 var selectors = [];
562 for (var i = 0; i < filters.length; i++)
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 }
559 591
560 clickHide_deactivate(); 592 clickHide_deactivate();
561 } 593 }
562 break; 594 break;
563 default: 595 default:
564 sendResponse({}); 596 sendResponse({});
565 break; 597 break;
566 } 598 }
567 }); 599 });
568 } 600 }
OLDNEW
« block.js ('K') | « block.js ('k') | include.preload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld