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