Advertisement
Guest User

HTML5 Outliner Bookmarklet

a guest
Nov 30th, 2012
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. javascript:(function(){var%20i=function(a){this.sections=[];this.startingNode=a};i.prototype={heading:false,append:function(a){a.container=this;this.sections.push(a)},asHTML:function(a){var%20b=u(this.heading);if(a)b='<a%20href="#'+v(this.startingNode)+'">'+b+"</a>";return%20b+q(this.sections,a)}};var%20q=function(a,b){for(var%20f="",c=0;c<a.length;c++)f+="<li>"+a[c].asHTML(b)+"</li>";return%20f==""?f:"<ol>"+f+"</ol>"},r=function(a){a=a.heading;return%20h(a)?j(a):1},u=function(a){if(h(a)){if(k(a)=="HGROUP")a=a.getElementsByTagName("h"+-j(a))[0];return%20a.textContent||a.innerText||"<i>No%20text%20content%20inside%20"+a.nodeName+"</i>"}return""+a},v=function(a){var%20b=a.getAttribute("id");if(b)return%20b;do%20b="h5o-"+%20++s;while(t.getElementById(b));a.setAttribute("id",b);return%20b},e,d,g,s,t,w=function(a,b,f){var%20c=a;a:for(;c;){b(c);if(c.firstChild){c=c.firstChild;continue%20a}for(;c;){f(c);if(c.nextSibling){c=c.nextSibling;continue%20a}c=c==a?null:c.parentNode}}},x=function(a){if(!h(o(g)))if(l(a)||m(a)){e!=null&&g.push(e);e=a;d=new%20i(a);e.outline={sections:[d],startingNode:a,asHTML:function(c){return%20q(this.sections,c)}}}else%20if(e!=null)if(h(a)){if(d.heading)if(j(a)>=r(n(e.outline))){var%20b=new%20i(a);e.outline.sections.push(b);d=b;d.heading=a}else{b=false;var%20f=d;do{if(j(a)<r(f)){b=new%20i(a);f.append(b);d=b;d.heading=a;b=true}f=f.container}while(!b)}else%20d.heading=a;g.push(a)}},y=function(a){var%20b=o(g);if(h(b))b==a&&g.pop();else{if((l(a)||m(a))&&!d.heading)d.heading="<i>Untitled%20"+k(a)+"</i>";if(l(a)&&g.length>0){e=g.pop();d=n(e.outline);for(b=0;b<a.outline.sections.length;b++)d.append(a.outline.sections[b])}else%20if(m(a)&&g.length>0){e=g.pop();for(d=n(e.outline);d.sections.length>0;)d=n(d)}else%20if(l(a)||m(a))d=e.outline.sections[0]}},k=function(a){return%20a.tagName.toUpperCase()},p=function(a){return%20function(b){return%20z(b)&&(new%20RegExp(a,"i")).test(k(b))}},m=p("^BLOCKQUOTE|BODY|DETAILS|FIELDSET|FIGURE|TD$"),l=p("^ARTICLE|ASIDE|NAV|SECTION$"),h=p("^H[1-6]|HGROUP$"),z=function(a){return%20a&&a.tagName},j=function(a){var%20b=k(a);if(b=="HGROUP")for(b=1;b<=6;b++){if(a.getElementsByTagName("H"+b).length>0)return-b}else%20return-parseInt(b.substr(1))},n=function(a){return%20o(a.sections)},o=function(a){return%20a[a.length-1]};HTML5Outline=function(a){s=0;t=a.ownerDocument||window.document;d=e=null;g=[];w(a,x,y);return%20e!=null?e.outline:null}})();;(function(){var%20b=function(e,f){for(var%20d=0;d<e.length;d++)e[d].setAttribute("style",f)},g=HTML5Outline(document.body).asHTML(true),a=document.createElement("div");b([a],"position:fixed;top:10px;right:10px;border:2px%20solid%20#000;background:rgba(255,255,255,.9);padding:15px;z-index:999;max-height:400px;overflow:auto;font-size:11px;font-family:Verdana,%20sans-serif;");a.innerHTML=g;b(a.getElementsByTagName("li"),"list-style:decimal%20outside;margin-left:20px;font-size:11px;font-family:Verdana,%20sans-serif;");b(a.getElementsByTagName("ol"),"margin:%200;padding:0;font-size:11px;font-family:Verdana,%20sans-serif;");b(a.getElementsByTagName("a"),"color:#008;text-decoration:underline;font-size:11px;font-family:Verdana,%20sans-serif;");var%20c=a.insertBefore(document.createElement("a"),a.firstChild);b([c],"float:%20right;%20margin:%200%200%205px%205px;%20padding:%205px;%20border:%201px%20#008%20solid;color:#00f;background-color:#ccf;");c.innerHTML="Close";c.href="#";c.onclick=function(){document.body.removeChild(a);a=c=null};document.body.appendChild(a)})();;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement