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

Delta Between Two Patch Sets: include.postload.js

Issue 4829486721794048: Issue 700 - Generate filters based on the style attribute as last resort (Closed)
Left Patch Set: Rebased Created Oct. 23, 2014, 10:36 a.m.
Right Patch Set: Rebased and escaped backslashes Created Oct. 30, 2014, 4:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
27 function quote(value)
28 {
29 return '"' + value.replace(/(["\\])/g, "\\$1") + '"';
30 }
26 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
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, false); 338 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, false);
334 } 339 }
335 340
336 // Selects the currently hovered-over filter or cancels selection 341 // Selects the currently hovered-over filter or cancels selection
337 function clickHide_keyDown(e) 342 function clickHide_keyDown(e)
338 { 343 {
339 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /) 344 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /)
340 clickHide_mouseClick(e); 345 clickHide_mouseClick(e);
341 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/) 346 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/)
342 { 347 {
343 clickHide_deactivate(); 348 ext.backgroundPage.sendMessage(
349 {
350 type: "forward",
351 payload:
352 {
353 type: "clickhide-deactivate"
354 }
355 });
344 e.preventDefault(); 356 e.preventDefault();
345 e.stopPropagation(); 357 e.stopPropagation();
346 } 358 }
347 } 359 }
348 360
349 // When the user clicks, the currentElement is the one we want. 361 // When the user clicks, the currentElement is the one we want.
350 // We should have ABP rules ready for when the 362 // We should have ABP rules ready for when the
351 // popup asks for them. 363 // popup asks for them.
352 function clickHide_mouseClick(e) 364 function clickHide_mouseClick(e)
353 { 365 {
(...skipping 27 matching lines...) Expand all
381 selectorList.push(selector); 393 selectorList.push(selector);
382 }; 394 };
383 395
384 if (elementId) 396 if (elementId)
385 addSelector("#" + elementId); 397 addSelector("#" + elementId);
386 398
387 if (elementClasses && elementClasses.length > 0) 399 if (elementClasses && elementClasses.length > 0)
388 { 400 {
389 var selector = ""; 401 var selector = "";
390 402
391 for (var i = 0; i < elt.classList.length; i++) 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
392 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); 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
393 405
394 addSelector(selector); 406 addSelector(selector);
395 } 407 }
396 408
397 if (url) 409 if (url)
398 { 410 {
399 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); 411 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
400 selectorList.push('[src="' + elt.getAttribute("src") + '"]'); 412
401 } 413 var src = elt.getAttribute("src");
402 414 if (src)
403 // Show popup 415 selectorList.push('[src=' + quote(src) + ']');
404 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 416 }
405 417
406 // restore the original style, before generating the fallback filter that 418 // restore the original style, before generating the fallback filter that
407 // will include the style, and to prevent highlightElements from saving those 419 // will include the style, and to prevent highlightElements from saving those
408 unhighlightElement(currentElement); 420 unhighlightElement(currentElement);
409 421
410 // as last resort, create a filter based on inline styles 422 // as last resort, create a filter based on inline styles
411 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) 423 if (clickHideFilters.length == 0)
412 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/ "/g, '\\"') + '"]'); 424 {
425 var style = elt.getAttribute("style");
426 if (style)
427 addSelector(elt.localName + '[style=' + quote(style) + ']');
428 }
429
430 // Show popup
431 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
413 432
414 // Highlight the elements specified by selector in yellow 433 // Highlight the elements specified by selector in yellow
415 highlightElements(selectorList.join(",")); 434 highlightElements(selectorList.join(","));
416 // Now, actually highlight the element the user clicked on in red 435 // Now, actually highlight the element the user clicked on in red
417 highlightElement(currentElement, "#fd1708", "#f6a1b5"); 436 highlightElement(currentElement, "#fd1708", "#f6a1b5");
418 437
419 // Make sure the browser doesn't handle this click 438 // Make sure the browser doesn't handle this click
420 e.preventDefault(); 439 e.preventDefault();
421 e.stopPropagation(); 440 e.stopPropagation();
422 } 441 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 clickHide_activated = true; 615 clickHide_activated = true;
597 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it? 616 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it?
598 clickHideFilters = [msg.filter]; 617 clickHideFilters = [msg.filter];
599 // Coerce red highlighted overlay on top of element to remove. 618 // Coerce red highlighted overlay on top of element to remove.
600 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime 619 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime
601 currentElement = addElementOverlay(target); 620 currentElement = addElementOverlay(target);
602 // clickHide_mouseOver(lastRightClickEvent); 621 // clickHide_mouseOver(lastRightClickEvent);
603 clickHide_mouseClick(lastRightClickEvent); 622 clickHide_mouseClick(lastRightClickEvent);
604 } 623 }
605 else 624 else
606 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", request.filter, url, lastRightClickEvent.target.src); 625 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", msg.filter, url, lastRightClickEvent.target.src);
607 break; 626 break;
608 case "clickhide-init": 627 case "clickhide-init":
609 if (clickHideFiltersDialog) 628 if (clickHideFiltersDialog)
610 { 629 {
611 sendResponse({filters: clickHide_filters}); 630 sendResponse({filters: clickHide_filters});
612 631
613 clickHideFiltersDialog.style.width = msg.width + "px"; 632 clickHideFiltersDialog.style.width = msg.width + "px";
614 clickHideFiltersDialog.style.height = msg.height + "px"; 633 clickHideFiltersDialog.style.height = msg.height + "px";
615 clickHideFiltersDialog.style.visibility = "visible"; 634 clickHideFiltersDialog.style.visibility = "visible";
616 } 635 }
617 break; 636 break;
618 case "clickhide-move": 637 case "clickhide-move":
619 if (clickHideFiltersDialog) 638 if (clickHideFiltersDialog)
620 { 639 {
621 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + request.x) + "px"; 640 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px";
622 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + request.y) + "px"; 641 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px";
623 } 642 }
624 break; 643 break;
625 case "clickhide-close": 644 case "clickhide-close":
626 if (clickHideFiltersDialog) 645 if (clickHideFiltersDialog)
627 { 646 {
628 // Explicitly get rid of currentElement 647 // Explicitly get rid of currentElement
629 if (msg.remove && currentElement && currentElement.parentNode) 648 if (msg.remove && currentElement && currentElement.parentNode)
630 currentElement.parentNode.removeChild(currentElement); 649 currentElement.parentNode.removeChild(currentElement);
631
632 clickHide_deactivate();
633 } 650 }
651 clickHide_deactivate();
634 break; 652 break;
635 default: 653 default:
636 sendResponse({}); 654 sendResponse({});
637 break; 655 break;
638 } 656 }
639 }); 657 });
640 658
641 if (window == window.top) 659 if (window == window.top)
642 ext.backgroundPage.sendMessage({type: "report-html-page"}); 660 ext.backgroundPage.sendMessage({type: "report-html-page"});
643 } 661 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld