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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 clickHide_mouseClick(ev); | 212 clickHide_mouseClick(ev); |
213 } | 213 } |
214 | 214 |
215 // Hovering over an element so highlight it | 215 // Hovering over an element so highlight it |
216 function clickHide_mouseOver(e) | 216 function clickHide_mouseOver(e) |
217 { | 217 { |
218 if (clickHide_activated == false) | 218 if (clickHide_activated == false) |
219 return; | 219 return; |
220 | 220 |
221 var target = e.target; | 221 var target = e.target; |
222 while (target.parentNode && !(target.id || target.className || target.src)) | 222 while (target.parentNode && !(target.id || target.className || target.src || /
:.+:/.test(target.getAttribute("style")))) |
223 target = target.parentNode; | 223 target = target.parentNode; |
224 if (target == document.documentElement || target == document.body) | 224 if (target == document.documentElement || target == document.body) |
225 target = null; | 225 target = null; |
226 | 226 |
227 if (target && target instanceof HTMLElement) | 227 if (target && target instanceof HTMLElement) |
228 { | 228 { |
229 currentElement = target; | 229 currentElement = target; |
230 currentElement_boxShadow = target.style.getPropertyValue("-webkit-box-shadow
"); | 230 currentElement_boxShadow = target.style.getPropertyValue("-webkit-box-shadow
"); |
231 currentElement_backgroundColor = target.style.backgroundColor; | 231 currentElement_backgroundColor = target.style.backgroundColor; |
232 target.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #d6d84b"); | 232 target.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #d6d84b"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 // Construct filters. The popup will retrieve these. | 287 // Construct filters. The popup will retrieve these. |
288 // Only one ID | 288 // Only one ID |
289 var elementId = elt.id ? elt.id.split(' ').join('') : null; | 289 var elementId = elt.id ? elt.id.split(' ').join('') : null; |
290 // Can have multiple classes, and there might be extraneous whitespace | 290 // Can have multiple classes, and there might be extraneous whitespace |
291 var elementClasses = null; | 291 var elementClasses = null; |
292 if (elt.className) | 292 if (elt.className) |
293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, ''
).split(' '); | 293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, ''
).split(' '); |
294 | 294 |
295 clickHideFilters = new Array(); | 295 clickHideFilters = new Array(); |
296 selectorList = new Array(); | 296 selectorList = new Array(); |
297 if (elementId) | 297 |
| 298 var addSelector = function(selector) |
298 { | 299 { |
299 clickHideFilters.push(document.domain + "###" + elementId); | |
300 selectorList.push("#" + elementId); | |
301 } | |
302 if (elementClasses && elementClasses.length > 0) | |
303 { | |
304 var selector = elementClasses.map(function(elClass) | |
305 { | |
306 return "." + elClass.replace(/([^\w-])/, "\\$1"); | |
307 }).join(""); | |
308 | |
309 clickHideFilters.push(document.domain + "##" + selector); | 300 clickHideFilters.push(document.domain + "##" + selector); |
310 selectorList.push(selector); | 301 selectorList.push(selector); |
| 302 }; |
| 303 |
| 304 if (elementId) |
| 305 addSelector("#" + elementId); |
| 306 |
| 307 if (elt.classList.length > 0) |
| 308 { |
| 309 var selector = ""; |
| 310 |
| 311 for (var i = 0; i < elt.classList.length; i++) |
| 312 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); |
| 313 |
| 314 addSelector(selector); |
311 } | 315 } |
| 316 |
312 if (url) | 317 if (url) |
313 { | 318 { |
314 clickHideFilters.push(relativeToAbsoluteUrl(url)); | 319 clickHideFilters.push(relativeToAbsoluteUrl(url)); |
315 selectorList.push(elt.localName + '[src="' + url + '"]'); | 320 selectorList.push(elt.localName + '[src="' + url + '"]'); |
316 } | 321 } |
317 | 322 |
| 323 // restore the original style, before generating the fallback filter that |
| 324 // will include the style, and to prevent highlightElements from saving those |
| 325 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado
w); |
| 326 currentElement.style.backgroundColor = currentElement_backgroundColor; |
| 327 |
| 328 // as last resort, create a filter based on inline styles |
| 329 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) |
| 330 addSelector(elt.localName + '[style="' + elt.getAttribute("style") + '"]'); |
| 331 |
318 // Show popup | 332 // Show popup |
319 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 333 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
320 | 334 |
321 // Highlight the unlucky elements | |
322 // Restore currentElement's box-shadow and bgcolor so that highlightElements w
on't save those | |
323 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado
w); | |
324 currentElement.style.backgroundColor = currentElement_backgroundColor; | |
325 // Highlight the elements specified by selector in yellow | 335 // Highlight the elements specified by selector in yellow |
326 highlightElements(selectorList.join(",")); | 336 highlightElements(selectorList.join(",")); |
327 // Now, actually highlight the element the user clicked on in red | 337 // Now, actually highlight the element the user clicked on in red |
328 currentElement.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #fd1
708"); | 338 currentElement.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #fd1
708"); |
329 currentElement.style.backgroundColor = "#f6a1b5"; | 339 currentElement.style.backgroundColor = "#f6a1b5"; |
330 | 340 |
331 // Make sure the browser doesn't handle this click | 341 // Make sure the browser doesn't handle this click |
332 e.preventDefault(); | 342 e.preventDefault(); |
333 e.stopPropagation(); | 343 e.stopPropagation(); |
334 } | 344 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 569 |
560 clickHide_deactivate(); | 570 clickHide_deactivate(); |
561 } | 571 } |
562 break; | 572 break; |
563 default: | 573 default: |
564 sendResponse({}); | 574 sendResponse({}); |
565 break; | 575 break; |
566 } | 576 } |
567 }); | 577 }); |
568 } | 578 } |
OLD | NEW |