K-Meleon
KMeleonWiki > Resources > MacroLibrary > MacroLibrary2 > Print Prep
Submitted by: MonkeeSage - MonkeeSage@ToughGuy.net - http://gratisDei.com/KM.htm
Notes: The javascript in the macro will do three things:
Ps. Works on pages with tables and frames as well, e.g., http://www.strongframes.com/
Pss. Make sure the open(" javascript:... "); line of the macro is ALL ONE LINE!!
Ps. The image replacing function doesn't work on images set by CSS rules, only those that are set inline via the element tag
# print_prep { menu="Pr&epare the page for printing"; # Replace images with their alternate text if any open(" javascript:(function(){function toArray(c){var a,k;a=new Array;for (k=0;k<c.length;++k)a[k]=c[k];return a;}var images,img,altText;images=toArray(document.images);for (var p=0;p<images.length;++p){img=images[p];altText=document.createTextNode(img.alt);img.parentNode.replaceChild(altText,img)}})(); "); # Totally remove embed, object, applet, and iframe elements open(" javascript:(function(){function R(w){try{var d=w.document,j,k,t,T,N,b,r=1,C;for(j=0;t=['object','embed','applet','iframe'][j];++j){T=d.getElementsByTagName(t);for(k=T.length-1;(k+1)&&(N=T[k]);--k)if(j!=3||!R((C=N.contentWindow)?C:N.contentDocument.defaultView)){b=d.createElement('div');b.style.width=N.width; b.style.height=N.height;b.innerHTML='<del>'+(j==3?'third-party '+t:t)+'</del>';N.parentNode.replaceChild(b,N);}}}catch(E){r=0}return r}R(self);var k,x;for(k=0;x=frames[k];++k)R(x)})(); "); # Change the document colors open(" javascript:(function(){var theElm=new Array();var elmCount=0;function eLm(obj){theElm[elmCount]=document.getElementsByTagName(obj);++elmCount;}function b_wKids(obj){for(var j=0;j<obj.length;++j){b_wIt(obj[j]);}}function b_wIt(obj){try{obj.bgColor='white';obj.Color='black';obj.color='black';}catch(e){}}function toB_W(x){eLm('table');eLm('td');eLm('tbody');eLm('th');eLm('tr');eLm('p');eLm('form');eLm('font');eLm('div');eLm('span');eLm('h1');eLm('h2');eLm('h3');eLm('label'); if(x.frames.length==0){void(b_wIt(x.document));for(var n=0;n<theElm.length;++n){if(theElm[n]){if(theElm[n].length>0)void(b_wKids(theElm[n]));}}}else{for(var j=0;j<x.frames.length;++j){void(toB_W(x.frames[j]));}}}void(toB_W(window));document.close();})(); ");
macros(print_prep)