-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextras.min.js
executable file
·1 lines (1 loc) · 2.18 KB
/
extras.min.js
1
function BBCodeTag(c,a,b){this.start=c;this.end=a;this.unparsed=b}var tags={aa:new BBCodeTag('<span class="aa">',"</span>"),b:new BBCodeTag("<b>","</b>"),code:new BBCodeTag("<code>","</code>",true),i:new BBCodeTag("<i>","</i>"),tt:new BBCodeTag("<tt>","</tt>"),o:new BBCodeTag('<span class="o">',"</span>"),quote:new BBCodeTag("<blockquote>","</blockquote>"),del:new BBCodeTag("<del>","</del>"),spoiler:new BBCodeTag('<span class="spoiler">',"</span>"),sub:new BBCodeTag("<sub>","</sub>"),sup:new BBCodeTag("<sup>","</sup>"),u:new BBCodeTag("<u>","</u>"),"#":new BBCodeTag("","",true)};function parseBBCode(h){var g=/^(.*?)\[([a-z#]+)\](.*)\[\/\2\](.*)$/m;var e=g.exec(h);if(!e){return h.replace("[br]","\n","gim")}var f=e[1];var i=e[2];var b="["+i+"]";var d="[/"+i+"]";var c=e[3];var a=e[4];if(!tags[i]||!tags[i].unparsed){c=parseBBCode(c)}if(tags[i]){b=tags[i].start;d=tags[i].end}return f+b+c+d+a}function getPlainText(c){var a="";for(var b=0;b<c.childNodes.length;++b){if(c.childNodes[b].nodeName=="BR"){a+="\n"}else{a+=c.childNodes[b].textContent}}return a}function make_format_link(d,a,c){var b=document.createElement("a");b.href='javascript:(function(){var post=document.getElementById("'+d.id+'");var comment=post.lastChild;comment.innerHTML='+c+"(getPlainText(comment));post.removeChild(post.firstChild);})()";b.appendChild(document.createTextNode(a));return b}function init(){var d='<!--#echo var="base" encoding="url"-->';var a=document.getElementsByTagName("form");var c=document.getElementsByTagName("div");for(var b=0;b<c.length;++b){if(c[b].className=="post"){(function(){var g=c[b].firstChild;var h=c[b].id.split("_");var e=h[0];var f=h[1];format_div=document.createElement("div");format_div.style.fontSize="xx-small";format_div.appendChild(document.createTextNode("formatting: "));format_div.appendChild(make_format_link(c[b],"html",""));format_div.appendChild(document.createTextNode(" "));format_div.appendChild(make_format_link(c[b],"bbcode","parseBBCode"));c[b].insertBefore(format_div,c[b].firstChild);g.onclick=function(k){var j=document.getElementById("sage_"+e).parentNode;var i=j.getElementsByTagName("textarea")[0];i.focus();if(i.value!=""&&i.value.substr(-1)!="\n"){i.value+="\n"}i.value+=">>"+f+"\n"}})()}}};