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