irc2html

- convert irc ascii art to html
git clone git://git.acid.vegas/irc2html.git
Log | Files | Refs | Archive

script.js (4457B)

      1 function formReset() {
      2 	document.getElementById('showcase').innerHTML = "<span class=\"placeholder\">*HTML view will appear here*</span>";
      3 }
      4 
      5 function toggle(bool) {
      6 	if (bool == true) {
      7 		return false;
      8 	}
      9 	else {
     10 		return true;
     11 	}
     12 }
     13 
     14 function convert() {
     15 	if (document.getElementById('text').value == "") {
     16 		return false;
     17 	}
     18 	document.getElementById('html').value = null;
     19 	document.getElementById('showcase').innerHTML = null;
     20 	lines = document.getElementById('text').value.split("\n");
     21 	reg = new RegExp("(([0-9]{1,2})?((?:,([0-9]{1,2}))?))|(||||)");
     22 	var showcase = "";
     23 	for (var i = 0, all=lines.length; i < all; i++) {
     24 		var line = lines[i];
     25 		line = line.replace(new RegExp('<','g'),'&lt;');
     26 		line = line.replace(new RegExp('>','g'),'&gt;');
     27 		var match, lastf = "1", lastb = "0";
     28 		var bold, italic, underline, reverse = false;
     29 		var first = true;
     30 		while ((match = reg.exec(line)) != null) {
     31 			var f, b, span;
     32 			if (match[2] != null) {
     33 				f = Number(match[2])
     34 				if (f > 15) { f = f-16; }
     35 				f = f.toString();
     36 				if (match[4] != null) {
     37 					b =  Number(match[4])
     38 					if (b > 15) { b = b-16; }
     39 					b = b.toString();
     40 				}
     41 				else {
     42 					b = lastb;
     43 				}
     44 			}
     45 			else if (match[2] == null && (match[5] == null || match[5] == '')) {
     46 				if (match[5] == null) {
     47 					f = "1"; b = "0";
     48 				}
     49 				else {
     50 					f = "1"; b = "0";
     51 					bold = false;
     52 					italic = false;
     53 					underline = false;
     54 					reverse = false;
     55 				}
     56 			}
     57 			else {
     58 				f = lastf, b = lastb;
     59 				if (match[5] == '') {
     60 					bold = toggle(bold);
     61 				}
     62 				else if (match[5] == '') {
     63 					italic = toggle(italic);
     64 				}
     65 				else if (match[5] == '') {
     66 					underline = toggle(underline);
     67 				}
     68 				else if (match[5] == '') {
     69 					reverse = toggle(reverse);
     70 				}
     71 			}
     72 			if (reverse == false) {
     73 				span = 'f'+f+' b'+b;
     74 			}
     75 			else {
     76 				span = 'f'+b+' b'+f;
     77 			}
     78 			if (bold == true) { span += ' _b'; }
     79 			if (italic == true) { span += ' _i'; }
     80 			if (underline == true) { span += ' _u'; }
     81 			if (first == false) {
     82 				line = line.replace(match[0],'</span><span class="'+span+'">');
     83 			}
     84 			else {
     85 				line = line.replace(match[0],'<span class="'+span+'">');
     86 				first = false;
     87 			}
     88 			lastf = f; lastb = b;
     89 		}
     90 		if (first == false) {
     91 			showcase += (line+"</span>\n");
     92 		}
     93 		else {
     94 			showcase += (line+"\n");
     95 		}
     96 	}
     97 	showcase = showcase.replace(new RegExp("\<span class=\"(?:[a-zA-Z0-9_ ]+\")>\<\/span>","g"),"");
     98 	document.getElementById('showcase').innerHTML = ("<pre>\n"+showcase+"</pre>");
     99 	document.getElementById('html').value = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<title>IRC2HTML - https://git.supernets.org/acidvegas/irc2html</title>\n<style type=\"text/css\">\n.f0 { color: #ffffff; }\n.b0 { background-color: #ffffff; }\n.f1 { color: #000000; }\n.b1 { background-color: #000000; }\n.f2 { color: #00007f; }\n.b2 { background-color: #00007f; }\n.f3 { color: #009300; }\n.b3 { background-color: #009300; }\n.f4 { color: #ff0000; }\n.b4 { background-color: #ff0000; }\n.f5 { color: #7f0000; }\n.b5 { background-color: #7f0000; }\n.f6 { color: #9c009c; }\n.b6 { background-color: #9c009c; }\n.f7 { color: #fc7f00; }\n.b7 { background-color: #fc7f00; }\n.f8 { color: #ffff00; }\n.b8 { background-color: #ffff00; }\n.f9 { color: #00fc00; }\n.b9 { background-color: #00fc00; }\n.f10 { color: #009393; }\n.b10 { background-color: #009393; }\n.f11 { color: #00ffff; }\n.b11 { background-color: #00ffff; }\n.f12 { color: #0000fc; }\n.b12 { background-color: #0000fc; }\n.f13 { color: #ff00ff; }\n.b13 { background-color: #ff00ff; }\n.f14 { color: #7f7f7f; }\n.b14 { background-color: #7f7f7f; }\n.f15 { color: #d2d2d2; }\n.b15 { background-color: #d2d2d2; }\n._b { font-weight: bold; }\n._i { font-style: italic; }\n._u { text-decoration: underline; }\npre { margin: 0; font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, monospace, serif; font-size: 0.9em; }\n</style>\n</head>\n<body>\n";
    100 	document.getElementById('html').value += document.getElementById('showcase').innerHTML;
    101 	document.getElementById('html').value += "\n</body>\n</html>";
    102 	return false;
    103 }
    104 
    105 function Submit() {
    106 	if (document.getElementById('text').value != "" && document.getElementById('text').value != null) {
    107 		return true;
    108 	}
    109 	return false;
    110 }
    111 
    112 function Download() {
    113 	document.location='data:text/html,'+encodeURIComponent(document.getElementById('html').value);
    114 }
    115 
    116 window.onload = convert;