Автор: LEX1
Дата сообщения: 04.10.2011 20:07
Обновлённый код для меню "Исходный код (snapshot)". В оригинале была пара неточностей, вылезших в другом браузере и лишняя глобальная переменная: [more]
Код: [no]javascript:(function(){var q=' ',C={img:1,br:1,link:1,input:1,hr:1,meta:1},u=false,v=0,D=1,g=window.document,m=window.location,w='resizable=yes,scrollbars=yes,location=no',h='</span></li>';var x=function(a){return'<span class=\'tag\'><'+a+''};var y=function(a){return(a?'/':'')+'></span>'};var z=function(a,b){if(b||C[a.toLowerCase()])return'';return'<span class=\'tag\'></'+a+'></span>'};var j=function(){var a=v.toString();while(a.length<3)a='0'+a;return'<li class=\'line'+(D&&((v++)&1)?' dark\'':'\'')+'><span>'};var n=function(a){return a.replace(/</g,'<').replace(/>/g,'>')};var E=function(a){var b=a.doctype,c='';if(b){c=j()+x('!DOCTYPE')+' <span class=\'attrDoc\'>'+b.nodeName+(b.publicId?' PUBLIC \''+b.publicId+'\'':'')+(b.systemId?'</span></span>'+h+j()+'<span class=\'tag\'><span class=\'attrDoc\'>'+q+'\''+b.systemId+'\'':'')+'</span>'+y()+h}return c};var F=function(a){var b=a.attributes,c=null,d='';for(var f=0;c=b[f];f++){if(c.specified&&c.value){d+=' <span class=\'attrTitle\'>'+c.name+'</span>=<span class=\'attrValue\'>\x22'+n(c.value.replace(/\t/g,q))+'\x22</span> '}}return d};var r=function(a){return n(a.nodeValue.replace(/[\n\t\r\u00A0]+ */g,'').replace(/ +/g,' '))};var G=function(a){var b=0,c='';while(b<a){c+=q;b++}return c};var A=function(a,b,c){var d='',f=G(b++);switch(a.nodeType){case 1:{var i=a.childNodes,k=null;var s=(i.length==0)||(i.length==1&&i[0].nodeType==3);var t=u&&i.length==0;var l=j()+f+x(a.nodeName)+F(a)+y(t);if(!s)l+=h;for(var B=0;k=i[B];B++){l+=A(k,b,!s&&k.nodeType==3)}if(s){l+=(a.nodeName.toLowerCase()=='textarea'?n(a.value):'')+z(a.nodeName,t)+h}else{l+=j()+f+z(a.nodeName,t)+h}return l}case 3:{if((d=r(a))&&c){return j()+f+d+h}else{return d}}case 4:{d=r(a);return j()+f+'<span class=\'cdata\'><![CDATA[</span>'+d+'<span class=\'cdata\'>]]></span>'+h}case 8:{d=r(a);return j()+f+'<span class=\'comment\'><!--'+d+'--></span>'+h}}return a.nodeType};var H=function(a){var b,c='';if(a){var d=a.getSelection().getRangeAt(0),f=d.commonAncestorContainer;if(f.nodeType==3||f.nodeType==4)f=f.parentNode;b=f.cloneNode(false);b.appendChild(d.cloneContents());var i=d.startContainer,k=d.endContainer;if(i!=f.firstChild||(i.nodeType==3&&d.startOffset!=0))b.insertBefore(g.createTextNode('\u2026'),b.firstChild);if(k!=f.lastChild||(k.nodeType==3&&d.endOffset!=k.nodeValue.length))b.appendChild(g.createTextNode('\u2026'))}else{c=E(g);b=g.documentElement};c+=A(b,0);return c};var I=function(a){if(a&&a.getSelection){if(a.getSelection().toString())return a;for(var b=0,c,d;c=a.frames[b];b++){try{if(d=arguments.callee(c))return d}catch(e){}}}};var o=I(window);if(o){g=o.document;m=o.location;w+=',width=800,height=500,left=100,top=100'};u=/[a-z]/.test(g.documentElement.nodeName);var J='<!DOCTYPE html PUBLIC><html><head><title>Snapshot: '+((g.getElementsByTagName('title').length&&n(g.getElementsByTagName('title')[0].text))||(m.protocol+'//'+m.host+m.pathname))+'</title><style type=\'text/css\'>body{padding:0 5px;margin:0;font-family:sans-serif;font-size:.7em;background-color:#FFF;color:#000;}#content{white-space:pre-wrap}ol{color:#999;}span{color:#000}.tag{color:#05F}.attrTitle{color:#E00}.attrValue{color:#C0C}.attrDoc{color:#800080}.comment{color:#008000}.cdata{color:#63D}.line{margin:0;padding:0}.dark{background-color:#FAFAFA}</style></head><body><ol id=\'content\'>'+H(o)+'</ol></body></html>';var p=window.open('about:blank','_blank',w);p.document.write(J);p.document.onkeyup=function(a){if(a.keyCode==27)p.close()};p.document.close()})()[/no]