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 switch (msg.type) |
475 switch (request.reqtype) | |
476 { | 479 { |
477 case "get-clickhide-state": | 480 case "get-clickhide-state": |
478 sendResponse({active: clickHide_activated}); | 481 sendResponse({active: clickHide_activated}); |
479 break; | 482 break; |
480 case "clickhide-activate": | 483 case "clickhide-activate": |
481 clickHide_activate(); | 484 clickHide_activate(); |
482 break; | 485 break; |
483 case "clickhide-deactivate": | 486 case "clickhide-deactivate": |
484 clickHide_deactivate(); | 487 clickHide_deactivate(); |
485 break; | 488 break; |
486 case "clickhide-new-filter": | 489 case "clickhide-new-filter": |
487 // The request is received by all frames, so ignore it if we're not the
frame the | 490 // The request is received by all frames, so ignore it if we're not the
frame the |
488 // user right-clicked in | 491 // user right-clicked in |
489 if(!lastRightClickEvent) | 492 if(!lastRightClickEvent) |
490 return; | 493 return; |
491 // We hope the URL we are given is the same as the one in the element re
ferenced | 494 // 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 | 495 // by lastRightClickEvent.target. If not, we just discard |
493 var target = lastRightClickEvent.target; | 496 var target = lastRightClickEvent.target; |
494 var url = target.src; | 497 var url = target.src; |
495 // If we don't have the element with a src URL same as the filter, look
for it. | 498 // 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 | 499 // Chrome's context menu API is terrible. Why can't it give us the frigg
in' element |
497 // to start with? | 500 // to start with? |
498 if(request.filter !== url) { | 501 if(msg.filter !== url) { |
499 // Grab all elements with a src attribute. | 502 // Grab all elements with a src attribute. |
500 // This won't work for all object/embed tags, but the context menu API
doesn't | 503 // 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. | 504 // work on those, so we're OK for now. |
502 var elts = document.querySelectorAll('[src]'); | 505 var elts = document.querySelectorAll('[src]'); |
503 for(var i=0; i<elts.length; i++) { | 506 for(var i=0; i<elts.length; i++) { |
504 url = elts[i].src; | 507 url = elts[i].src; |
505 if(request.filter === url) { | 508 if(msg.filter === url) { |
506 // This is hopefully our element. In case of multiple elements | 509 // This is hopefully our element. In case of multiple elements |
507 // with the same src, only one will be highlighted. | 510 // with the same src, only one will be highlighted. |
508 target = elts[i]; | 511 target = elts[i]; |
509 break; | 512 break; |
510 } | 513 } |
511 } | 514 } |
512 } | 515 } |
513 // Following test will be true if we found the element with the filter U
RL | 516 // Following test will be true if we found the element with the filter U
RL |
514 if(request.filter === url) | 517 if(msg.filter === url) |
515 { | 518 { |
516 // This request would have come from the chrome.contextMenu handler, s
o we | 519 // 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. | 520 // simulate the user having chosen the element to get rid of via the u
sual means. |
518 clickHide_activated = true; | 521 clickHide_activated = true; |
519 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s
o why set it? | 522 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s
o why set it? |
520 clickHideFilters = [request.filter]; | 523 clickHideFilters = [msg.filter]; |
521 // Coerce red highlighted overlay on top of element to remove. | 524 // 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 | 525 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta
fix it sometime |
523 currentElement = addElementOverlay(target); | 526 currentElement = addElementOverlay(target); |
524 // clickHide_mouseOver(lastRightClickEvent); | 527 // clickHide_mouseOver(lastRightClickEvent); |
525 clickHide_mouseClick(lastRightClickEvent); | 528 clickHide_mouseClick(lastRightClickEvent); |
526 } | 529 } |
527 else | 530 else |
528 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha
t element.", request.filter, url, lastRightClickEvent.target.src); | 531 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha
t element.", request.filter, url, lastRightClickEvent.target.src); |
529 break; | 532 break; |
530 case "clickhide-init": | 533 case "clickhide-init": |
531 if (clickHideFiltersDialog) | 534 if (clickHideFiltersDialog) |
532 { | 535 { |
533 sendResponse({filters: clickHide_filters}); | 536 sendResponse({filters: clickHide_filters}); |
534 | 537 |
535 clickHideFiltersDialog.style.width = (request.width + 5) + "px"; | 538 clickHideFiltersDialog.style.width = (msg.width + 5) + "px"; |
536 clickHideFiltersDialog.style.height = (request.height + 5) + "px"; | 539 clickHideFiltersDialog.style.height = (msg.height + 5) + "px"; |
537 clickHideFiltersDialog.style.visibility = "visible"; | 540 clickHideFiltersDialog.style.visibility = "visible"; |
538 } | 541 } |
539 break; | 542 break; |
540 case "clickhide-move": | 543 case "clickhide-move": |
541 if (clickHideFiltersDialog) | 544 if (clickHideFiltersDialog) |
542 { | 545 { |
543 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s
tyle.left, 10) + request.x) + "px"; | 546 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"; | 547 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st
yle.top, 10) + request.y) + "px"; |
545 } | 548 } |
546 break; | 549 break; |
547 case "clickhide-close": | 550 case "clickhide-close": |
548 if (clickHideFiltersDialog) | 551 if (clickHideFiltersDialog) |
549 { | 552 { |
550 // Explicitly get rid of currentElement | 553 // Explicitly get rid of currentElement |
551 if (request.remove && currentElement && currentElement.parentNode) | 554 if (msg.remove && currentElement && currentElement.parentNode) |
552 currentElement.parentNode.removeChild(currentElement); | 555 currentElement.parentNode.removeChild(currentElement); |
553 | 556 |
554 clickHide_deactivate(); | 557 clickHide_deactivate(); |
555 } | 558 } |
556 break; | 559 break; |
557 default: | 560 default: |
558 sendResponse({}); | 561 sendResponse({}); |
559 break; | 562 break; |
560 } | 563 } |
561 }); | 564 }); |
562 } | 565 } |
OLD | NEW |