| 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.attributes.length == 0) |
| 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 tag's name |
| 329 // and all of its attributes, if everything else fails |
| 330 if (clickHideFilters.length == 0) |
| 331 { |
| 332 var selector = elt.localName; |
| 333 |
| 334 for (var i = 0; i < elt.attributes.length; i++) |
| 335 selector += "[" + elt.attributes[i].name + '="' + elt.attributes[i].value.
replace('"', '\\"') + '"]'; |
| 336 |
| 337 addSelector(selector); |
| 338 } |
| 339 |
| 318 // Show popup | 340 // Show popup |
| 319 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); | 341 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); |
| 320 | 342 |
| 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 | 343 // Highlight the elements specified by selector in yellow |
| 326 highlightElements(selectorList.join(",")); | 344 highlightElements(selectorList.join(",")); |
| 327 // Now, actually highlight the element the user clicked on in red | 345 // Now, actually highlight the element the user clicked on in red |
| 328 currentElement.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #fd1
708"); | 346 currentElement.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #fd1
708"); |
| 329 currentElement.style.backgroundColor = "#f6a1b5"; | 347 currentElement.style.backgroundColor = "#f6a1b5"; |
| 330 | 348 |
| 331 // Make sure the browser doesn't handle this click | 349 // Make sure the browser doesn't handle this click |
| 332 e.preventDefault(); | 350 e.preventDefault(); |
| 333 e.stopPropagation(); | 351 e.stopPropagation(); |
| 334 } | 352 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 559 | 577 |
| 560 clickHide_deactivate(); | 578 clickHide_deactivate(); |
| 561 } | 579 } |
| 562 break; | 580 break; |
| 563 default: | 581 default: |
| 564 sendResponse({}); | 582 sendResponse({}); |
| 565 break; | 583 break; |
| 566 } | 584 } |
| 567 }); | 585 }); |
| 568 } | 586 } |
| OLD | NEW |