MOVED domains/cubic.com.js to domains/remove_print_css.js
[app.webkitpdf] / domains / remove_print_css.js
1
2 (function (args) {
3      
4     
5     for (var ss = 0; ss < document.styleSheets.length; ss++) {
6         var css =document.styleSheets[ss];
7         console.log("sheet " + ss + '/' + document.styleSheets.length + ": " + css.ownerNode.outerHTML) ;
8         
9         var node = css.ownerNode;
10          ;
11         if (node.nodeName == 'STYLE' && node.getAttribute('media') && node.getAttribute('media').match(/print/)) {
12             node.innerHTML = '';
13             continue;
14         }
15         if (node.nodeName == 'LINK' && node.getAttribute('media') && node.getAttribute('media').match(/print/)) {
16             node.setAttribute('href' , '');
17             node.setAttribute('media' , 'speech');
18             continue;
19         }
20         
21         // now we are dealing with non-print styles...
22         
23         var ar = document.styleSheets[ss].rules;
24         if (!ar) {
25             if (node.nodeName == 'STYLE' ) {
26                 node.innerHTML = '';
27                 continue;
28             }
29             node.setAttribute('href' , '');
30             continue;
31         }
32         
33         var newsheet = '';
34         
35         
36         for(i=0; i < ar.length; i++){
37             if(ar[i].cssText.indexOf("@media") < 0 ) {
38                 newsheet += ar[i].cssText +"\n";
39                 continue;
40             }
41             //console.log(ar[i].cssText);
42             if(ar[i].cssText.match(/@media\s+print/)) {
43                 continue;
44             }
45             
46             // see if getting rid of 'only' from screen works.
47             if(!ar[i].cssText.match(/only\s+screen/)) {
48                 newsheet += ar[i].cssText +"\n";
49                 continue;   
50             }
51             var str = ar[i].cssText.replace(/only\s+screen/, 'screen');
52             newsheet += str +"\n";
53             
54             
55         }
56         
57         
58         if (node.nodeName == 'STYLE' ) {
59             node.innerHTML = newsheet;
60             continue;
61         }
62         var newnode = document.createElement('STYLE');
63         newnode.innerHTML = newsheet;
64         node.parentNode.replaceChild(newnode,node);
65         
66         
67     
68     }
69
70     
71     
72 })();