| OLD | NEW |
| 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 clickHideFilters = null; | |
| 23 var highlightedElementsSelector = null; | 22 var highlightedElementsSelector = null; |
| 24 var clickHideFiltersDialog = null; | 23 var clickHideFiltersDialog = null; |
| 25 var lastRightClickEvent = null; | 24 var lastRightClickEvent = null; |
| 25 var lastRightClickEventRandom = null; |
| 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Position in upper-left all the time | 318 // Position in upper-left all the time |
| 319 clickHideFiltersDialog.style.left = "50px"; | 319 clickHideFiltersDialog.style.left = "50px"; |
| 320 clickHideFiltersDialog.style.top = "50px"; | 320 clickHideFiltersDialog.style.top = "50px"; |
| 321 | 321 |
| 322 // Make dialog partly transparent when mouse isn't over it so user has a bette
r | 322 // Make dialog partly transparent when mouse isn't over it so user has a bette
r |
| 323 // view of what's going to be blocked | 323 // view of what's going to be blocked |
| 324 clickHideFiltersDialog.onmouseout = function() | 324 clickHideFiltersDialog.onmouseout = function() |
| 325 { | 325 { |
| 326 if (clickHideFiltersDialog) | 326 if (clickHideFiltersDialog) |
| 327 clickHideFiltersDialog.style.setProperty("opacity", "0.7"); | 327 clickHideFiltersDialog.style.setProperty("opacity", "0.7"); |
| 328 } | 328 }; |
| 329 clickHideFiltersDialog.onmouseover = function() | 329 clickHideFiltersDialog.onmouseover = function() |
| 330 { | 330 { |
| 331 if (clickHideFiltersDialog) | 331 if (clickHideFiltersDialog) |
| 332 clickHideFiltersDialog.style.setProperty("opacity", "1.0"); | 332 clickHideFiltersDialog.style.setProperty("opacity", "1.0"); |
| 333 } | 333 }; |
| 334 | 334 |
| 335 document.body.appendChild(clickHideFiltersDialog); | 335 document.body.appendChild(clickHideFiltersDialog); |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Turn on the choose element to create filter thing | 338 // Turn on the choose element to create filter thing |
| 339 function clickHide_activate() { | 339 function clickHide_activate() { |
| 340 if(document == null) | 340 if(document == null) |
| 341 return; | 341 return; |
| 342 | 342 |
| 343 // If we are already selecting, abort now | 343 // If we are already selecting, abort now |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 clickHide_filters = null; | 383 clickHide_filters = null; |
| 384 if(!document) | 384 if(!document) |
| 385 return; // This can happen inside a nuked iframe...I think | 385 return; // This can happen inside a nuked iframe...I think |
| 386 document.removeEventListener("mouseover", clickHide_mouseOver, true); | 386 document.removeEventListener("mouseover", clickHide_mouseOver, true); |
| 387 document.removeEventListener("mouseout", clickHide_mouseOut, true); | 387 document.removeEventListener("mouseout", clickHide_mouseOut, true); |
| 388 document.removeEventListener("click", clickHide_mouseClick, true); | 388 document.removeEventListener("click", clickHide_mouseClick, true); |
| 389 document.removeEventListener("keydown", clickHide_keyDown, true); | 389 document.removeEventListener("keydown", clickHide_keyDown, true); |
| 390 | 390 |
| 391 if (!keepOverlays) | 391 if (!keepOverlays) |
| 392 { | 392 { |
| 393 lastRightClickEvent = null; |
| 394 |
| 393 if (currentElement) { | 395 if (currentElement) { |
| 394 currentElement.removeEventListener("contextmenu", clickHide_elementClickH
andler, true); | 396 currentElement.removeEventListener("contextmenu", clickHide_elementClickH
andler, true); |
| 395 unhighlightElements(); | 397 unhighlightElements(); |
| 396 unhighlightElement(currentElement); | 398 unhighlightElement(currentElement); |
| 397 currentElement = null; | 399 currentElement = null; |
| 398 clickHideFilters = null; | |
| 399 } | 400 } |
| 400 unhighlightElements(); | 401 unhighlightElements(); |
| 401 | 402 |
| 402 var overlays = document.getElementsByClassName("__adblockplus__overlay"); | 403 var overlays = document.getElementsByClassName("__adblockplus__overlay"); |
| 403 while (overlays.length > 0) | 404 while (overlays.length > 0) |
| 404 overlays[0].parentNode.removeChild(overlays[0]); | 405 overlays[0].parentNode.removeChild(overlays[0]); |
| 405 } | 406 } |
| 406 } | 407 } |
| 407 | 408 |
| 408 function clickHide_elementClickHandler(ev) { | 409 function clickHide_elementClickHandler(ev) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // popup asks for them. | 468 // popup asks for them. |
| 468 function clickHide_mouseClick(e) | 469 function clickHide_mouseClick(e) |
| 469 { | 470 { |
| 470 if (!currentElement || !clickHide_activated) | 471 if (!currentElement || !clickHide_activated) |
| 471 return; | 472 return; |
| 472 | 473 |
| 473 var elt = currentElement; | 474 var elt = currentElement; |
| 474 if (currentElement.classList.contains("__adblockplus__overlay")) | 475 if (currentElement.classList.contains("__adblockplus__overlay")) |
| 475 elt = currentElement.prisoner; | 476 elt = currentElement.prisoner; |
| 476 | 477 |
| 477 clickHideFilters = new Array(); | 478 var clickHideFilters = new Array(); |
| 478 selectorList = new Array(); | 479 var selectorList = new Array(); |
| 479 | 480 |
| 480 var addSelector = function(selector) | 481 var addSelector = function(selector) |
| 481 { | 482 { |
| 482 if (selectorList.indexOf(selector) != -1) | 483 if (selectorList.indexOf(selector) != -1) |
| 483 return; | 484 return; |
| 484 | 485 |
| 485 clickHideFilters.push(document.domain + "##" + selector); | 486 clickHideFilters.push(document.domain + "##" + selector); |
| 486 selectorList.push(selector); | 487 selectorList.push(selector); |
| 487 }; | 488 }; |
| 488 | 489 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 519 } | 520 } |
| 520 | 521 |
| 521 // as last resort, create a filter based on inline styles | 522 // as last resort, create a filter based on inline styles |
| 522 if (clickHideFilters.length == 0) | 523 if (clickHideFilters.length == 0) |
| 523 { | 524 { |
| 524 var style = elt.getAttribute("style"); | 525 var style = elt.getAttribute("style"); |
| 525 if (style) | 526 if (style) |
| 526 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']'); | 527 addSelector(escapeCSS(elt.localName) + '[style=' + quote(style) + ']'); |
| 527 } | 528 } |
| 528 | 529 |
| 529 // Show popup | 530 // Show popup, or if inside frame tell the parent to do it |
| 530 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 531 if (window.self == window.top) |
| 532 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
| 533 else |
| 534 ext.backgroundPage.sendMessage( |
| 535 { |
| 536 type: "clickHide-showDialog", |
| 537 screenX: e.screenX, |
| 538 screenY: e.screenY, |
| 539 clickHideFilters: clickHideFilters |
| 540 }); |
| 531 | 541 |
| 532 // Highlight the elements specified by selector in yellow | 542 // Highlight the elements specified by selector in yellow |
| 533 if (selectorList.length > 0) | 543 if (selectorList.length > 0) |
| 534 highlightElements(selectorList.join(",")); | 544 highlightElements(selectorList.join(",")); |
| 535 // Now, actually highlight the element the user clicked on in red | 545 // Now, actually highlight the element the user clicked on in red |
| 536 highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 546 highlightElement(currentElement, "#fd1708", "#f6a1b5"); |
| 537 | 547 |
| 538 // Make sure the browser doesn't handle this click | 548 // Make sure the browser doesn't handle this click |
| 539 e.preventDefault(); | 549 e.preventDefault(); |
| 540 e.stopPropagation(); | 550 e.stopPropagation(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 // In Chrome 37-40, the document_end content script (this one) runs properly, wh
ile the | 582 // In Chrome 37-40, the document_end content script (this one) runs properly, wh
ile the |
| 573 // document_start content scripts (that defines ext) might not. Check whether va
riable ext | 583 // document_start content scripts (that defines ext) might not. Check whether va
riable ext |
| 574 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define
d". | 584 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define
d". |
| 575 // See https://crbug.com/416907 | 585 // See https://crbug.com/416907 |
| 576 if ("ext" in window && document instanceof HTMLDocument) | 586 if ("ext" in window && document instanceof HTMLDocument) |
| 577 { | 587 { |
| 578 // Use a contextmenu handler to save the last element the user right-clicked o
n. | 588 // Use a contextmenu handler to save the last element the user right-clicked o
n. |
| 579 // To make things easier, we actually save the DOM event. | 589 // To make things easier, we actually save the DOM event. |
| 580 // We have to do this because the contextMenu API only provides a URL, not the
actual | 590 // We have to do this because the contextMenu API only provides a URL, not the
actual |
| 581 // DOM element. | 591 // DOM element. |
| 582 document.addEventListener('contextmenu', function(e) { | 592 document.addEventListener('contextmenu', function(e) |
| 593 { |
| 583 lastRightClickEvent = e; | 594 lastRightClickEvent = e; |
| 595 // 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 |
| 597 // frames that they should clear lastRightClickEvent unless the number match
es |
| 598 lastRightClickEventRandom = Math.random(); |
| 599 ext.backgroundPage.sendMessage( |
| 600 { |
| 601 type: "clickHide-clear-lastRightClickEvent", |
| 602 random: lastRightClickEventRandom |
| 603 }); |
| 584 }, true); | 604 }, true); |
| 585 | 605 |
| 586 document.addEventListener("click", function(event) | 606 document.addEventListener("click", function(event) |
| 587 { | 607 { |
| 588 // Ignore right-clicks | 608 // Ignore right-clicks |
| 589 if (event.button == 2) | 609 if (event.button == 2) |
| 590 return; | 610 return; |
| 591 | 611 |
| 592 // Search the link associated with the click | 612 // Search the link associated with the click |
| 593 var link = event.target; | 613 var link = event.target; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 696 } |
| 677 break; | 697 break; |
| 678 case "clickhide-move": | 698 case "clickhide-move": |
| 679 if (clickHideFiltersDialog) | 699 if (clickHideFiltersDialog) |
| 680 { | 700 { |
| 681 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s
tyle.left, 10) + msg.x) + "px"; | 701 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s
tyle.left, 10) + msg.x) + "px"; |
| 682 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st
yle.top, 10) + msg.y) + "px"; | 702 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st
yle.top, 10) + msg.y) + "px"; |
| 683 } | 703 } |
| 684 break; | 704 break; |
| 685 case "clickhide-close": | 705 case "clickhide-close": |
| 686 if (clickHideFiltersDialog && msg.remove) | 706 if (currentElement && msg.remove) |
| 687 { | 707 { |
| 688 // Explicitly get rid of currentElement | 708 // Explicitly get rid of currentElement |
| 689 var element = currentElement.prisoner || currentElement; | 709 var element = currentElement.prisoner || currentElement; |
| 690 if (element && element.parentNode) | 710 if (element && element.parentNode) |
| 691 element.parentNode.removeChild(element); | 711 element.parentNode.removeChild(element); |
| 692 } | 712 } |
| 693 clickHide_deactivate(); | 713 clickHide_deactivate(); |
| 694 break; | 714 break; |
| 715 case "clickHide-showDialog": |
| 716 if (window.self == window.top) |
| 717 clickHide_showDialog(msg.screenX + window.pageXOffset, |
| 718 msg.screenY + window.pageYOffset, |
| 719 msg.clickHideFilters); |
| 720 break; |
| 721 case "clickHide-clear-lastRightClickEvent": |
| 722 if (msg.random != lastRightClickEventRandom) |
| 723 lastRightClickEvent = null; |
| 724 lastRightClickEventRandom = null; |
| 725 break; |
| 695 } | 726 } |
| 696 }); | 727 }); |
| 697 | 728 |
| 698 if (window == window.top) | 729 if (window == window.top) |
| 699 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 730 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
| 700 } | 731 } |
| OLD | NEW |