LEFT | RIGHT |
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 449 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 » » ext.backgroundPage.sendMessage({ | 470 ext.backgroundPage.sendMessage({ |
471 » » » type: "add-subscription", | 471 type: "add-subscription", |
472 » » » title: title, | 472 title: title, |
473 » » » url: url | 473 url: url |
474 » » }); | 474 }); |
475 }, true); | 475 }, true); |
476 | 476 |
477 ext.onMessage.addListener(function(msg, sender, sendResponse) { | 477 ext.onMessage.addListener(function(msg, sender, sendResponse) |
| 478 { |
478 switch (msg.type) | 479 switch (msg.type) |
479 { | 480 { |
480 case "get-clickhide-state": | 481 case "get-clickhide-state": |
481 sendResponse({active: clickHide_activated}); | 482 sendResponse({active: clickHide_activated}); |
482 break; | 483 break; |
483 case "clickhide-activate": | 484 case "clickhide-activate": |
484 clickHide_activate(); | 485 clickHide_activate(); |
485 break; | 486 break; |
486 case "clickhide-deactivate": | 487 case "clickhide-deactivate": |
487 clickHide_deactivate(); | 488 clickHide_deactivate(); |
488 break; | 489 break; |
489 case "clickhide-new-filter": | 490 case "clickhide-new-filter": |
490 // 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 |
491 // user right-clicked in | 492 // user right-clicked in |
492 if(!lastRightClickEvent) | 493 if(!lastRightClickEvent) |
493 return; | 494 return; |
494 // 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 |
495 // by lastRightClickEvent.target. If not, we just discard | 496 // by lastRightClickEvent.target. If not, we just discard |
496 var target = lastRightClickEvent.target; | 497 var target = lastRightClickEvent.target; |
497 var url = target.src; | 498 var url = target.src; |
498 // 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. |
499 // 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 |
500 // to start with? | 501 // to start with? |
501 if(msg.filter !== url) { | 502 if(msg.filter !== url) |
| 503 { |
502 // Grab all elements with a src attribute. | 504 // Grab all elements with a src attribute. |
503 // 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 |
504 // work on those, so we're OK for now. | 506 // work on those, so we're OK for now. |
505 var elts = document.querySelectorAll('[src]'); | 507 var elts = document.querySelectorAll('[src]'); |
506 for(var i=0; i<elts.length; i++) { | 508 for(var i=0; i<elts.length; i++) { |
507 url = elts[i].src; | 509 url = elts[i].src; |
508 if(msg.filter === url) { | 510 if(msg.filter === url) |
| 511 { |
509 // This is hopefully our element. In case of multiple elements | 512 // This is hopefully our element. In case of multiple elements |
510 // with the same src, only one will be highlighted. | 513 // with the same src, only one will be highlighted. |
511 target = elts[i]; | 514 target = elts[i]; |
512 break; | 515 break; |
513 } | 516 } |
514 } | 517 } |
515 } | 518 } |
516 // 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 |
517 if(msg.filter === url) | 520 if(msg.filter === url) |
518 { | 521 { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 | 559 |
557 clickHide_deactivate(); | 560 clickHide_deactivate(); |
558 } | 561 } |
559 break; | 562 break; |
560 default: | 563 default: |
561 sendResponse({}); | 564 sendResponse({}); |
562 break; | 565 break; |
563 } | 566 } |
564 }); | 567 }); |
565 } | 568 } |
LEFT | RIGHT |