Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: include.postload.js

Issue 4840054052618240: Issue 1428 - Disable "Block Element" on non-HTML pages (Closed)
Left Patch Set: Created Sept. 25, 2014, 4:15 p.m.
Right Patch Set: Removed outdated comment Created Sept. 26, 2014, 10:21 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | popup.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 var selector = elementClasses.map(function(elClass) 384 var selector = elementClasses.map(function(elClass)
385 { 385 {
386 return "." + elClass.replace(/([^\w-])/, "\\$1"); 386 return "." + elClass.replace(/([^\w-])/, "\\$1");
387 }).join(""); 387 }).join("");
388 388
389 clickHideFilters.push(document.domain + "##" + selector); 389 clickHideFilters.push(document.domain + "##" + selector);
390 selectorList.push(selector); 390 selectorList.push(selector);
391 } 391 }
392 if (url) 392 if (url)
393 { 393 {
394 clickHideFilters.push(url.replace(/.*?:\/\//, '||')); 394 clickHideFilters.push(relativeToAbsoluteUrl(url));
395 selectorList.push(elt.localName + '[src="' + elt.getAttribute("src") + '"]') ; 395 selectorList.push(elt.localName + '[src="' + url + '"]');
396 } 396 }
397 397
398 // Show popup 398 // Show popup
399 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 399 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
400 400
401 // Highlight the unlucky elements 401 // Highlight the unlucky elements
402 // Restore currentElement's box-shadow and bgcolor so that highlightElements w on't save those 402 // Restore currentElement's box-shadow and bgcolor so that highlightElements w on't save those
403 unhighlightElement(currentElement); 403 unhighlightElement(currentElement);
404 // Highlight the elements specified by selector in yellow 404 // Highlight the elements specified by selector in yellow
405 highlightElements(selectorList.join(",")); 405 highlightElements(selectorList.join(","));
(...skipping 16 matching lines...) Expand all
422 // This OBJECT could contain an EMBED we already nuked, in which case there' s no URL 422 // This OBJECT could contain an EMBED we already nuked, in which case there' s no URL
423 if(params[0]) 423 if(params[0])
424 url = params[0].getAttribute("value"); 424 url = params[0].getAttribute("value");
425 else { 425 else {
426 params = elt.querySelectorAll("param[name=\"src\"]"); 426 params = elt.querySelectorAll("param[name=\"src\"]");
427 if(params[0]) 427 if(params[0])
428 url = params[0].getAttribute("value"); 428 url = params[0].getAttribute("value");
429 } 429 }
430 430
431 if (url) 431 if (url)
432 url = resolveURL(url); 432 url = normalizeURL(url);
433 } else if(!url) { 433 } else if(!url) {
434 url = elt.src || elt.href; 434 url = elt.src || elt.href;
435 } 435 }
436 return url; 436 return url;
437 } 437 }
438 438
439 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js 439 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js
440 // and licensed under the MIT license. See jquery-*.min.js for details. 440 // and licensed under the MIT license. See jquery-*.min.js for details.
441 function removeDotSegments(u) { 441 function removeDotSegments(u) {
442 var r = '', m = []; 442 var r = '', m = [];
(...skipping 15 matching lines...) Expand all
458 u = m[2]; 458 u = m[2];
459 r = r + m[1]; 459 r = r + m[1];
460 } 460 }
461 } 461 }
462 return r; 462 return r;
463 } else { 463 } else {
464 return u; 464 return u;
465 } 465 }
466 } 466 }
467 467
468 // Content scripts are apparently invoked on non-HTML documents, so we have to 468 // Does some degree of URL normalization
469 // check for that before doing stuff. |document instanceof HTMLDocument| check 469 function normalizeURL(url)
470 // will fail on some sites like planet.mozilla.org because WebKit creates 470 {
471 // Document instances for XHTML documents, have to test the root element. 471 var components = url.match(/(.+:\/\/.+?)\/(.*)/);
472 if(!components)
473 return url;
474 var newPath = removeDotSegments(components[2]);
475 if(newPath.length == 0)
476 return components[1];
477 if(newPath[0] != '/')
478 newPath = '/' + newPath;
479 return components[1] + newPath;
480 }
481
472 if (document instanceof HTMLDocument) 482 if (document instanceof HTMLDocument)
Thomas Greiner 2014/09/26 10:03:55 What about the comment above?
Sebastian Noack 2014/09/26 10:23:43 That comment is outdated. I have removed it. In fa
Thomas Greiner 2014/09/26 12:48:55 Thanks. I'll ignore the rest of the changes in the
473 { 483 {
474 // Use a contextmenu handler to save the last element the user right-clicked o n. 484 // Use a contextmenu handler to save the last element the user right-clicked o n.
475 // To make things easier, we actually save the DOM event. 485 // To make things easier, we actually save the DOM event.
476 // We have to do this because the contextMenu API only provides a URL, not the actual 486 // We have to do this because the contextMenu API only provides a URL, not the actual
477 // DOM element. 487 // DOM element.
478 document.addEventListener('contextmenu', function(e) { 488 document.addEventListener('contextmenu', function(e) {
479 lastRightClickEvent = e; 489 lastRightClickEvent = e;
480 }, false); 490 }, false);
481 491
482 document.addEventListener("click", function(event) 492 document.addEventListener("click", function(event)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 break; 638 break;
629 default: 639 default:
630 sendResponse({}); 640 sendResponse({});
631 break; 641 break;
632 } 642 }
633 }); 643 });
634 644
635 if (window == window.top) 645 if (window == window.top)
636 ext.backgroundPage.sendMessage({type: "report-html-page"}); 646 ext.backgroundPage.sendMessage({type: "report-html-page"});
637 } 647 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld