Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 // elt.parentNode.appendChild(overlay, elt); | 246 // elt.parentNode.appendChild(overlay, elt); |
247 document.documentElement.appendChild(overlay); | 247 document.documentElement.appendChild(overlay); |
248 return overlay; | 248 return overlay; |
249 } | 249 } |
250 | 250 |
251 // Show dialog asking user whether she wants to add the proposed filters derived | 251 // Show dialog asking user whether she wants to add the proposed filters derived |
252 // from selected page element | 252 // from selected page element |
253 function clickHide_showDialog(left, top, filters) | 253 function clickHide_showDialog(left, top, filters) |
254 { | 254 { |
255 // If we are already selecting, abort now | 255 // If we are already selecting, abort now |
256 if (clickHide_activated || clickHideFiltersDialog) | 256 if (clickHide_activated) |
257 clickHide_deactivate(true); | 257 clickHide_rulesPending(); |
258 | 258 |
259 clickHide_filters = filters; | 259 clickHide_filters = filters; |
260 | 260 |
261 clickHideFiltersDialog = document.createElement("iframe"); | 261 clickHideFiltersDialog = document.createElement("iframe"); |
262 clickHideFiltersDialog.src = ext.getURL("block.html"); | 262 clickHideFiltersDialog.src = ext.getURL("block.html"); |
263 clickHideFiltersDialog.setAttribute("style", "position: fixed !important; visi bility: hidden; display: block !important; border: 0px !important;"); | 263 clickHideFiltersDialog.setAttribute("style", "position: fixed !important; visi bility: hidden; display: block !important; border: 0px !important;"); |
264 clickHideFiltersDialog.style.WebkitBoxShadow = "5px 5px 20px rgba(0,0,0,0.5)"; | 264 clickHideFiltersDialog.style.WebkitBoxShadow = "5px 5px 20px rgba(0,0,0,0.5)"; |
265 clickHideFiltersDialog.style.zIndex = 0x7FFFFFFF; | 265 clickHideFiltersDialog.style.zIndex = 0x7FFFFFFF; |
266 | 266 |
267 // Position in upper-left all the time | 267 // Position in upper-left all the time |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
327 document.removeEventListener("mousedown", clickHide_stopPropagation, true); | 327 document.removeEventListener("mousedown", clickHide_stopPropagation, true); |
328 document.removeEventListener("mouseup", clickHide_stopPropagation, true); | 328 document.removeEventListener("mouseup", clickHide_stopPropagation, true); |
329 document.removeEventListener("mouseenter", clickHide_stopPropagation, true); | 329 document.removeEventListener("mouseenter", clickHide_stopPropagation, true); |
330 document.removeEventListener("mouseleave", clickHide_stopPropagation, true); | 330 document.removeEventListener("mouseleave", clickHide_stopPropagation, true); |
331 document.removeEventListener("mouseover", clickHide_mouseOver, true); | 331 document.removeEventListener("mouseover", clickHide_mouseOver, true); |
332 document.removeEventListener("mouseout", clickHide_mouseOut, true); | 332 document.removeEventListener("mouseout", clickHide_mouseOut, true); |
333 document.removeEventListener("click", clickHide_mouseClick, true); | 333 document.removeEventListener("click", clickHide_mouseClick, true); |
334 document.removeEventListener("keydown", clickHide_keyDown, true); | 334 document.removeEventListener("keydown", clickHide_keyDown, true); |
335 } | 335 } |
336 | 336 |
337 // Turn off click-to-hide | 337 function clickHide_deactivate() |
338 function clickHide_deactivate(keepOverlays) | 338 { |
339 { | 339 clickHide_rulesPending(); |
340 | |
340 if (clickHideFiltersDialog) | 341 if (clickHideFiltersDialog) |
341 { | 342 { |
342 document.documentElement.removeChild(clickHideFiltersDialog); | 343 document.documentElement.removeChild(clickHideFiltersDialog); |
343 clickHideFiltersDialog = null; | 344 clickHideFiltersDialog = null; |
344 } | 345 } |
345 | 346 |
346 clickHide_activated = false; | |
347 clickHide_filters = null; | 347 clickHide_filters = null; |
348 if(!document) | 348 lastRightClickEvent = null; |
349 return; // This can happen inside a nuked iframe...I think | 349 |
350 | 350 if (currentElement) |
351 document.removeEventListener("mousedown", clickHide_stopPropagation, true); | 351 { |
352 document.removeEventListener("mouseup", clickHide_stopPropagation, true); | 352 currentElement.removeEventListener("contextmenu", clickHide_elementClickHan dler, true); |
353 document.removeEventListener("mouseenter", clickHide_stopPropagation, true); | |
354 document.removeEventListener("mouseleave", clickHide_stopPropagation, true); | |
355 document.removeEventListener("mouseover", clickHide_mouseOver, true); | |
356 document.removeEventListener("mouseout", clickHide_mouseOut, true); | |
357 document.removeEventListener("click", clickHide_mouseClick, true); | |
358 document.removeEventListener("keydown", clickHide_keyDown, true); | |
359 | |
360 if (keepOverlays !== true) | |
361 { | |
362 lastRightClickEvent = null; | |
363 | |
364 if (currentElement) { | |
365 currentElement.removeEventListener("contextmenu", clickHide_elementClickH andler, true); | |
366 unhighlightElements(); | |
367 unhighlightElement(currentElement); | |
368 currentElement = null; | |
369 } | |
370 unhighlightElements(); | 353 unhighlightElements(); |
371 | 354 unhighlightElement(currentElement); |
372 var overlays = document.getElementsByClassName("__adblockplus__overlay"); | 355 currentElement = null; |
373 while (overlays.length > 0) | 356 } |
374 overlays[0].parentNode.removeChild(overlays[0]); | 357 unhighlightElements(); |
375 | 358 |
376 ext.onExtensionUnloaded.removeListener(clickHide_deactivate); | 359 var overlays = document.getElementsByClassName("__adblockplus__overlay"); |
377 } | 360 while (overlays.length > 0) |
361 overlays[0].parentNode.removeChild(overlays[0]); | |
362 | |
363 ext.onExtensionUnloaded.removeListener(clickHide_deactivate); | |
378 } | 364 } |
379 | 365 |
380 function clickHide_stopPropagation(e) | 366 function clickHide_stopPropagation(e) |
381 { | 367 { |
382 e.stopPropagation(); | 368 e.stopPropagation(); |
383 } | 369 } |
384 | 370 |
385 function clickHide_elementClickHandler(e) { | 371 function clickHide_elementClickHandler(e) { |
386 e.preventDefault(); | 372 e.preventDefault(); |
387 e.stopPropagation(); | 373 e.stopPropagation(); |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 case "clickhide-move": | 700 case "clickhide-move": |
715 if (clickHideFiltersDialog) | 701 if (clickHideFiltersDialog) |
716 { | 702 { |
717 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px"; | 703 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px"; |
718 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px"; | 704 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px"; |
719 } | 705 } |
720 break; | 706 break; |
721 case "clickhide-close": | 707 case "clickhide-close": |
722 if (currentElement && msg.remove) | 708 if (currentElement && msg.remove) |
723 { | 709 { |
710 // Hide the selected element itself if an added blocking | |
711 // filter is causing it to collapse. Note that this | |
712 // behavior is incomplete, but the best we can do here, | |
713 // e.g. if an added blocking filter matches other elements, | |
714 // the effect won't be visible until the page is is reloaded. | |
724 checkCollapse(currentElement.prisoner || currentElement); | 715 checkCollapse(currentElement.prisoner || currentElement); |
kzar
2015/03/04 13:09:03
IMHO there should be a comment here to mention we'
| |
725 | 716 |
726 var selectors = msg.selectors; | 717 // Apply added element hiding filters. |
kzar
2015/03/04 11:04:02
Shouldn't we check msg.remove is true first?
Sebastian Noack
2015/03/04 11:34:52
Well, we do above. ;)
kzar
2015/03/04 13:09:03
Gah, sorry!
kzar
2015/03/04 13:09:03
I think there should also be a comment here to say
Sebastian Noack
2015/03/04 14:02:01
I don't think it needs to be that verbose. But the
kzar
2015/03/04 14:04:14
Looks great.
| |
727 if (selectors.length > 0) | 718 updateStylesheet(); |
728 hideElements(selectors); | |
729 } | 719 } |
730 clickHide_deactivate(); | 720 clickHide_deactivate(); |
731 break; | 721 break; |
732 case "clickhide-show-dialog": | 722 case "clickhide-show-dialog": |
733 if (window.self == window.top) | 723 if (window.self == window.top) |
734 clickHide_showDialog(msg.screenX + window.pageXOffset, | 724 clickHide_showDialog(msg.screenX + window.pageXOffset, |
735 msg.screenY + window.pageYOffset, | 725 msg.screenY + window.pageYOffset, |
736 msg.clickHideFilters); | 726 msg.clickHideFilters); |
737 break; | 727 break; |
738 case "clickhide-clear-last-right-click-event": | 728 case "clickhide-clear-last-right-click-event": |
739 if (lastRightClickEventValid) | 729 if (lastRightClickEventValid) |
740 lastRightClickEventValid = false; | 730 lastRightClickEventValid = false; |
741 else | 731 else |
742 lastRightClickEvent = null; | 732 lastRightClickEvent = null; |
743 break; | 733 break; |
744 } | 734 } |
745 }); | 735 }); |
746 | 736 |
747 if (window == window.top) | 737 if (window == window.top) |
748 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 738 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
749 } | 739 } |
LEFT | RIGHT |