| OLD | NEW |
| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 228 |
| 229 // We only generate filters based on the "style" attribute, | 229 // We only generate filters based on the "style" attribute, |
| 230 // if this is the only way we can generate a filter, and | 230 // if this is the only way we can generate a filter, and |
| 231 // only if there are at least two CSS properties defined. | 231 // only if there are at least two CSS properties defined. |
| 232 if (/:.+:/.test(element.getAttribute("style"))) | 232 if (/:.+:/.test(element.getAttribute("style"))) |
| 233 return true; | 233 return true; |
| 234 | 234 |
| 235 return false; | 235 return false; |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Gets the absolute position of an element by walking up the DOM tree, | |
| 239 // adding up offsets. | |
| 240 // I hope there's a better way because it just seems absolutely stupid | |
| 241 // that the DOM wouldn't have a direct way to get this, given that it | |
| 242 // has hundreds and hundreds of other methods that do random junk. | |
| 243 function getAbsolutePosition(elt) { | |
| 244 var l = 0; | |
| 245 var t = 0; | |
| 246 for(; elt; elt = elt.offsetParent) { | |
| 247 l += elt.offsetLeft; | |
| 248 t += elt.offsetTop; | |
| 249 } | |
| 250 return [l, t]; | |
| 251 } | |
| 252 | |
| 253 // Adds an overlay to an element, which is probably a Flash object | 238 // Adds an overlay to an element, which is probably a Flash object |
| 254 function addElementOverlay(elt) { | 239 function addElementOverlay(elt) { |
| 255 var zIndex = "auto"; | 240 var zIndex = "auto"; |
| 256 var position = "absolute"; | 241 var position = "absolute"; |
| 257 | 242 |
| 258 for (var e = elt; e; e = e.parentElement) | 243 for (var e = elt; e; e = e.parentElement) |
| 259 { | 244 { |
| 260 var style = getComputedStyle(e); | 245 var style = getComputedStyle(e); |
| 261 | 246 |
| 262 // If the element isn't rendered (since its or one of its ancestor's | 247 // If the element isn't rendered (since its or one of its ancestor's |
| (...skipping 16 matching lines...) Expand all Loading... |
| 279 zIndex = style.zIndex; | 264 zIndex = style.zIndex; |
| 280 else | 265 else |
| 281 zIndex = Math.max(zIndex, style.zIndex); | 266 zIndex = Math.max(zIndex, style.zIndex); |
| 282 } | 267 } |
| 283 } | 268 } |
| 284 | 269 |
| 285 var overlay = document.createElement('div'); | 270 var overlay = document.createElement('div'); |
| 286 overlay.prisoner = elt; | 271 overlay.prisoner = elt; |
| 287 overlay.className = "__adblockplus__overlay"; | 272 overlay.className = "__adblockplus__overlay"; |
| 288 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; overflow:hidde
n; box-sizing:border-box;'); | 273 overlay.setAttribute('style', 'opacity:0.4; display:inline-box; overflow:hidde
n; box-sizing:border-box;'); |
| 289 var pos = getAbsolutePosition(elt); | 274 var rect = elt.getBoundingClientRect(); |
| 290 overlay.style.width = elt.offsetWidth + "px"; | 275 overlay.style.width = rect.width + "px"; |
| 291 overlay.style.height = elt.offsetHeight + "px"; | 276 overlay.style.height = rect.height + "px"; |
| 292 overlay.style.left = pos[0] + "px"; | 277 overlay.style.left = (rect.left + window.scrollX) + "px"; |
| 293 overlay.style.top = pos[1] + "px"; | 278 overlay.style.top = (rect.top + window.scrollY) + "px"; |
| 294 overlay.style.position = position; | 279 overlay.style.position = position; |
| 295 overlay.style.zIndex = zIndex; | 280 overlay.style.zIndex = zIndex; |
| 296 | 281 |
| 297 // elt.parentNode.appendChild(overlay, elt); | 282 // elt.parentNode.appendChild(overlay, elt); |
| 298 document.body.appendChild(overlay); | 283 document.body.appendChild(overlay); |
| 299 return overlay; | 284 return overlay; |
| 300 } | 285 } |
| 301 | 286 |
| 302 // Show dialog asking user whether she wants to add the proposed filters derived | 287 // Show dialog asking user whether she wants to add the proposed filters derived |
| 303 // from selected page element | 288 // from selected page element |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 lastRightClickEventValid = false; | 714 lastRightClickEventValid = false; |
| 730 else | 715 else |
| 731 lastRightClickEvent = null; | 716 lastRightClickEvent = null; |
| 732 break; | 717 break; |
| 733 } | 718 } |
| 734 }); | 719 }); |
| 735 | 720 |
| 736 if (window == window.top) | 721 if (window == window.top) |
| 737 ext.backgroundPage.sendMessage({type: "report-html-page"}); | 722 ext.backgroundPage.sendMessage({type: "report-html-page"}); |
| 738 } | 723 } |
| OLD | NEW |