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-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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 clickHide_mouseClick(ev); | 302 clickHide_mouseClick(ev); |
303 } | 303 } |
304 | 304 |
305 // Hovering over an element so highlight it | 305 // Hovering over an element so highlight it |
306 function clickHide_mouseOver(e) | 306 function clickHide_mouseOver(e) |
307 { | 307 { |
308 if (clickHide_activated == false) | 308 if (clickHide_activated == false) |
309 return; | 309 return; |
310 | 310 |
311 var target = e.target; | 311 var target = e.target; |
312 while (target.parentNode && !(target.id || target.className || target.src)) | 312 while (target.parentNode && !(target.id || target.className || target.src || /
:.+:/.test(target.getAttribute("style")))) |
313 target = target.parentNode; | 313 target = target.parentNode; |
314 if (target == document.documentElement || target == document.body) | 314 if (target == document.documentElement || target == document.body) |
315 target = null; | 315 target = null; |
316 | 316 |
317 if (target && target instanceof HTMLElement) | 317 if (target && target instanceof HTMLElement) |
318 { | 318 { |
319 currentElement = target; | 319 currentElement = target; |
320 | 320 |
321 highlightElement(target, "#d6d84b", "#f8fa47"); | 321 highlightElement(target, "#d6d84b", "#f8fa47"); |
322 target.addEventListener("contextmenu", clickHide_elementClickHandler, false)
; | 322 target.addEventListener("contextmenu", clickHide_elementClickHandler, false)
; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Construct filters. The popup will retrieve these. | 367 // Construct filters. The popup will retrieve these. |
368 // Only one ID | 368 // Only one ID |
369 var elementId = elt.id ? elt.id.split(' ').join('') : null; | 369 var elementId = elt.id ? elt.id.split(' ').join('') : null; |
370 // Can have multiple classes, and there might be extraneous whitespace | 370 // Can have multiple classes, and there might be extraneous whitespace |
371 var elementClasses = null; | 371 var elementClasses = null; |
372 if (elt.className) | 372 if (elt.className) |
373 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, ''
).split(' '); | 373 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, ''
).split(' '); |
374 | 374 |
375 clickHideFilters = new Array(); | 375 clickHideFilters = new Array(); |
376 selectorList = new Array(); | 376 selectorList = new Array(); |
| 377 |
| 378 var addSelector = function(selector) |
| 379 { |
| 380 clickHideFilters.push(document.domain + "##" + selector); |
| 381 selectorList.push(selector); |
| 382 }; |
| 383 |
377 if (elementId) | 384 if (elementId) |
378 { | 385 addSelector("#" + elementId); |
379 clickHideFilters.push(document.domain + "###" + elementId); | 386 |
380 selectorList.push("#" + elementId); | |
381 } | |
382 if (elementClasses && elementClasses.length > 0) | 387 if (elementClasses && elementClasses.length > 0) |
383 { | 388 { |
384 var selector = elementClasses.map(function(elClass) | 389 var selector = ""; |
385 { | |
386 return "." + elClass.replace(/([^\w-])/, "\\$1"); | |
387 }).join(""); | |
388 | 390 |
389 clickHideFilters.push(document.domain + "##" + selector); | 391 for (var i = 0; i < elt.classList.length; i++) |
390 selectorList.push(selector); | 392 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); |
| 393 |
| 394 addSelector(selector); |
391 } | 395 } |
| 396 |
392 if (url) | 397 if (url) |
393 { | 398 { |
394 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); | 399 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||")); |
395 selectorList.push('[src="' + elt.getAttribute("src") + '"]'); | 400 selectorList.push('[src="' + elt.getAttribute("src") + '"]'); |
396 } | 401 } |
397 | 402 |
398 // Show popup | 403 // Show popup |
399 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 404 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
400 | 405 |
401 // Highlight the unlucky elements | 406 // restore the original style, before generating the fallback filter that |
402 // Restore currentElement's box-shadow and bgcolor so that highlightElements w
on't save those | 407 // will include the style, and to prevent highlightElements from saving those |
403 unhighlightElement(currentElement); | 408 unhighlightElement(currentElement); |
| 409 |
| 410 // as last resort, create a filter based on inline styles |
| 411 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) |
| 412 addSelector(elt.localName + '[style="' + elt.getAttribute("style").replace(/
"/g, '\\"') + '"]'); |
| 413 |
404 // Highlight the elements specified by selector in yellow | 414 // Highlight the elements specified by selector in yellow |
405 highlightElements(selectorList.join(",")); | 415 highlightElements(selectorList.join(",")); |
406 // Now, actually highlight the element the user clicked on in red | 416 // Now, actually highlight the element the user clicked on in red |
407 highlightElement(currentElement, "#fd1708", "#f6a1b5"); | 417 highlightElement(currentElement, "#fd1708", "#f6a1b5"); |
408 | 418 |
409 // Make sure the browser doesn't handle this click | 419 // Make sure the browser doesn't handle this click |
410 e.preventDefault(); | 420 e.preventDefault(); |
411 e.stopPropagation(); | 421 e.stopPropagation(); |
412 } | 422 } |
413 | 423 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 break; | 634 break; |
625 default: | 635 default: |
626 sendResponse({}); | 636 sendResponse({}); |
627 break; | 637 break; |
628 } | 638 } |
629 }); | 639 }); |
630 | 640 |
631 if (window == window.top) | 641 if (window == window.top) |
632 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 642 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
633 } | 643 } |
OLD | NEW |