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

Side by Side Diff: include.postload.js

Issue 5945877571043328: Issue 705 - Generate element hiding instead request blocking filters for non-HTTP URLs (Closed)
Patch Set: Created June 24, 2014, 2:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 var elt = currentElement; 272 var elt = currentElement;
273 var url = null; 273 var url = null;
274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay") 274 if (currentElement.className && currentElement.className == "__adblockplus__ov erlay")
275 { 275 {
276 elt = currentElement.prisoner; 276 elt = currentElement.prisoner;
277 url = currentElement.prisonerURL; 277 url = currentElement.prisonerURL;
278 } 278 }
279 else if (elt.src) 279 else if (elt.src)
280 url = elt.src; 280 url = elt.src;
281 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
287 // Construct filters. The popup will retrieve these. 282 // Construct filters. The popup will retrieve these.
288 // Only one ID 283 // Only one ID
289 var elementId = elt.id ? elt.id.split(' ').join('') : null; 284 var elementId = elt.id ? elt.id.split(' ').join('') : null;
290 // Can have multiple classes, and there might be extraneous whitespace 285 // Can have multiple classes, and there might be extraneous whitespace
291 var elementClasses = null; 286 var elementClasses = null;
292 if (elt.className) 287 if (elt.className)
293 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' '); 288 elementClasses = elt.className.replace(/\s+/g, ' ').replace(/^\s+|\s+$/g, '' ).split(' ');
294 289
295 clickHideFilters = new Array(); 290 clickHideFilters = new Array();
296 selectorList = new Array(); 291 selectorList = new Array();
297 292
298 var addSelector = function(selector) 293 var addSelector = function(selector)
299 { 294 {
300 clickHideFilters.push(document.domain + "##" + selector); 295 clickHideFilters.push(document.domain + "##" + selector);
301 selectorList.push(selector); 296 selectorList.push(selector);
302 }; 297 };
303 298
299 var addSelectorFromAttribute = function(element, attribute)
300 {
301 var value = element.getAttribute(attribute);
302 if (value)
303 addSelector(element.localName + "[" + attribute + '="' + value.replace(/"/ g, '\\"') + '"]');
304 };
305
304 if (elementId) 306 if (elementId)
305 addSelector("#" + elementId); 307 addSelector("#" + elementId);
306 308
307 if (elt.classList.length > 0) 309 if (elt.classList.length > 0)
308 { 310 {
309 var selector = ""; 311 var selector = "";
310 312
311 for (var i = 0; i < elt.classList.length; i++) 313 for (var i = 0; i < elt.classList.length; i++)
312 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1"); 314 selector += "." + elt.classList[i].replace(/([^\w-])/, "\\$1");
313 315
314 addSelector(selector); 316 addSelector(selector);
315 } 317 }
316 318
317 if (url) 319 if (url)
318 { 320 {
319 clickHideFilters.push(url); 321 url = relativeToAbsoluteUrl(url);
320 selectorList.push(elt.localName + '[src="' + url + '"]'); 322 if (/^https?:/.test(url))
323 {
324 clickHideFilters.push(normalizeURL(url));
325 selectorList.push(elt.localName + '[src="' + url + '"]');
326 }
327 else
328 addSelectorFromAttribute(elt, "src");
321 } 329 }
322 330
323 // restore the original style, before generating the fallback filter that 331 // restore the original style, before generating the fallback filter that
324 // will include the style, and to prevent highlightElements from saving those 332 // will include the style, and to prevent highlightElements from saving those
325 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w); 333 currentElement.style.setProperty("-webkit-box-shadow", currentElement_boxShado w);
326 currentElement.style.backgroundColor = currentElement_backgroundColor; 334 currentElement.style.backgroundColor = currentElement_backgroundColor;
327 335
328 // as last resort, create a filter based on inline styles 336 // as last resort, create a filter based on inline styles
329 if (clickHideFilters.length == 0 && elt.hasAttribute("style")) 337 if (clickHideFilters.length == 0)
330 addSelector(elt.localName + '[style="' + elt.getAttribute("style") + '"]'); 338 addSelectorFromAttribute(elt, "style");
331 339
332 // Show popup 340 // Show popup
333 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters); 341 clickHide_showDialog(e.clientX, e.clientY, clickHideFilters);
334 342
335 // Highlight the elements specified by selector in yellow 343 // Highlight the elements specified by selector in yellow
336 highlightElements(selectorList.join(",")); 344 highlightElements(selectorList.join(","));
337 // Now, actually highlight the element the user clicked on in red 345 // Now, actually highlight the element the user clicked on in red
338 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");
339 currentElement.style.backgroundColor = "#f6a1b5"; 347 currentElement.style.backgroundColor = "#f6a1b5";
340 348
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 575
568 clickHide_deactivate(); 576 clickHide_deactivate();
569 } 577 }
570 break; 578 break;
571 default: 579 default:
572 sendResponse({}); 580 sendResponse({});
573 break; 581 break;
574 } 582 }
575 }); 583 });
576 } 584 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld