| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 // If we are already selecting, abort now | 263 // If we are already selecting, abort now |
| 264 if (clickHide_activated || clickHideFiltersDialog) | 264 if (clickHide_activated || clickHideFiltersDialog) |
| 265 clickHide_deactivate(); | 265 clickHide_deactivate(); |
| 266 | 266 |
| 267 // Add overlays for elements with URLs so user can easily click them | 267 // Add overlays for elements with URLs so user can easily click them |
| 268 var elts = document.querySelectorAll('object,embed,img,iframe'); | 268 var elts = document.querySelectorAll('object,embed,img,iframe'); |
| 269 for(var i=0; i<elts.length; i++) | 269 for(var i=0; i<elts.length; i++) |
| 270 addElementOverlay(elts[i]); | 270 addElementOverlay(elts[i]); |
| 271 | 271 |
| 272 clickHide_activated = true; | 272 clickHide_activated = true; |
| 273 document.addEventListener("mouseover", clickHide_mouseOver, false); | 273 document.addEventListener("mouseover", clickHide_mouseOver, true); |
| 274 document.addEventListener("mouseout", clickHide_mouseOut, false); | 274 document.addEventListener("mouseout", clickHide_mouseOut, true); |
| 275 document.addEventListener("click", clickHide_mouseClick, false); | 275 document.addEventListener("click", clickHide_mouseClick, true); |
| 276 document.addEventListener("keydown", clickHide_keyDown, false); | 276 document.addEventListener("keydown", clickHide_keyDown, true); |
| 277 } | 277 } |
| 278 | 278 |
| 279 // Called when user has clicked on something and we are waiting for confirmation | 279 // Called when user has clicked on something and we are waiting for confirmation |
| 280 // on whether the user actually wants these filters | 280 // on whether the user actually wants these filters |
| 281 function clickHide_rulesPending() { | 281 function clickHide_rulesPending() { |
| 282 clickHide_activated = false; | 282 clickHide_activated = false; |
| 283 document.removeEventListener("mouseover", clickHide_mouseOver, false); | 283 document.removeEventListener("mouseover", clickHide_mouseOver, true); |
| 284 document.removeEventListener("mouseout", clickHide_mouseOut, false); | 284 document.removeEventListener("mouseout", clickHide_mouseOut, true); |
| 285 document.removeEventListener("click", clickHide_mouseClick, false); | 285 document.removeEventListener("click", clickHide_mouseClick, true); |
| 286 document.removeEventListener("keydown", clickHide_keyDown, false); | 286 document.removeEventListener("keydown", clickHide_keyDown, true); |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Turn off click-to-hide | 289 // Turn off click-to-hide |
| 290 function clickHide_deactivate() | 290 function clickHide_deactivate() |
| 291 { | 291 { |
| 292 if (clickHideFiltersDialog) | 292 if (clickHideFiltersDialog) |
| 293 { | 293 { |
| 294 document.body.removeChild(clickHideFiltersDialog); | 294 document.body.removeChild(clickHideFiltersDialog); |
| 295 clickHideFiltersDialog = null; | 295 clickHideFiltersDialog = null; |
| 296 } | 296 } |
| 297 | 297 |
| 298 if(currentElement) { | 298 if(currentElement) { |
| 299 currentElement.removeEventListener("contextmenu", clickHide_elementClickHand
ler, false); | 299 currentElement.removeEventListener("contextmenu", clickHide_elementClickHand
ler, false); |
| 300 unhighlightElements(); | 300 unhighlightElements(); |
| 301 unhighlightElement(currentElement); | 301 unhighlightElement(currentElement); |
| 302 currentElement = null; | 302 currentElement = null; |
| 303 clickHideFilters = null; | 303 clickHideFilters = null; |
| 304 } | 304 } |
| 305 unhighlightElements(); | 305 unhighlightElements(); |
| 306 | 306 |
| 307 clickHide_activated = false; | 307 clickHide_activated = false; |
| 308 clickHide_filters = null; | 308 clickHide_filters = null; |
| 309 if(!document) | 309 if(!document) |
| 310 return; // This can happen inside a nuked iframe...I think | 310 return; // This can happen inside a nuked iframe...I think |
| 311 document.removeEventListener("mouseover", clickHide_mouseOver, false); | 311 document.removeEventListener("mouseover", clickHide_mouseOver, true); |
| 312 document.removeEventListener("mouseout", clickHide_mouseOut, false); | 312 document.removeEventListener("mouseout", clickHide_mouseOut, true); |
| 313 document.removeEventListener("click", clickHide_mouseClick, false); | 313 document.removeEventListener("click", clickHide_mouseClick, true); |
| 314 document.removeEventListener("keydown", clickHide_keyDown, false); | 314 document.removeEventListener("keydown", clickHide_keyDown, true); |
| 315 | 315 |
| 316 // Remove overlays | 316 // Remove overlays |
| 317 // For some reason iterating over the array returend by getElementsByClassName
() doesn't work | 317 // For some reason iterating over the array returend by getElementsByClassName
() doesn't work |
| 318 var elt; | 318 var elt; |
| 319 while(elt = document.querySelector('.__adblockplus__overlay')) | 319 while(elt = document.querySelector('.__adblockplus__overlay')) |
| 320 elt.parentNode.removeChild(elt); | 320 elt.parentNode.removeChild(elt); |
| 321 } | 321 } |
| 322 | 322 |
| 323 function clickHide_elementClickHandler(ev) { | 323 function clickHide_elementClickHandler(ev) { |
| 324 ev.preventDefault(); | 324 ev.preventDefault(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 336 while (target.parentNode && !(target.id || target.className || getElementURLs(
target).length > 0 || /:.+:/.test(target.getAttribute("style")))) | 336 while (target.parentNode && !(target.id || target.className || getElementURLs(
target).length > 0 || /:.+:/.test(target.getAttribute("style")))) |
| 337 target = target.parentNode; | 337 target = target.parentNode; |
| 338 if (target == document.documentElement || target == document.body) | 338 if (target == document.documentElement || target == document.body) |
| 339 target = null; | 339 target = null; |
| 340 | 340 |
| 341 if (target && target instanceof HTMLElement) | 341 if (target && target instanceof HTMLElement) |
| 342 { | 342 { |
| 343 currentElement = target; | 343 currentElement = target; |
| 344 | 344 |
| 345 highlightElement(target, "#d6d84b", "#f8fa47"); | 345 highlightElement(target, "#d6d84b", "#f8fa47"); |
| 346 target.addEventListener("contextmenu", clickHide_elementClickHandler, false)
; | 346 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 // No longer hovering over this element so unhighlight it | 350 // No longer hovering over this element so unhighlight it |
| 351 function clickHide_mouseOut(e) | 351 function clickHide_mouseOut(e) |
| 352 { | 352 { |
| 353 if (!clickHide_activated || !currentElement) | 353 if (!clickHide_activated || !currentElement) |
| 354 return; | 354 return; |
| 355 | 355 |
| 356 unhighlightElement(currentElement); | 356 unhighlightElement(currentElement); |
| 357 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle
r, false); | 357 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle
r, true); |
| 358 } | 358 } |
| 359 | 359 |
| 360 // Selects the currently hovered-over filter or cancels selection | 360 // Selects the currently hovered-over filter or cancels selection |
| 361 function clickHide_keyDown(e) | 361 function clickHide_keyDown(e) |
| 362 { | 362 { |
| 363 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN*
/) | 363 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN*
/) |
| 364 clickHide_mouseClick(e); | 364 clickHide_mouseClick(e); |
| 365 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES
CAPE*/) | 365 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES
CAPE*/) |
| 366 { | 366 { |
| 367 ext.backgroundPage.sendMessage( | 367 ext.backgroundPage.sendMessage( |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define
d". | 578 // exists before continuing to avoid "Uncaught ReferenceError: ext is not define
d". |
| 579 // See https://crbug.com/416907 | 579 // See https://crbug.com/416907 |
| 580 if ("ext" in window && document instanceof HTMLDocument) | 580 if ("ext" in window && document instanceof HTMLDocument) |
| 581 { | 581 { |
| 582 // Use a contextmenu handler to save the last element the user right-clicked o
n. | 582 // Use a contextmenu handler to save the last element the user right-clicked o
n. |
| 583 // To make things easier, we actually save the DOM event. | 583 // To make things easier, we actually save the DOM event. |
| 584 // We have to do this because the contextMenu API only provides a URL, not the
actual | 584 // We have to do this because the contextMenu API only provides a URL, not the
actual |
| 585 // DOM element. | 585 // DOM element. |
| 586 document.addEventListener('contextmenu', function(e) { | 586 document.addEventListener('contextmenu', function(e) { |
| 587 lastRightClickEvent = e; | 587 lastRightClickEvent = e; |
| 588 }, false); | 588 }, true); |
| 589 | 589 |
| 590 document.addEventListener("click", function(event) | 590 document.addEventListener("click", function(event) |
| 591 { | 591 { |
| 592 // Ignore right-clicks | 592 // Ignore right-clicks |
| 593 if (event.button == 2) | 593 if (event.button == 2) |
| 594 return; | 594 return; |
| 595 | 595 |
| 596 // Search the link associated with the click | 596 // Search the link associated with the click |
| 597 var link = event.target; | 597 var link = event.target; |
| 598 while (link && !(link instanceof HTMLAnchorElement)) | 598 while (link && !(link instanceof HTMLAnchorElement)) |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 break; | 735 break; |
| 736 default: | 736 default: |
| 737 sendResponse({}); | 737 sendResponse({}); |
| 738 break; | 738 break; |
| 739 } | 739 } |
| 740 }); | 740 }); |
| 741 | 741 |
| 742 if (window == window.top) | 742 if (window == window.top) |
| 743 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 743 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
| 744 } | 744 } |
| OLD | NEW |