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

Side by Side Diff: include.preload.js

Issue 8684066: Fixed "Hide placeholders of blocked elements" feature (Closed)
Patch Set: Created Oct. 26, 2012, 2:33 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 | webrequest.js » ('j') | 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 Source Code is subject to the terms of the Mozilla Public License 2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 var SELECTOR_GROUP_SIZE = 20; 7 var SELECTOR_GROUP_SIZE = 20;
8 8
9 var elemhideElt = null; 9 var elemhideElt = null;
10 10
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 setRules(); 42 setRules();
43 } 43 }
44 44
45 function sendRequests() 45 function sendRequests()
46 { 46 {
47 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything 47 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
48 if (!(document.documentElement instanceof HTMLElement)) 48 if (!(document.documentElement instanceof HTMLElement))
49 return; 49 return;
50 50
51 chrome.extension.onMessage.addListener(function(request, sender, sendResponse)
52 {
53 switch (request.reqtype)
54 {
55 case "hide-element":
56 if (request.documentUrl != document.URL)
57 return;
58
59 // We have little way of knowing which element was blocked - see
60 // http://code.google.com/p/chromium/issues/detail?id=97392. Have to
61 // look through all of them and try to find the right one.
62 var remove = [];
63 var elements = (request.type == "IMAGE" ? document.images : document.get ElementsByTagName("iframe"));
64 for (var i = 0, l = elements.length; i < l; i++)
65 if (elements[i].src == request.url)
66 remove.push(elements[i]);
67
68 for (var i = 0, l = remove.length; i < l; i++)
69 if (remove[i].parentNode)
70 remove[i].parentNode.removeChild(remove[i]);
71 }
72 });
73
51 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response) 74 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response)
52 { 75 {
53 setElemhideCSSRules(response.selectors); 76 setElemhideCSSRules(response.selectors);
54 }); 77 });
55 } 78 }
56 79
57 // In Chrome 18 the document might not be initialized yet 80 // In Chrome 18 the document might not be initialized yet
58 if (document.documentElement) 81 if (document.documentElement)
59 sendRequests(); 82 sendRequests();
60 else 83 else
61 window.setTimeout(sendRequests, 0); 84 window.setTimeout(sendRequests, 0);
OLDNEW
« no previous file with comments | « no previous file | webrequest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld