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         var cn = [];
26         
27         if (dom.childNodes.length > 50) {
28             console.log(dom);
29             throw "too many child nodes?");
30         }
31         for (var i = 0;i < dom.childNodes.length;i++) {
32             cn.push(dom.childNodes[i]);
33         }
34         
35         
36         for (var i = 0;i < cn.length;i++) {
37             console.log( i + ':'+ cn[i].nodeName);
38             cn.push(cn[i]);
39         }    
40         
41         return;
42         
43         
44         //var pstyle = false;
45         //if (dom.nodeName != 'BODY') {
46         //    pstyle = window.getComputedStyle(dom.parentElement, null);
47         //}
48          
49         
50         
51         //if (dom.nodeName == 'LI') {            throw 'done';        }
52         
53         
54         for(var i=0;i<style.length;i++){
55             var prop = style[i];
56             var camel = prop.replace(/\-([a-z])/g, camelize);
57             var val = style.getPropertyValue(prop);
58             //returns[camel] = val;
59             
60             // idea... if the parent has the same style.. then do not apply it to the child?
61             //if (pstyle && pstyle[prop] == val) {
62             //    continue;
63             //}
64             console.log(prop + '=' + val);
65             
66             dom.style[camel] = val;
67          
68             
69         }
70         var es = dom.getAttribute('style');
71         console.log(dom.nodeName + '::' + es);
72         dom.setAttribute('style', es);
73         
74         //return returns;
75     }
76     
77     function changeit() {
78         
79         
80         var el = document.querySelector('body');
81         fillStyle(el);
82         
83         var matches = document.getElementsByTagName('style');
84         for(var i =0;i < matches.length;i++) {
85             matches[i].parentElement.removeChild(matches[i]);
86         }
87         var matches = document.getElementsByTagName('link');
88         for(var i =0;i < matches.length;i++) {
89         //    matches[i].parentElement.removeChild(matches[i]);
90         }
91     }
92     changeit();
93     
94 })();