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

Delta Between Two Patch Sets: include.postload.js

Issue 4829486721794048: Issue 700 - Generate filters based on the style attribute as last resort (Closed)
Left Patch Set: Apply fallback only on style and only if at least 2 rules are given Created June 24, 2014, 12:48 p.m.
Right Patch Set: Rebased and escaped backslashes Created Oct. 30, 2014, 4:05 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 // Click-to-hide stuff 18 // Click-to-hide stuff
19 var clickHide_activated = false; 19 var clickHide_activated = false;
20 var clickHide_filters = null; 20 var clickHide_filters = null;
21 var currentElement = null; 21 var currentElement = null;
22 var currentElement_boxShadow = null;
23 var currentElement_backgroundColor;
24 var clickHideFilters = null; 22 var clickHideFilters = null;
25 var highlightedElementsSelector = null; 23 var highlightedElementsSelector = null;
26 var highlightedElementsBoxShadows = null;
27 var highlightedElementsBGColors = null;
28 var clickHideFiltersDialog = null; 24 var clickHideFiltersDialog = null;
29 var lastRightClickEvent = null; 25 var lastRightClickEvent = null;
26
27 function quote(value)
28 {
29 return '"' + value.replace(/(["\\])/g, "\\$1") + '"';
30 }
31
32 function supportsShadowRoot(element)
33 {
34 if (!("createShadowRoot" in element))
35 return false;
36
37 // There are some elements (e.g. <textarea>), which don't
38 // support author created shadow roots and throw an exception.
39 var clone = element.cloneNode(false);
40 try
41 {
42 clone.createShadowRoot();
43 }
44 catch (e)
45 {
46 return false;
47 }
48
49 // There are some elements (e.g. <input>), which support
50 // author created shadow roots, but ignore insertion points.
51 var child = document.createTextNode("");
52 clone.appendChild(child);
53
54 var shadow = document.createElement("shadow");
55 clone.shadowRoot.appendChild(shadow);
56
57 return shadow.getDistributedNodes()[0] == child;
58 }
59
60 function highlightElement(element, shadowColor, backgroundColor)
61 {
62 unhighlightElement(element);
63
64 var originalBoxShadowPriority = element.style.getPropertyPriority("box-shadow" );
65 var originalBackgroundColorPriority = element.style.getPropertyPriority("backg round-color");
66
67 var boxShadow = "inset 0px 0px 5px " + shadowColor;
68
69 var highlightWithShadowDOM = function()
70 {
71 var style = document.createElement("style");
72 style.textContent = ":host {" +
73 "box-shadow:" + boxShadow + " !important;" +
74 "background-color:" + backgroundColor + " !important;" +
75 "}";
76
77 var root = element.createShadowRoot();
78 root.appendChild(document.createElement("shadow"));
79 root.appendChild(style);
80
81 element._unhighlight = function()
82 {
83 root.removeChild(style);
84 };
85 };
86
87 var highlightWithStyleAttribute = function()
88 {
89 var originalBoxShadow = element.style.getPropertyValue("box-shadow");
90 var originalBackgroundColor = element.style.getPropertyValue("background-col or");
91
92 element.style.setProperty("box-shadow", boxShadow, "important");
93 element.style.setProperty("background-color", backgroundColor, "important");
94
95 element._unhighlight = function()
96 {
97 this.style.removeProperty("box-shadow");
98 this.style.setProperty(
99 "box-shadow",
100 originalBoxShadow,
101 originalBoxShadowPriority
102 );
103
104 this.style.removeProperty("background-color");
105 this.style.setProperty(
106 "background-color",
107 originalBackgroundColor,
108 originalBackgroundColorPriority
109 );
110 };
111 };
112
113 // Use shadow DOM if posibble to avoid side effects when the
114 // web page updates style while highlighted. However, if the
115 // element has important styles we can't override them with shadow DOM.
116 if (supportsShadowRoot(element) && originalBoxShadowPriority != "importa nt" &&
117 originalBackgroundColorPriority != "importa nt")
118 highlightWithShadowDOM();
119 else
120 highlightWithStyleAttribute();
121 }
122
123
124 function unhighlightElement(element)
125 {
126 if ("_unhighlight" in element)
127 {
128 element._unhighlight();
129 delete element._unhighlight;
130 }
131 }
30 132
31 // Highlight elements according to selector string. This would include 133 // Highlight elements according to selector string. This would include
32 // all elements that would be affected by proposed filters. 134 // all elements that would be affected by proposed filters.
33 function highlightElements(selectorString) { 135 function highlightElements(selectorString) {
34 if(highlightedElementsSelector) 136 unhighlightElements();
35 unhighlightElements();
36 137
37 var highlightedElements = document.querySelectorAll(selectorString); 138 var highlightedElements = document.querySelectorAll(selectorString);
38 highlightedElementsSelector = selectorString; 139 highlightedElementsSelector = selectorString;
39 highlightedElementsBoxShadows = new Array(); 140
40 highlightedElementsBGColors = new Array(); 141 for(var i = 0; i < highlightedElements.length; i++)
41 142 highlightElement(highlightedElements[i], "#fd6738", "#f6e1e5");
42 for(var i = 0; i < highlightedElements.length; i++) {
43 highlightedElementsBoxShadows[i] = highlightedElements[i].style.getPropertyV alue("-webkit-box-shadow");
44 highlightedElementsBGColors[i] = highlightedElements[i].style.backgroundColo r;
45 highlightedElements[i].style.setProperty("-webkit-box-shadow", "inset 0px 0p x 5px #fd6738");
46 highlightedElements[i].style.backgroundColor = "#f6e1e5";
47 }
48 } 143 }
49 144
50 // Unhighlight all elements, including those that would be affected by 145 // Unhighlight all elements, including those that would be affected by
51 // the proposed filters 146 // the proposed filters
52 function unhighlightElements() { 147 function unhighlightElements() {
53 if(highlightedElementsSelector == null) 148 if (highlightedElementsSelector)
54 return; 149 {
55 var highlightedElements = document.querySelectorAll(highlightedElementsSelecto r); 150 Array.prototype.forEach.call(
56 for(var i = 0; i < highlightedElements.length; i++) { 151 document.querySelectorAll(highlightedElementsSelector),
57 highlightedElements[i].style.setProperty("-webkit-box-shadow", highlightedEl ementsBoxShadows[i]); 152 unhighlightElement
58 highlightedElements[i].style.backgroundColor = highlightedElementsBGColors[i ]; 153 );
59 } 154
60 highlightedElementsSelector = null; 155 highlightedElementsSelector = null;
156 }
61 } 157 }
62 158
63 // Gets the absolute position of an element by walking up the DOM tree, 159 // Gets the absolute position of an element by walking up the DOM tree,
64 // adding up offsets. 160 // adding up offsets.
65 // I hope there's a better way because it just seems absolutely stupid 161 // I hope there's a better way because it just seems absolutely stupid
66 // that the DOM wouldn't have a direct way to get this, given that it 162 // that the DOM wouldn't have a direct way to get this, given that it
67 // has hundreds and hundreds of other methods that do random junk. 163 // has hundreds and hundreds of other methods that do random junk.
68 function getAbsolutePosition(elt) { 164 function getAbsolutePosition(elt) {
69 var l = 0; 165 var l = 0;
70 var t = 0; 166 var t = 0;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 clickHide_deactivate(); 207 clickHide_deactivate();
112 currentElement = savedElement; 208 currentElement = savedElement;
113 } 209 }
114 210
115 clickHide_filters = filters; 211 clickHide_filters = filters;
116 212
117 clickHideFiltersDialog = document.createElement("iframe"); 213 clickHideFiltersDialog = document.createElement("iframe");
118 clickHideFiltersDialog.src = ext.getURL("block.html"); 214 clickHideFiltersDialog.src = ext.getURL("block.html");
119 clickHideFiltersDialog.setAttribute("style", "position: fixed !important; visi bility: hidden; display: block !important; border: 0px !important;"); 215 clickHideFiltersDialog.setAttribute("style", "position: fixed !important; visi bility: hidden; display: block !important; border: 0px !important;");
120 clickHideFiltersDialog.style.WebkitBoxShadow = "5px 5px 20px rgba(0,0,0,0.5)"; 216 clickHideFiltersDialog.style.WebkitBoxShadow = "5px 5px 20px rgba(0,0,0,0.5)";
121 clickHideFiltersDialog.style.zIndex = 99999; 217 clickHideFiltersDialog.style.zIndex = 0x7FFFFFFF;
122 218
123 // Position in upper-left all the time 219 // Position in upper-left all the time
124 clickHideFiltersDialog.style.left = "50px"; 220 clickHideFiltersDialog.style.left = "50px";
125 clickHideFiltersDialog.style.top = "50px"; 221 clickHideFiltersDialog.style.top = "50px";
126 222
127 // Make dialog partly transparent when mouse isn't over it so user has a bette r 223 // Make dialog partly transparent when mouse isn't over it so user has a bette r
128 // view of what's going to be blocked 224 // view of what's going to be blocked
129 clickHideFiltersDialog.onmouseout = function() 225 clickHideFiltersDialog.onmouseout = function()
130 { 226 {
131 if (clickHideFiltersDialog) 227 if (clickHideFiltersDialog)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 { 272 {
177 if (clickHideFiltersDialog) 273 if (clickHideFiltersDialog)
178 { 274 {
179 document.body.removeChild(clickHideFiltersDialog); 275 document.body.removeChild(clickHideFiltersDialog);
180 clickHideFiltersDialog = null; 276 clickHideFiltersDialog = null;
181 } 277 }
182 278
183 if(currentElement) { 279 if(currentElement) {
184 currentElement.removeEventListener("contextmenu", clickHide_elementClickHand ler, false); 280 currentElement.removeEventListener("contextmenu", clickHide_elementClickHand ler, false);
185 unhighlightElements(); 281 unhighlightElements();
186 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxSha dow); 282 unhighlightElement(currentElement);
187 currentElement.style.backgroundColor = currentElement_backgroundColor;
188 currentElement = null; 283 currentElement = null;
189 clickHideFilters = null; 284 clickHideFilters = null;
190 } 285 }
191 unhighlightElements(); 286 unhighlightElements();
192 287
193 clickHide_activated = false; 288 clickHide_activated = false;
194 clickHide_filters = null; 289 clickHide_filters = null;
195 if(!document) 290 if(!document)
196 return; // This can happen inside a nuked iframe...I think 291 return; // This can happen inside a nuked iframe...I think
197 document.removeEventListener("mouseover", clickHide_mouseOver, false); 292 document.removeEventListener("mouseover", clickHide_mouseOver, false);
(...skipping 22 matching lines...) Expand all
220 315
221 var target = e.target; 316 var target = e.target;
222 while (target.parentNode && !(target.id || target.className || target.src || / :.+:/.test(target.getAttribute("style")))) 317 while (target.parentNode && !(target.id || target.className || target.src || / :.+:/.test(target.getAttribute("style"))))
223 target = target.parentNode; 318 target = target.parentNode;
224 if (target == document.documentElement || target == document.body) 319 if (target == document.documentElement || target == document.body)
225 target = null; 320 target = null;
226 321
227 if (target && target instanceof HTMLElement) 322 if (target && target instanceof HTMLElement)
228 { 323 {
229 currentElement = target; 324 currentElement = target;
230 currentElement_boxShadow = target.style.getPropertyValue("-webkit-box-shadow "); 325
231 currentElement_backgroundColor = target.style.backgroundColor; 326 highlightElement(target, "#d6d84b", "#f8fa47");
232 target.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #d6d84b");
233 target.style.backgroundColor = "#f8fa47";
234
235 target.addEventListener("contextmenu", clickHide_elementClickHandler, false) ; 327 target.addEventListener("contextmenu", clickHide_elementClickHandler, false) ;
236 } 328 }
237 } 329 }
238 330
239 // No longer hovering over this element so unhighlight it 331 // No longer hovering over this element so unhighlight it
240 function clickHide_mouseOut(e) 332 function clickHide_mouseOut(e)
241 { 333 {
242 if (!clickHide_activated || !currentElement) 334 if (!clickHide_activated || !currentElement)
243 return; 335 return;
244 336
245 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); 337 unhighlightElement(currentElement);
246 currentElement.style.backgroundColor = currentElement_backgroundColor;
247
248 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, false); 338 currentElement.removeEventListener("contextmenu", clickHide_elementClickHandle r, false);
249 } 339 }
250 340
251 // Selects the currently hovered-over filter or cancels selection 341 // Selects the currently hovered-over filter or cancels selection
252 function clickHide_keyDown(e) 342 function clickHide_keyDown(e)
253 { 343 {
254 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /) 344 if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 13 /*DOM_VK_RETURN* /)
255 clickHide_mouseClick(e); 345 clickHide_mouseClick(e);
256 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/) 346 else if (!e.ctrlKey && !e.altKey && !e.shiftKey && e.keyCode == 27 /*DOM_VK_ES CAPE*/)
257 { 347 {
258 clickHide_deactivate(); 348 ext.backgroundPage.sendMessage(
349 {
350 type: "forward",
351 payload:
352 {
353 type: "clickhide-deactivate"
354 }
355 });
259 e.preventDefault(); 356 e.preventDefault();
260 e.stopPropagation(); 357 e.stopPropagation();
261 } 358 }
262 } 359 }
263 360
264 // When the user clicks, the currentElement is the one we want. 361 // When the user clicks, the currentElement is the one we want.
265 // We should have ABP rules ready for when the 362 // We should have ABP rules ready for when the
266 // popup asks for them. 363 // popup asks for them.
267 function clickHide_mouseClick(e) 364 function clickHide_mouseClick(e)
268 { 365 {
269 if (!currentElement || !clickHide_activated) 366 if (!currentElement || !clickHide_activated)
270 return; 367 return;
271 368
272 var elt = currentElement; 369 var elt = currentElement;
273 var url = null; 370 var url = null;
274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay") 371 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay")
275 { 372 {
276 elt = currentElement.prisoner; 373 elt = currentElement.prisoner;
277 url = currentElement.prisonerURL; 374 url = currentElement.prisonerURL;
278 } 375 }
279 else if (elt.src) 376 else if (elt.src)
280 url = elt.src; 377 url = elt.src;
281
282 // Only normalize when the element contains a URL (issue 328.)
283 // The URL is not always normalized, so do it here
284 if (url)
285 url = normalizeURL(relativeToAbsoluteUrl(url));
286 378
287 // Construct filters. The popup will retrieve these. 379 // Construct filters. The popup will retrieve these.
288 // Only one ID 380 // Only one ID
289 var elementId = elt.id ? elt.id.split(' ').join('') : null; 381 var elementId = elt.id ? elt.id.split(' ').join('') : null;
290 // Can have multiple classes, and there might be extraneous whitespace 382 // Can have multiple classes, and there might be extraneous whitespace
291 var elementClasses = null; 383 var elementClasses = null;
292 if (elt.className) 384 if (elt.className)
293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); 385 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' ');
294 386
295 clickHideFilters = new Array(); 387 clickHideFilters = new Array();
296 selectorList = new Array(); 388 selectorList = new Array();
297 389
298 var addSelector = function(selector) 390 var addSelector = function(selector)
299 { 391 {
300 clickHideFilters.push(document.domain + "##" + selector); 392 clickHideFilters.push(document.domain + "##" + selector);
301 selectorList.push(selector); 393 selectorList.push(selector);
302 }; 394 };
303 395
304 if (elementId) 396 if (elementId)
305 addSelector("#" + elementId); 397 addSelector("#" + elementId);
306 398
307 if (elt.classList.length > 0) 399 if (elementClasses && elementClasses.length > 0)
308 { 400 {
309 var selector = ""; 401 var selector = "";
310 402
311 for (var i = 0; i < elt.classList.length; i++) 403 for (var i = 0; i < elt.classList.length; i++)
Thomas Greiner 2014/11/04 09:53:21 It's certainly not wrong to use elt.classList here
Sebastian Noack 2014/11/04 14:51:07 The patch has already been merged, but I might fil
Thomas Greiner 2014/11/04 15:15:53 That's totally fine with me. Looks like the origin
Sebastian Noack 2014/11/04 15:44:54 For reference, https://issues.adblockplus.org/tick
312 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); 404 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1");
Wladimir Palant 2014/11/03 18:11:33 Somehow I feel that changing Array.map() into a lo
313 405
314 addSelector(selector); 406 addSelector(selector);
315 } 407 }
316 408
317 if (url) 409 if (url)
318 { 410 {
319 clickHideFilters.push(relativeToAbsoluteUrl(url)); 411 clickHideFilters.push(url.replace(/^[\w\-]+:\/+(?:www\.)?/, "||"));
320 selectorList.push(elt.localName + '[src="' + url + '"]'); 412
413 var src = elt.getAttribute("src");
414 if (src)
415 selectorList.push('[src=' + quote(src) + ']');
321 } 416 }
322 417
323 // restore the original style, before generating the fallback filter that 418 // restore the original style, before generating the fallback filter that
324 // will include the style, and to prevent highlightElements from saving those 419 // will include the style, and to prevent highlightElements from saving those
325 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); 420 unhighlightElement(currentElement);
326 currentElement.style.backgroundColor = currentElement_backgroundColor;
327 421
328 // as last resort, create a filter based on inline styles 422 // as last resort, create a filter based on inline styles
329 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) 423 if (clickHideFilters.length == 0)
330 addSelector(elt.localName + '[style="' + elt.getAttribute("style") + '"]'); 424 {
425 var style = elt.getAttribute("style");
426 if (style)
427 addSelector(elt.localName + '[style=' + quote(style) + ']');
428 }
331 429
332 // Show popup 430 // Show popup
333 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 431 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
334 432
335 // Highlight the elements specified by selector in yellow 433 // Highlight the elements specified by selector in yellow
336 highlightElements(selectorList.join(",")); 434 highlightElements(selectorList.join(","));
337 // Now, actually highlight the element the user clicked on in red 435 // Now, actually highlight the element the user clicked on in red
338 currentElement.style.setProperty("-webkit-box-shadow", "inset 0px 0px 5px #fd1 708"); 436 highlightElement(currentElement, "#fd1708", "#f6a1b5");
339 currentElement.style.backgroundColor = "#f6a1b5";
340 437
341 // Make sure the browser doesn't handle this click 438 // Make sure the browser doesn't handle this click
342 e.preventDefault(); 439 e.preventDefault();
343 e.stopPropagation(); 440 e.stopPropagation();
344 } 441 }
345 442
346 // Extracts source URL from an IMG, OBJECT, EMBED, or IFRAME 443 // Extracts source URL from an IMG, OBJECT, EMBED, or IFRAME
347 function getElementURL(elt) { 444 function getElementURL(elt) {
348 // Check children of object nodes for "param" nodes with name="movie" that spe cify a URL 445 // Check children of object nodes for "param" nodes with name="movie" that spe cify a URL
349 // in value attribute 446 // in value attribute
350 var url; 447 var url;
351 if(elt.localName.toUpperCase() == "OBJECT" && !(url = elt.getAttribute("data") )) { 448 if(elt.localName.toUpperCase() == "OBJECT" && !(url = elt.getAttribute("data") )) {
352 // No data attribute, look in PARAM child tags for a URL for the swf file 449 // No data attribute, look in PARAM child tags for a URL for the swf file
353 var params = elt.querySelectorAll("param[name=\"movie\"]"); 450 var params = elt.querySelectorAll("param[name=\"movie\"]");
354 // This OBJECT could contain an EMBED we already nuked, in which case there' s no URL 451 // This OBJECT could contain an EMBED we already nuked, in which case there' s no URL
355 if(params[0]) 452 if(params[0])
356 url = params[0].getAttribute("value"); 453 url = params[0].getAttribute("value");
357 else { 454 else {
358 params = elt.querySelectorAll("param[name=\"src\"]"); 455 params = elt.querySelectorAll("param[name=\"src\"]");
359 if(params[0]) 456 if(params[0])
360 url = params[0].getAttribute("value"); 457 url = params[0].getAttribute("value");
361 } 458 }
459
460 if (url)
461 url = resolveURL(url);
362 } else if(!url) { 462 } else if(!url) {
363 url = elt.getAttribute("src") || elt.getAttribute("href"); 463 url = elt.src || elt.href;
364 } 464 }
365 return url; 465 return url;
366 } 466 }
367 467
368 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js 468 // This function Copyright (c) 2008 Jeni Tennison, from jquery.uri.js
369 // and licensed under the MIT license. See jquery-*.min.js for details. 469 // and licensed under the MIT license. See jquery-*.min.js for details.
370 function removeDotSegments(u) { 470 function removeDotSegments(u) {
371 var r = '', m = []; 471 var r = '', m = [];
372 if (/\./.test(u)) { 472 if (/\./.test(u)) {
373 while (u !== undefined && u !== '') { 473 while (u !== undefined && u !== '') {
(...skipping 13 matching lines...) Expand all
387 u = m[2]; 487 u = m[2];
388 r = r + m[1]; 488 r = r + m[1];
389 } 489 }
390 } 490 }
391 return r; 491 return r;
392 } else { 492 } else {
393 return u; 493 return u;
394 } 494 }
395 } 495 }
396 496
397 // Does some degree of URL normalization 497 if (document instanceof HTMLDocument)
398 function normalizeURL(url)
399 {
400 var components = url.match(/(.+:\/\/.+?)\/(.*)/);
401 if(!components)
402 return url;
403 var newPath = removeDotSegments(components[2]);
404 if(newPath.length == 0)
405 return components[1];
406 if(newPath[0] != '/')
407 newPath = '/' + newPath;
408 return components[1] + newPath;
409 }
410
411 // Content scripts are apparently invoked on non-HTML documents, so we have to
412 // check for that before doing stuff. |document instanceof HTMLDocument| check
413 // will fail on some sites like planet.mozilla.org because WebKit creates
414 // Document instances for XHTML documents, have to test the root element.
415 if (document.documentElement instanceof HTMLElement)
416 { 498 {
417 // Use a contextmenu handler to save the last element the user right-clicked o n. 499 // Use a contextmenu handler to save the last element the user right-clicked o n.
418 // To make things easier, we actually save the DOM event. 500 // To make things easier, we actually save the DOM event.
419 // We have to do this because the contextMenu API only provides a URL, not the actual 501 // We have to do this because the contextMenu API only provides a URL, not the actual
420 // DOM element. 502 // DOM element.
421 document.addEventListener('contextmenu', function(e) { 503 document.addEventListener('contextmenu', function(e) {
422 lastRightClickEvent = e; 504 lastRightClickEvent = e;
423 }, false); 505 }, false);
424 506
425 document.addEventListener("click", function(event) 507 document.addEventListener("click", function(event)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 if(msg.filter === url) 611 if(msg.filter === url)
530 { 612 {
531 // This request would have come from the chrome.contextMenu handler, s o we 613 // This request would have come from the chrome.contextMenu handler, s o we
532 // simulate the user having chosen the element to get rid of via the u sual means. 614 // simulate the user having chosen the element to get rid of via the u sual means.
533 clickHide_activated = true; 615 clickHide_activated = true;
534 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it? 616 // FIXME: clickHideFilters is erased in clickHide_mouseClick anyway, s o why set it?
535 clickHideFilters = [msg.filter]; 617 clickHideFilters = [msg.filter];
536 // Coerce red highlighted overlay on top of element to remove. 618 // Coerce red highlighted overlay on top of element to remove.
537 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime 619 // TODO: Wow, the design of the clickHide stuff is really dumb - gotta fix it sometime
538 currentElement = addElementOverlay(target); 620 currentElement = addElementOverlay(target);
539 currentElement_backgroundColor = target.style.backgroundColor;
540 // clickHide_mouseOver(lastRightClickEvent); 621 // clickHide_mouseOver(lastRightClickEvent);
541 clickHide_mouseClick(lastRightClickEvent); 622 clickHide_mouseClick(lastRightClickEvent);
542 } 623 }
543 else 624 else
544 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", request.filter, url, lastRightClickEvent.target.src); 625 console.log("clickhide-new-filter: URLs don't match. Couldn't find tha t element.", msg.filter, url, lastRightClickEvent.target.src);
545 break; 626 break;
546 case "clickhide-init": 627 case "clickhide-init":
547 if (clickHideFiltersDialog) 628 if (clickHideFiltersDialog)
548 { 629 {
549 sendResponse({filters: clickHide_filters}); 630 sendResponse({filters: clickHide_filters});
550 631
551 clickHideFiltersDialog.style.width = msg.width + "px"; 632 clickHideFiltersDialog.style.width = msg.width + "px";
552 clickHideFiltersDialog.style.height = msg.height + "px"; 633 clickHideFiltersDialog.style.height = msg.height + "px";
553 clickHideFiltersDialog.style.visibility = "visible"; 634 clickHideFiltersDialog.style.visibility = "visible";
554 } 635 }
555 break; 636 break;
556 case "clickhide-move": 637 case "clickhide-move":
557 if (clickHideFiltersDialog) 638 if (clickHideFiltersDialog)
558 { 639 {
559 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + request.x) + "px"; 640 clickHideFiltersDialog.style.left = (parseInt(clickHideFiltersDialog.s tyle.left, 10) + msg.x) + "px";
560 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + request.y) + "px"; 641 clickHideFiltersDialog.style.top = (parseInt(clickHideFiltersDialog.st yle.top, 10) + msg.y) + "px";
561 } 642 }
562 break; 643 break;
563 case "clickhide-close": 644 case "clickhide-close":
564 if (clickHideFiltersDialog) 645 if (clickHideFiltersDialog)
565 { 646 {
566 // Explicitly get rid of currentElement 647 // Explicitly get rid of currentElement
567 if (msg.remove && currentElement && currentElement.parentNode) 648 if (msg.remove && currentElement && currentElement.parentNode)
568 currentElement.parentNode.removeChild(currentElement); 649 currentElement.parentNode.removeChild(currentElement);
569
570 clickHide_deactivate();
571 } 650 }
651 clickHide_deactivate();
572 break; 652 break;
573 default: 653 default:
574 sendResponse({}); 654 sendResponse({});
575 break; 655 break;
576 } 656 }
577 }); 657 });
578 } 658
659 if (window == window.top)
660 ext.backgroundPage.sendMessage({type: "report-html-page"});
661 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld