inliner.js
[app.webkitpdf] / inliner.js
1
2
3
4 (function(){
5     
6     var camelize = function(a,b){
7         return b.toUpperCase();
8     }
9     
10      
11     
12     var fillStyle = function(dom)
13     {
14         if (!dom || dom.nodeType != 1) {
15             console.log("SKIP: " + dom.nodeName);
16             return;
17         }
18         console.log(dom.nodeName);
19         
20         var style = window.getComputedStyle(dom, null);
21         if (style.display == 'none') {
22             dom.parentElement.removeChild(dom);
23             return;
24         }
25         
26         for (var i = dom.childNodes.length -1; i--; i> -1) {
27             fillStyle(dom.childNodes[i]);
28         }
29         return;
30         
31         
32         //var pstyle = false;
33         //if (dom.nodeName != 'BODY') {
34         //    pstyle = window.getComputedStyle(dom.parentElement, null);
35         //}
36          
37         
38         
39         //if (dom.nodeName == 'LI') {            throw 'done';        }
40         
41         
42         for(var i=0;i<style.length;i++){
43             var prop = style[i];
44             var camel = prop.replace(/\-([a-z])/g, camelize);
45             var val = style.getPropertyValue(prop);
46             //returns[camel] = val;
47             
48             // idea... if the parent has the same style.. then do not apply it to the child?
49             //if (pstyle && pstyle[prop] == val) {
50             //    continue;
51             //}
52             console.log(prop + '=' + val);
53             
54             dom.style[camel] = val;
55          
56             
57         }
58         var es = dom.getAttribute('style');
59         console.log(dom.nodeName + '::' + es);
60         dom.setAttribute('style', es);
61         
62         //return returns;
63     }
64     var el = document.querySelector('body');
65     fillStyle(el);
66     
67     var matches = document.getElementsByTagName('style');
68     for(var i =0;i < matches.length;i++) {
69         matches[i].parentElement.removeChild(matches[i]);
70     }
71     var matches = document.getElementsByTagName('link');
72     for(var i =0;i < matches.length;i++) {
73     //    matches[i].parentElement.removeChild(matches[i]);
74     }
75      
76     
77 })();