| 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-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 if (clickHide_activated || clickHideFiltersDialog) | 108 if (clickHide_activated || clickHideFiltersDialog) |
| 109 { | 109 { |
| 110 var savedElement = (currentElement.prisoner ? currentElement.prisoner : curr
entElement); | 110 var savedElement = (currentElement.prisoner ? currentElement.prisoner : curr
entElement); |
| 111 clickHide_deactivate(); | 111 clickHide_deactivate(); |
| 112 currentElement = savedElement; | 112 currentElement = savedElement; |
| 113 } | 113 } |
| 114 | 114 |
| 115 clickHide_filters = filters; | 115 clickHide_filters = filters; |
| 116 | 116 |
| 117 clickHideFiltersDialog = document.createElement("iframe"); | 117 clickHideFiltersDialog = document.createElement("iframe"); |
| 118 clickHideFiltersDialog.src = chrome.extension.getURL("block.html"); | 118 clickHideFiltersDialog.src = ext.getURL("block.html"); |
| 119 clickHideFiltersDialog.setAttribute("style", "position: fixed !important; visi
bility: hidden; display: block !important; border: 0px !important;"); | 119 clickHideFiltersDialog.setAttribute("style", "position: fixed !important; visi
bility: hidden; display: block !important; border: 0px !important;"); |
| 120 clickHideFiltersDialog.style.WebkitBoxShadow = "5px 5px 20px rgba(0,0,0,0.5)"; | 120 clickHideFiltersDialog.style.WebkitBoxShadow = "5px 5px 20px rgba(0,0,0,0.5)"; |
| 121 clickHideFiltersDialog.style.zIndex = 99999; | 121 clickHideFiltersDialog.style.zIndex = 99999; |
| 122 | 122 |
| 123 // Position in upper-left all the time | 123 // Position in upper-left all the time |
| 124 clickHideFiltersDialog.style.left = "50px"; | 124 clickHideFiltersDialog.style.left = "50px"; |
| 125 clickHideFiltersDialog.style.top = "50px"; | 125 clickHideFiltersDialog.style.top = "50px"; |
| 126 | 126 |
| 127 // Make dialog partly transparent when mouse isn't over it so user has a bette
r | 127 // Make dialog partly transparent when mouse isn't over it so user has a bette
r |
| 128 // view of what's going to be blocked | 128 // view of what's going to be blocked |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 // Default title to the URL | 460 // Default title to the URL |
| 461 if (!title) | 461 if (!title) |
| 462 title = url; | 462 title = url; |
| 463 | 463 |
| 464 // Trim spaces in title and URL | 464 // Trim spaces in title and URL |
| 465 title = title.replace(/^\s+/, "").replace(/\s+$/, ""); | 465 title = title.replace(/^\s+/, "").replace(/\s+$/, ""); |
| 466 url = url.replace(/^\s+/, "").replace(/\s+$/, ""); | 466 url = url.replace(/^\s+/, "").replace(/\s+$/, ""); |
| 467 if (!/^(https?|ftp):/.test(url)) | 467 if (!/^(https?|ftp):/.test(url)) |
| 468 return; | 468 return; |
| 469 | 469 |
| 470 chrome.extension.sendRequest({reqtype: "add-subscription", title: title, url
: url}); | 470 ext.backgroundPage.sendMessage({ |
| 471 type: "add-subscription", |
| 472 title: title, |
| 473 url: url |
| 474 }); |
| 471 }, true); | 475 }, true); |
| 472 | 476 |
| 473 chrome.extension.onRequest.addListener(function(request, sender, sendResponse) | 477 ext.onMessage.addListener(function(msg, sender, sendResponse) |
| 474 { | 478 { |
| 475 switch (request.reqtype) | 479 switch (msg.type) |
| 476 { | 480 { |
| 477 case "get-clickhide-state": | 481 case "get-clickhide-state": |
| 478 sendResponse({active: clickHide_activated}); | 482 sendResponse({active: clickHide_activated}); |
| 479 break; | 483 break; |
| 480 case "clickhide-activate": | 484 case "clickhide-activate": |
| 481 clickHide_activate(); | 485 clickHide_activate(); |
| 482 break; | 486 break; |
| 483 case "clickhide-deactivate": | 487 case "clickhide-deactivate": |
| 484 clickHide_deactivate(); | 488 clickHide_deactivate(); |
| 485 break; | 489 break; |
| 486 case "clickhide-new-filter": | 490 case "clickhide-new-filter": |
| 487 // The request is received by all frames, so ignore it if we're not the
frame the | 491 // The request is received by all frames, so ignore it if we're not the
frame the |
| 488 // user right-clicked in | 492 // user right-clicked in |
| 489 if(!lastRightClickEvent) | 493 if(!lastRightClickEvent) |
| 490 return; | 494 return; |
| 491 // We hope the URL we are given is the same as the one in the element re
ferenced | 495 // We hope the URL we are given is the same as the one in the element re
ferenced |
| 492 // by lastRightClickEvent.target. If not, we just discard | 496 // by lastRightClickEvent.target. If not, we just discard |
| 493 var target = lastRightClickEvent.target; | 497 var target = lastRightClickEvent.target; |
| 494 var url = target.src; | 498 var url = target.src; |
| 495 // If we don't have the element with a src URL same as the filter, look
for it. | 499 // If we don't have the element with a src URL same as the filter, look
for it. |
| 496 // Chrome's context menu API is terrible. Why can't it give us the frigg
in' element | 500 // Chrome's context menu API is terrible. Why can't it give us the frigg
in' element |
| 497 // to start with? | 501 // to start with? |
| 498 if(request.filter !== url) { | 502 if(msg.filter !== url) |
| 503 { |
| 499 // Grab all elements with a src attribute. | 504 // Grab all elements with a src attribute. |
| 500 // This won't work for all object/embed tags, but the context menu API
doesn't | 505 // This won't work for all object/embed tags, but the context menu API
doesn't |
| 501 // work on those, so we're OK for now. | 506 // work on those, so we're OK for now. |
| 502 var elts = document.querySelectorAll('[src]'); | 507 var elts = document.querySelectorAll('[src]'); |
| 503 for(var i=0; i<elts.length; i++) { | 508 for(var i=0; i<elts.length; i++) { |
| 504 url = elts[i].src; | 509 url = elts[i].src; |
| 505 if(request.filter === url) { | 510 if(msg.filter === url) |
| 511 { |
| 506 // This is hopefully our element. In case of multiple elements | 512 // This is hopefully our element. In case of multiple elements |
| 507 // with the same src, only one will be highlighted. | 513 // with the same src, only one will be highlighted. |
| 508 target = elts[i]; | 514 target = elts[i]; |
| 509 break; | 515 break; |
| 510 } | 516 } |
| 511 } | 517 } |
| 512 } | 518 } |
| 513 // Following test will be true if we found the element with the filter U
RL | 519 // Following test will be true if we found the element with the filter U
RL |
| 514 if(request.filter === url) | 520 if(msg.filter === url) |
| 515 { | 521 { |
| 516 // This request would have come from the chrome.contextMenu handler, s
o we | 522 // This request would have come from the chrome.contextMenu handler, s
o we |
| 517 // simulate the user having chosen the element to get rid of via the u
sual means. | 523 // simulate the user having chosen the element to get rid of via the u
sual means. |
| 518 clickHide_activated = true; | 524 clickHide_activated = true; |
| 519 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s
o why set it? | 525 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s
o why set it? |
| 520 clickHideFilters = [request.filter]; | 526 clickHideFilters = [msg.filter]; |
| 521 // Coerce red highlighted overlay on top of element to remove. | 527 // Coerce red highlighted overlay on top of element to remove. |
| 522 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta
fix it sometime | 528 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta
fix it sometime |
| 523 currentElement = addElementOverlay(target); | 529 currentElement = addElementOverlay(target); |
| 524 // clickHide_mouseOver(lastRightClickEvent); | 530 // clickHide_mouseOver(lastRightClickEvent); |
| 525 clickHide_mouseClick(lastRightClickEvent); | 531 clickHide_mouseClick(lastRightClickEvent); |
| 526 } | 532 } |
| 527 else | 533 else |
| 528 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.", request.filter, url, lastRightClickEvent.target.src); |
| 529 break; | 535 break; |
| 530 case "clickhide-init": | 536 case "clickhide-init": |
| 531 if (clickHideFiltersDialog) | 537 if (clickHideFiltersDialog) |
| 532 { | 538 { |
| 533 sendResponse({filters: clickHide_filters}); | 539 sendResponse({filters: clickHide_filters}); |
| 534 | 540 |
| 535 clickHideFiltersDialog.style.width = (request.width + 5) + "px"; | 541 clickHideFiltersDialog.style.width = (msg.width + 5) + "px"; |
| 536 clickHideFiltersDialog.style.height = (request.height + 5) + "px"; | 542 clickHideFiltersDialog.style.height = (msg.height + 5) + "px"; |
| 537 clickHideFiltersDialog.style.visibility = "visible"; | 543 clickHideFiltersDialog.style.visibility = "visible"; |
| 538 } | 544 } |
| 539 break; | 545 break; |
| 540 case "clickhide-move": | 546 case "clickhide-move": |
| 541 if (clickHideFiltersDialog) | 547 if (clickHideFiltersDialog) |
| 542 { | 548 { |
| 543 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s
tyle.left, 10) + request.x) + "px"; | 549 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s
tyle.left, 10) + request.x) + "px"; |
| 544 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st
yle.top, 10) + request.y) + "px"; | 550 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st
yle.top, 10) + request.y) + "px"; |
| 545 } | 551 } |
| 546 break; | 552 break; |
| 547 case "clickhide-close": | 553 case "clickhide-close": |
| 548 if (clickHideFiltersDialog) | 554 if (clickHideFiltersDialog) |
| 549 { | 555 { |
| 550 // Explicitly get rid of currentElement | 556 // Explicitly get rid of currentElement |
| 551 if (request.remove && currentElement && currentElement.parentNode) | 557 if (msg.remove && currentElement && currentElement.parentNode) |
| 552 currentElement.parentNode.removeChild(currentElement); | 558 currentElement.parentNode.removeChild(currentElement); |
| 553 | 559 |
| 554 clickHide_deactivate(); | 560 clickHide_deactivate(); |
| 555 } | 561 } |
| 556 break; | 562 break; |
| 557 default: | 563 default: |
| 558 sendResponse({}); | 564 sendResponse({}); |
| 559 break; | 565 break; |
| 560 } | 566 } |
| 561 }); | 567 }); |
| 562 } | 568 } |
| OLD | NEW |