0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[泥コード]🔖DOMツリー解析

0
Posted at

🔖DOMツリー


var root='Global',w1,d1;

/*Html変換*/
function enHtml(str){var rtn;
rtn=(String(str).replace(/\&/g,"&#38;")).replace(/[<.>#]/g,function(t){return '&#'+String((t).charCodeAt(0))+';';});
if(!rtn)return false;return rtn;
}

/*nVl変換*/
function tVle(nd){var t,vle,nVl,chdn,com,lst;
t=nd.nodeType;nVl=(t===8?enHtml(nd.nodeValue):nd.nodeValue);
chdn=(!(t===1&&nd.children)?'':('(子:'+nd.children.length+')'));
com=('米'+chdn+':');
lst=['',' V:','','字:','','','','',com,'','','','',''];
if(!confirm('Comment:'+lst[8]))return false;
vle=(!Boolean(nVl.trim())?'':lst[t]+'\"'+(nVl.trim()).replace(/[  ]{2,999}/g,' ').replace(/[\s]*\n[\s]*/g,'⊿')+'\"');
return vle;
}

/*全要素内処理*/
function doNodes(node,ind,num){
/*doNodes*/

/*1.要素⊿*/
function tElm(nd,hdr){
var rtn,nNm,nVl
,nId=(nd.id?'#'+nd.id:'')
,nCs=(nd.className?nd.className.trim().replace(/[\s]+/g,'.'):'')
,bLt=(nId?'<B>':'')
,bRt=(nId?'</B>':'');
nNm=nd.nodeName.toUpperCase();nVl=tVle(nd);
rtn='\n'+hdr+bLt+'['+nNm+']'+nId+nCs+bRt+nVl;
return rtn;
}

/*3.文字⊿*/
function tTxt(nd,hdr){var rtn,nVl;
nVl=tVle(nd);rtn='\n'+hdr+nVl;return rtn;
}

/*8.米⊿*/
function tCmt(nd,hdr){var rtn,nVl;
nVl=tVle(nd);rtn='\n'+hdr+nVl;return rtn;
}

/*2.属性(行内)*/
function tAtt(at){var rtn,nVl,vle,ky;
nVl=at.nodeValue;vle=(!nVl.trim()?'':nVl.trim());ky=at.nodeName;
if(vle)vle=':\"'+vle+'\"';rtn=' '+ky+vle;return rtn;
}

switch(node.nodeType){
case 2:d1.write(tAtt(node));break;
case 3:d1.write(tTxt(node,ind));break;
case 8:d1.write(tCmt(node,ind));break;
default: d1.write(tElm(node,ind));break;
}

/*排除候補
d1.write(ind+'['+num+']'+'TYPE='+node.nodeType+';NAME='+node.nodeName);
if(node.id)d1.write(';ID='+node.id);
if(node.className)d1.write(';CLASS='+node.className);
if(node.nodeValue)d1.write(';VAL='+node.nodeValue.replace(/\n/g,'[NL]'));
d1.writeln('');
排除候補*/

/*Att.Tre
if(node.attributes){
for(var i=0;i<node.attributes.length;++i){doNodes(
node.attributes.item(i),ind+' |',i);}
}Att.Tre*/

if(node.childNodes){
/*Chld.Tre*/
for(var i=0;i<node.childNodes.length;i++){doNodes(node.childNodes.item(i),ind+' ',i);}
/*Chld.Tre*/}

/*doNodes*/}
/*処理宣言終了*/

/*空頁作成*/
w1=window.open('','Test');
d1=w1.document;

/*窓上書開始*/d1.open();
d1.writeln('<pre>\nTest...');

/*全要素順次アクセス*/
doNodes(document.documentElement,'',1);

/*窓上書完了*/
d1.writeln('END.</pre>');
d1.close();

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?