X-Git-Url: http://git.roojs.org/?p=app.webkitpdf;a=blobdiff_plain;f=inliner.js;h=f079dd86cfe9060762b84925b8623e83da5f4530;hp=f8df8ad6af093eff40ff3233d99bdd19ab1fd33c;hb=6d6cb84a885a8451e33b64bed99ad3a82a13efe6;hpb=d02daa4d246cd1c853f7d8a347f202aeefd783b7 diff --git a/inliner.js b/inliner.js index f8df8ad..f079dd8 100644 --- a/inliner.js +++ b/inliner.js @@ -1,4 +1,17 @@ - +/** + * + * could this work by findind all the visible text, + * then making them hidden.. + * + * -- make a snapshot of the background.. + * + * -- delete the whole page... + * -- show the image as the background. + * -- then overlay all the text given their calculated positions.. + * + * + * + */ (function(){ @@ -7,47 +20,50 @@ return b.toUpperCase(); } - var keys = ['fontFamily','fontSize','fontWeight','fontStyle','color', - 'textTransform','textDecoration','letterSpacing','wordSpacing', - 'lineHeight','textAlign','verticalAlign','direction','backgroundColor', - 'backgroundImage','backgroundRepeat','backgroundposition', - 'backgroundAttachment','opacity','width','height','top','right','bottom', - 'left','marginTop','marginRight','marginBottom','marginLeft', - 'paddingTop','paddingRight','paddingBottom','paddingLeft', - 'borderTopWidth','borderRightWidth','borderBottomWidth', - 'borderLeftWidth','borderTopColor','borderRightColor', - 'borderBottomColor','borderLeftColor','borderTopStyle', - 'borderRightStyle','borderBottomStyle','borderLeftStyle','position', - 'display','visibility','zIndex','overflowX','overflowY','whiteSpace', - 'clip','float','clear','cursor','listStyleImage','listStylePosition', - 'listStyleType','markerOffset' - ]; + - var fillStyle = function(dom) + var fillStyle = function(dom, pstyle) { if (!dom || dom.nodeType != 1) { + //console.log("SKIP: " + dom.nodeName); return; } - console.log(dom.nodeName); + //console.log(dom.nodeName); var style = window.getComputedStyle(dom, null); - if (style.display == 'none') { + if (style.display == 'none' || dom.nodeName == "NOSCRIPT" || dom.nodeName == "SCRIPT" ) { dom.parentElement.removeChild(dom); return; } + var cn = []; - for (var i = dom.childNodes.length -1; i--; i> -1) { - fillStyle(dom.childNodes[i]); + if (dom.childNodes.length > 100) { + console.log(dom); + throw "too many child nodes?" + dom.childNodes.length ; + } + for (var i = 0;i < dom.childNodes.length;i++) { + cn.push(dom.childNodes[i]); } - + if (cn.length > 100) { + console.log(dom); + throw "too many child nodes? cn"; + } + for (var i = 0;i < cn.length;i++) { + + //console.log( i + ':'+ cn[i].nodeName); + fillStyle(cn[i], style); + } + //var pstyle = false; //if (dom.nodeName != 'BODY') { // pstyle = window.getComputedStyle(dom.parentElement, null); //} - + if (dom.nodeName == 'SPAM') { + pstyle = false; //?? others?? + } //if (dom.nodeName == 'LI') { throw 'done'; } @@ -59,32 +75,46 @@ //returns[camel] = val; // idea... if the parent has the same style.. then do not apply it to the child? - //if (pstyle && pstyle[prop] == val) { - // continue; - //} - console.log(prop + '=' + val); + if (pstyle && pstyle[prop] == val) { + continue; + } + //console.log(prop + '=' + val); dom.style[camel] = val; } var es = dom.getAttribute('style'); - console.log(node.nodeName + '::' + es); - dom.setAtrtribute('style', es); + //console.log(dom.nodeName + '::' + es); + dom.setAttribute('style', es); //return returns; } - var el = document.querySelector('body'); - fillStyle(el); - var matches = document.getElementsByTagName('style'); - for(var i =0;i < matches.length;i++) { - matches[i].parentElement.removeChild(matches[i]); - } - var matches = document.getElementsByTagName('link'); - for(var i =0;i < matches.length;i++) { - matches[i].parentElement.removeChild(matches[i]); + function changeit() { + + + var el = document.querySelector('body'); + fillStyle(el), false; + + var matches = document.getElementsByTagName('style'); + var rm = []; + for(var i =0;i < matches.length;i++) { + rm.push(matches[i]); + + } + var matches = document.getElementsByTagName('link'); + for(var i =0;i < matches.length;i++) { + rm.push(matches[i]); + } + for(var i =0 ; i < rm.length;i++) { + rm[i].parentNode.removeChild(rm[i]); + } + + + } - + changeit(); + console.log("done"); })(); \ No newline at end of file