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

Side by Side Diff: include.postload.js

Issue 5225119261655040: Issue 1282 - Don't generate filters conflicting with existing exception rules (Closed)
Patch Set: Rebased Created Jan. 25, 2015, 1:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « background.js ('k') | include.preload.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 186
187 case "video": 187 case "video":
188 case "audio": 188 case "audio":
189 case "picture": 189 case "picture":
190 return getURLsFromMediaElement(element); 190 return getURLsFromMediaElement(element);
191 } 191 }
192 192
193 return getURLsFromAttributes(element); 193 return getURLsFromAttributes(element);
194 } 194 }
195 195
196 function isBlockable(element)
197 {
198 if (element.id)
199 return true;
200 if (element.classList.length > 0)
201 return true;
202 if (getURLsFromElement(element).length > 0)
203 return true;
204
205 // We only generate filters based on the "style" attribute,
206 // if this is the only way we can generate a filter, and
207 // only if there are at least two CSS properties defined.
208 if (/:.+:/.test(element.getAttribute("style")))
209 return true;
210
211 return false;
212 }
213
214 // Gets the absolute position of an element by walking up the DOM tree, 196 // Gets the absolute position of an element by walking up the DOM tree,
215 // adding up offsets. 197 // adding up offsets.
216 // I hope there's a better way because it just seems absolutely stupid 198 // I hope there's a better way because it just seems absolutely stupid
217 // that the DOM wouldn't have a direct way to get this, given that it 199 // that the DOM wouldn't have a direct way to get this, given that it
218 // has hundreds and hundreds of other methods that do random junk. 200 // has hundreds and hundreds of other methods that do random junk.
219 function getAbsolutePosition(elt) { 201 function getAbsolutePosition(elt) {
220 var l = 0; 202 var l = 0;
221 var t = 0; 203 var t = 0;
222 for(; elt; elt = elt.offsetParent) { 204 for(; elt; elt = elt.offsetParent) {
223 l += elt.offsetLeft; 205 l += elt.offsetLeft;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 // Turn on the choose element to create filter thing 296 // Turn on the choose element to create filter thing
315 function clickHide_activate() { 297 function clickHide_activate() {
316 if(document == null) 298 if(document == null)
317 return; 299 return;
318 300
319 // If we are already selecting, abort now 301 // If we are already selecting, abort now
320 if (clickHide_activated || clickHideFiltersDialog) 302 if (clickHide_activated || clickHideFiltersDialog)
321 clickHide_deactivate(); 303 clickHide_deactivate();
322 304
323 // Add overlays for blockable elements that don't emit mouse events that they can still be selected 305 // Add overlays for blockable elements that don't emit mouse events that they can still be selected
324 var elts = document.querySelectorAll('object,embed,iframe'); 306 [].forEach.call(
325 for(var i=0; i<elts.length; i++) 307 document.querySelectorAll('object,embed,iframe'),
326 { 308 function(element)
327 var element = elts[i]; 309 {
328 if (isBlockable(element)) 310 getFiltersForElement(element, function(filters)
329 addElementOverlay(element); 311 {
330 } 312 if (filters.length > 0)
313 addElementOverlay(element);
314 });
315 }
316 );
331 317
332 clickHide_activated = true; 318 clickHide_activated = true;
333 document.addEventListener("mouseover", clickHide_mouseOver, true); 319 document.addEventListener("mouseover", clickHide_mouseOver, true);
334 document.addEventListener("mouseout", clickHide_mouseOut, true); 320 document.addEventListener("mouseout", clickHide_mouseOut, true);
335 document.addEventListener("click", clickHide_mouseClick, true); 321 document.addEventListener("click", clickHide_mouseClick, true);
336 document.addEventListener("keydown", clickHide_keyDown, true); 322 document.addEventListener("keydown", clickHide_keyDown, true);
337 } 323 }
338 324
339 // Called when user has clicked on something and we are waiting for confirmation 325 // Called when user has clicked on something and we are waiting for confirmation
340 // on whether the user actually wants these filters 326 // on whether the user actually wants these filters
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 overlays[0].parentNode.removeChild(overlays[0]); 367 overlays[0].parentNode.removeChild(overlays[0]);
382 } 368 }
383 } 369 }
384 370
385 function clickHide_elementClickHandler(ev) { 371 function clickHide_elementClickHandler(ev) {
386 ev.preventDefault(); 372 ev.preventDefault();
387 ev.stopPropagation(); 373 ev.stopPropagation();
388 clickHide_mouseClick(ev); 374 clickHide_mouseClick(ev);
389 } 375 }
390 376
377 function getBlockableElementOrAncestor(element, callback)
378 {
379 if (element && element != document.documentElement &&
380 element != document.body)
381 {
382 if (element instanceof HTMLElement)
383 {
384 getFiltersForElement(element, function(filters)
385 {
386 if (filters.length > 0)
387 callback(element);
388 else
389 getBlockableElementOrAncestor(element.parentElement, callback);
390 });
391 }
392 else
393 {
394 getBlockableElementOrAncestor(element.parentElement, callback);
395 }
396 }
397 else
398 {
399 callback(null);
400 }
401 }
402
391 // Hovering over an element so highlight it 403 // Hovering over an element so highlight it
392 function clickHide_mouseOver(e) 404 function clickHide_mouseOver(e)
393 { 405 {
394 if (clickHide_activated == false) 406 if (clickHide_activated == false)
395 return; 407 return;
396 408
397 var target = e.target; 409 getBlockableElementOrAncestor(e.target, function(element)
398 while (target.parentNode && !isBlockable(target)) 410 {
399 target = target.parentNode; 411 if (currentElement)
400 if (target == document.documentElement || target == document.body) 412 unhighlightElement(currentElement);
401 target = null;
402 413
403 if (target && target instanceof HTMLElement) 414 if (element)
404 { 415 {
405 currentElement = target; 416 highlightElement(element, "#d6d84b", "#f8fa47");
417 element.addEventListener("contextmenu", clickHide_elementClickHandler, tru e);
418 }
406 419
407 highlightElement(target, "#d6d84b", "#f8fa47"); 420 currentElement = element;
408 target.addEventListener("contextmenu", clickHide_elementClickHandler, true); 421 });
409 }
410 } 422 }
411 423
412 // No longer hovering over this element so unhighlight it 424 // No longer hovering over this element so unhighlight it
413 function clickHide_mouseOut(e) 425 function clickHide_mouseOut(e)
414 { 426 {
415 if (!clickHide_activated || !currentElement) 427 if (!clickHide_activated || currentElement != e.target)
416 return; 428 return;
417 429
418 unhighlightElement(currentElement); 430 unhighlightElement(currentElement);
419 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, true); 431 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, true);
420 } 432 }
421 433
422 // Selects the currently hovered-over filter or cancels selection 434 // Selects the currently hovered-over filter or cancels selection
423 function clickHide_keyDown(e) 435 function clickHide_keyDown(e)
424 { 436 {
425 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /) 437 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /)
(...skipping 17 matching lines...) Expand all
443 { 455 {
444 ext.backgroundPage.sendMessage( 456 ext.backgroundPage.sendMessage(
445 { 457 {
446 type: "compose-filters", 458 type: "compose-filters",
447 tagName: element.localName, 459 tagName: element.localName,
448 id: element.id, 460 id: element.id,
449 src: element.getAttribute("src"), 461 src: element.getAttribute("src"),
450 style: element.getAttribute("style"), 462 style: element.getAttribute("style"),
451 classes: [].slice.call(element.classList), 463 classes: [].slice.call(element.classList),
452 urls: getURLsFromElement(element), 464 urls: getURLsFromElement(element),
465 mediatype: typeMap[element.localName],
453 baseURL: document.location.href 466 baseURL: document.location.href
454 }, 467 },
455 function(response) 468 function(response)
456 { 469 {
457 callback(response.filters, response.selectors); 470 callback(response.filters, response.selectors);
458 } 471 }
459 ); 472 );
460 } 473 }
461 474
462 // When the user clicks, the currentElement is the one we want. 475 // When the user clicks, the currentElement is the one we want.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 lastRightClickEventValid = false; 684 lastRightClickEventValid = false;
672 else 685 else
673 lastRightClickEvent = null; 686 lastRightClickEvent = null;
674 break; 687 break;
675 } 688 }
676 }); 689 });
677 690
678 if (window == window.top) 691 if (window == window.top)
679 ext.backgroundPage.sendMessage({type: "report-html-page"}); 692 ext.backgroundPage.sendMessage({type: "report-html-page"});
680 } 693 }
OLDNEW
« no previous file with comments | « background.js ('k') | include.preload.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld