Beautify Apache server-status page

Apache HTTP server can have mod_status enabled and can

当前为 2016-04-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Beautify Apache server-status page
  3. // @namespace http://denilson.sa.nom.br/
  4. // @author Denilson Sá
  5. // @grant none
  6. // @license Public domain
  7. // @version 1.3
  8. // @description Apache HTTP server can have mod_status enabled and can
  9. // display some server status via HTTP/HTML (there must be some
  10. // uncommented lines in httpd.conf). However, the page sent to
  11. // browser is a bit raw, completely unstyled, and hard to read.
  12. // This script tries to make that page much prettier and more
  13. // readable. It has been tested with Apache 2.0.55 and 2.2.21 and
  14. // should work on most versions, unless the generated HTML changes,
  15. // which will degrade gradually the script.
  16. // @include http://*/server-status
  17. // ==/UserScript==
  18.  
  19.  
  20. //////////////////////////////////////////////////////////////////////
  21. // Including code from:
  22. // http://www.kryogenix.org/code/browser/sorttable/
  23. // fetched on 2011-10-18
  24. // Slightly modified in order to fix bugs
  25.  
  26.  
  27. // Denilson has moved to the top of the script instead of the bottom.
  28. // Dean's forEach: http://dean.edwards.name/base/forEach.js
  29. /*
  30. forEach, version 1.0
  31. Copyright 2006, Dean Edwards
  32. License: http://www.opensource.org/licenses/mit-license.php
  33. */
  34.  
  35. // array-like enumeration
  36. if (!Array.forEach) { // mozilla already supports this
  37. Array.forEach = function(array, block, context) {
  38. for (var i = 0; i < array.length; i++) {
  39. block.call(context, array[i], i, array);
  40. }
  41. };
  42. }
  43.  
  44. // generic enumeration
  45. Function.prototype.forEach = function(object, block, context) {
  46. for (var key in object) {
  47. if (typeof this.prototype[key] == "undefined") {
  48. block.call(context, object[key], key, object);
  49. }
  50. }
  51. };
  52.  
  53. // character enumeration
  54. String.forEach = function(string, block, context) {
  55. Array.forEach(string.split(""), function(chr, index) {
  56. block.call(context, chr, index, string);
  57. });
  58. };
  59.  
  60. // globally resolve forEach enumeration
  61. var forEach = function(object, block, context) {
  62. if (object) {
  63. var resolve = Object; // default
  64. if (object instanceof Function) {
  65. // functions have a "length" property
  66. resolve = Function;
  67. } else if (object.forEach instanceof Function) {
  68. // the object implements a custom forEach method so use that
  69. object.forEach(block, context);
  70. return;
  71. } else if (typeof object == "string") {
  72. // the object is a string
  73. resolve = String;
  74. } else if (typeof object.length == "number") {
  75. // the object is array-like
  76. resolve = Array;
  77. }
  78. resolve.forEach(object, block, context);
  79. }
  80. };
  81.  
  82.  
  83.  
  84. /*
  85. SortTable
  86. version 2
  87. 7th April 2007
  88. Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
  89. Instructions:
  90. Download this file
  91. Add <script src="sorttable.js"></script> to your HTML
  92. Add class="sortable" to any table you'd like to make sortable
  93. Click on the headers to sort
  94. Thanks to many, many people for contributions and suggestions.
  95. Licenced as X11: http://www.kryogenix.org/code/browser/licence.html
  96. This basically means: do what you want with it.
  97. */
  98.  
  99. // Denilson has changed this to always false.
  100. var stIsIE = false;
  101.  
  102. sorttable = {
  103. init: function() {
  104. // quit if this function has already been called
  105. if (arguments.callee.done) return;
  106. // flag this function so we don't do the same thing twice
  107. arguments.callee.done = true;
  108.  
  109. // Denilson removed this because the timer is not even set anymore
  110. // kill the timer
  111. //if (_timer) clearInterval(_timer);
  112. if (!document.createElement || !document.getElementsByTagName) return;
  113. sorttable.DATE_RE = /^(\d\d?)[\/\.-](\d\d?)[\/\.-]((\d\d)?\d\d)$/;
  114. forEach(document.getElementsByTagName('table'), function(table) {
  115. if (table.className.search(/\bsortable\b/) != -1) {
  116. sorttable.makeSortable(table);
  117. }
  118. });
  119. },
  120. makeSortable: function(table) {
  121. if (table.getElementsByTagName('thead').length == 0) {
  122. // table doesn't have a tHead. Since it should have, create one and
  123. // put the first table row in it.
  124. the = document.createElement('thead');
  125. the.appendChild(table.rows[0]);
  126. table.insertBefore(the,table.firstChild);
  127. }
  128. // Safari doesn't support table.tHead, sigh
  129. if (table.tHead == null) table.tHead = table.getElementsByTagName('thead')[0];
  130. if (table.tHead.rows.length != 1) return; // can't cope with two header rows
  131. // Sorttable v1 put rows with a class of "sortbottom" at the bottom (as
  132. // "total" rows, for example). This is B&R, since what you're supposed
  133. // to do is put them in a tfoot. So, if there are sortbottom rows,
  134. // for backwards compatibility, move them to tfoot (creating it if needed).
  135. sortbottomrows = [];
  136. for (var i=0; i<table.rows.length; i++) {
  137. if (table.rows[i].className.search(/\bsortbottom\b/) != -1) {
  138. sortbottomrows[sortbottomrows.length] = table.rows[i];
  139. }
  140. }
  141. if (sortbottomrows) {
  142. if (table.tFoot == null) {
  143. // table doesn't have a tfoot. Create one.
  144. tfo = document.createElement('tfoot');
  145. table.appendChild(tfo);
  146. }
  147. for (var i=0; i<sortbottomrows.length; i++) {
  148. tfo.appendChild(sortbottomrows[i]);
  149. }
  150. delete sortbottomrows;
  151. }
  152. // work through each column and calculate its type
  153. headrow = table.tHead.rows[0].cells;
  154. for (var i=0; i<headrow.length; i++) {
  155. // manually override the type with a sorttable_type attribute
  156. if (!headrow[i].className.match(/\bsorttable_nosort\b/)) { // skip this col
  157. mtch = headrow[i].className.match(/\bsorttable_([a-z0-9]+)\b/);
  158. if (mtch) { override = mtch[1]; }
  159. if (mtch && typeof sorttable["sort_"+override] == 'function') {
  160. headrow[i].sorttable_sortfunction = sorttable["sort_"+override];
  161. } else {
  162. headrow[i].sorttable_sortfunction = sorttable.guessType(table,i);
  163. }
  164. // make it clickable to sort
  165. headrow[i].sorttable_columnindex = i;
  166. headrow[i].sorttable_tbody = table.tBodies[0];
  167. dean_addEvent(headrow[i],"click", function(e) {
  168.  
  169. if (this.className.search(/\bsorttable_sorted\b/) != -1) {
  170. // if we're already sorted by this column, just
  171. // reverse the table, which is quicker
  172. sorttable.reverse(this.sorttable_tbody);
  173. this.className = this.className.replace('sorttable_sorted',
  174. 'sorttable_sorted_reverse');
  175. this.removeChild(document.getElementById('sorttable_sortfwdind'));
  176. sortrevind = document.createElement('span');
  177. sortrevind.id = "sorttable_sortrevind";
  178. sortrevind.innerHTML = stIsIE ? '&nbsp<font face="webdings">5</font>' : '&nbsp;&#x25B4;';
  179. this.appendChild(sortrevind);
  180. return;
  181. }
  182. if (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) {
  183. // if we're already sorted by this column in reverse, just
  184. // re-reverse the table, which is quicker
  185. sorttable.reverse(this.sorttable_tbody);
  186. this.className = this.className.replace('sorttable_sorted_reverse',
  187. 'sorttable_sorted');
  188. this.removeChild(document.getElementById('sorttable_sortrevind'));
  189. sortfwdind = document.createElement('span');
  190. sortfwdind.id = "sorttable_sortfwdind";
  191. sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
  192. this.appendChild(sortfwdind);
  193. return;
  194. }
  195. // remove sorttable_sorted classes
  196. theadrow = this.parentNode;
  197. forEach(theadrow.childNodes, function(cell) {
  198. if (cell.nodeType == 1) { // an element
  199. cell.className = cell.className.replace('sorttable_sorted_reverse','');
  200. cell.className = cell.className.replace('sorttable_sorted','');
  201. }
  202. });
  203. sortfwdind = document.getElementById('sorttable_sortfwdind');
  204. if (sortfwdind) { sortfwdind.parentNode.removeChild(sortfwdind); }
  205. sortrevind = document.getElementById('sorttable_sortrevind');
  206. if (sortrevind) { sortrevind.parentNode.removeChild(sortrevind); }
  207. this.className += ' sorttable_sorted';
  208. sortfwdind = document.createElement('span');
  209. sortfwdind.id = "sorttable_sortfwdind";
  210. sortfwdind.innerHTML = stIsIE ? '&nbsp<font face="webdings">6</font>' : '&nbsp;&#x25BE;';
  211. this.appendChild(sortfwdind);
  212.  
  213. // build an array to sort. This is a Schwartzian transform thing,
  214. // i.e., we "decorate" each row with the actual sort key,
  215. // sort based on the sort keys, and then put the rows back in order
  216. // which is a lot faster because you only do getInnerText once per row
  217. row_array = [];
  218. col = this.sorttable_columnindex;
  219. rows = this.sorttable_tbody.rows;
  220. for (var j=0; j<rows.length; j++) {
  221. row_array[row_array.length] = [sorttable.getInnerText(rows[j].cells[col]), rows[j]];
  222. }
  223. /* If you want a stable sort, uncomment the following line */
  224. //sorttable.shaker_sort(row_array, this.sorttable_sortfunction);
  225. /* and comment out this one */
  226. row_array.sort(this.sorttable_sortfunction);
  227. tb = this.sorttable_tbody;
  228. for (var j=0; j<row_array.length; j++) {
  229. tb.appendChild(row_array[j][1]);
  230. }
  231. delete row_array;
  232. });
  233. }
  234. }
  235. },
  236. guessType: function(table, column) {
  237. // guess the type of a column based on its first non-blank row
  238. sortfn = sorttable.sort_alpha;
  239. for (var i=0; i<table.tBodies[0].rows.length; i++) {
  240. text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);
  241. if (text != '') {
  242. if (text.match(/^-?[£$¤]?[\d,.]+%?$/)) {
  243. return sorttable.sort_numeric;
  244. }
  245. // check for a date: dd/mm/yyyy or dd/mm/yy
  246. // can have / or . or - as separator
  247. // can be mm/dd as well
  248. possdate = text.match(sorttable.DATE_RE)
  249. if (possdate) {
  250. // looks like a date
  251. first = parseInt(possdate[1]);
  252. second = parseInt(possdate[2]);
  253. if (first > 12) {
  254. // definitely dd/mm
  255. return sorttable.sort_ddmm;
  256. } else if (second > 12) {
  257. return sorttable.sort_mmdd;
  258. } else {
  259. // looks like a date, but we can't tell which, so assume
  260. // that it's dd/mm (English imperialism!) and keep looking
  261. sortfn = sorttable.sort_ddmm;
  262. }
  263. }
  264. }
  265. }
  266. return sortfn;
  267. },
  268. getInnerText: function(node) {
  269. // gets the text we want to use for sorting for a cell.
  270. // strips leading and trailing whitespace.
  271. // this is *not* a generic getInnerText function; it's special to sorttable.
  272. // for example, you can override the cell text with a customkey attribute.
  273. // it also gets .value for <input> fields.
  274. hasInputs = (typeof node.getElementsByTagName == 'function') &&
  275. node.getElementsByTagName('input').length;
  276. if (node.getAttribute("sorttable_customkey") != null) {
  277. return node.getAttribute("sorttable_customkey");
  278. }
  279. else if (typeof node.textContent != 'undefined' && !hasInputs) {
  280. return node.textContent.replace(/^\s+|\s+$/g, '');
  281. }
  282. else if (typeof node.innerText != 'undefined' && !hasInputs) {
  283. return node.innerText.replace(/^\s+|\s+$/g, '');
  284. }
  285. else if (typeof node.text != 'undefined' && !hasInputs) {
  286. return node.text.replace(/^\s+|\s+$/g, '');
  287. }
  288. else {
  289. switch (node.nodeType) {
  290. case 3:
  291. if (node.nodeName.toLowerCase() == 'input') {
  292. return node.value.replace(/^\s+|\s+$/g, '');
  293. }
  294. case 4:
  295. return node.nodeValue.replace(/^\s+|\s+$/g, '');
  296. break;
  297. case 1:
  298. case 11:
  299. var innerText = '';
  300. for (var i = 0; i < node.childNodes.length; i++) {
  301. innerText += sorttable.getInnerText(node.childNodes[i]);
  302. }
  303. return innerText.replace(/^\s+|\s+$/g, '');
  304. break;
  305. default:
  306. return '';
  307. }
  308. }
  309. },
  310. reverse: function(tbody) {
  311. // reverse the rows in a tbody
  312. newrows = [];
  313. for (var i=0; i<tbody.rows.length; i++) {
  314. newrows[newrows.length] = tbody.rows[i];
  315. }
  316. for (var i=newrows.length-1; i>=0; i--) {
  317. tbody.appendChild(newrows[i]);
  318. }
  319. delete newrows;
  320. },
  321. /* sort functions
  322. each sort function takes two parameters, a and b
  323. you are comparing a[0] and b[0] */
  324. sort_numeric: function(a,b) {
  325. aa = parseFloat(a[0].replace(/[^0-9.-]/g,''));
  326. if (isNaN(aa)) aa = 0;
  327. bb = parseFloat(b[0].replace(/[^0-9.-]/g,''));
  328. if (isNaN(bb)) bb = 0;
  329. return aa-bb;
  330. },
  331. sort_alpha: function(a,b) {
  332. if (a[0]==b[0]) return 0;
  333. if (a[0]<b[0]) return -1;
  334. return 1;
  335. },
  336. sort_ddmm: function(a,b) {
  337. mtch = a[0].match(sorttable.DATE_RE);
  338. y = mtch[3]; m = mtch[2]; d = mtch[1];
  339. if (m.length == 1) m = '0'+m;
  340. if (d.length == 1) d = '0'+d;
  341. dt1 = y+m+d;
  342. mtch = b[0].match(sorttable.DATE_RE);
  343. y = mtch[3]; m = mtch[2]; d = mtch[1];
  344. if (m.length == 1) m = '0'+m;
  345. if (d.length == 1) d = '0'+d;
  346. dt2 = y+m+d;
  347. if (dt1==dt2) return 0;
  348. if (dt1<dt2) return -1;
  349. return 1;
  350. },
  351. sort_mmdd: function(a,b) {
  352. mtch = a[0].match(sorttable.DATE_RE);
  353. y = mtch[3]; d = mtch[2]; m = mtch[1];
  354. if (m.length == 1) m = '0'+m;
  355. if (d.length == 1) d = '0'+d;
  356. dt1 = y+m+d;
  357. mtch = b[0].match(sorttable.DATE_RE);
  358. y = mtch[3]; d = mtch[2]; m = mtch[1];
  359. if (m.length == 1) m = '0'+m;
  360. if (d.length == 1) d = '0'+d;
  361. dt2 = y+m+d;
  362. if (dt1==dt2) return 0;
  363. if (dt1<dt2) return -1;
  364. return 1;
  365. },
  366. shaker_sort: function(list, comp_func) {
  367. // A stable sort function to allow multi-level sorting of data
  368. // see: http://en.wikipedia.org/wiki/Cocktail_sort
  369. // thanks to Joseph Nahmias
  370. var b = 0;
  371. var t = list.length - 1;
  372. var swap = true;
  373.  
  374. while(swap) {
  375. swap = false;
  376. for(var i = b; i < t; ++i) {
  377. if ( comp_func(list[i], list[i+1]) > 0 ) {
  378. var q = list[i]; list[i] = list[i+1]; list[i+1] = q;
  379. swap = true;
  380. }
  381. } // for
  382. t--;
  383.  
  384. if (!swap) break;
  385.  
  386. for(var i = t; i > b; --i) {
  387. if ( comp_func(list[i], list[i-1]) < 0 ) {
  388. var q = list[i]; list[i] = list[i-1]; list[i-1] = q;
  389. swap = true;
  390. }
  391. } // for
  392. b++;
  393.  
  394. } // while(swap)
  395. }
  396. }
  397.  
  398. /* ******************************************************************
  399. Supporting functions: bundled here to avoid depending on a library
  400. ****************************************************************** */
  401.  
  402. // Dean Edwards/Matthias Miller/John Resig
  403.  
  404. // Denilson has disabled the code below. I'm manually calling sorttable.init instead.
  405. // // for Mozilla/Opera9
  406. // if (document.addEventListener) {
  407. // document.addEventListener("DOMContentLoaded", sorttable.init, false);
  408. // }
  409. //
  410. // // for Internet Explorer
  411. // // Removed
  412. //
  413. // // for Safari
  414. // if (/WebKit/i.test(navigator.userAgent)) { // sniff
  415. // var _timer = setInterval(function() {
  416. // if (/loaded|complete/.test(document.readyState)) {
  417. // sorttable.init(); // call the onload handler
  418. // }
  419. // }, 10);
  420. // }
  421. //
  422. // // for other browsers
  423. // //window.onload = sorttable.init;
  424.  
  425.  
  426. // written by Dean Edwards, 2005
  427. // with input from Tino Zijdel, Matthias Miller, Diego Perini
  428.  
  429. // http://dean.edwards.name/weblog/2005/10/add-event/
  430.  
  431. function dean_addEvent(element, type, handler) {
  432. if (element.addEventListener) {
  433. element.addEventListener(type, handler, false);
  434. } else {
  435. // assign each event handler a unique ID
  436. if (!handler.$$guid) handler.$$guid = dean_addEvent.guid++;
  437. // create a hash table of event types for the element
  438. if (!element.events) element.events = {};
  439. // create a hash table of event handlers for each element/event pair
  440. var handlers = element.events[type];
  441. if (!handlers) {
  442. handlers = element.events[type] = {};
  443. // store the existing event handler (if there is one)
  444. if (element["on" + type]) {
  445. handlers[0] = element["on" + type];
  446. }
  447. }
  448. // store the event handler in the hash table
  449. handlers[handler.$$guid] = handler;
  450. // assign a global event handler to do all the work
  451. element["on" + type] = handleEvent;
  452. }
  453. };
  454. // a counter used to create unique IDs
  455. dean_addEvent.guid = 1;
  456.  
  457. function removeEvent(element, type, handler) {
  458. if (element.removeEventListener) {
  459. element.removeEventListener(type, handler, false);
  460. } else {
  461. // delete the event handler from the hash table
  462. if (element.events && element.events[type]) {
  463. delete element.events[type][handler.$$guid];
  464. }
  465. }
  466. };
  467.  
  468. function handleEvent(event) {
  469. var returnValue = true;
  470. // grab the event object (IE uses a global event object)
  471. event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
  472. // get a reference to the hash table of event handlers
  473. var handlers = this.events[event.type];
  474. // execute each event handler
  475. for (var i in handlers) {
  476. this.$$handleEvent = handlers[i];
  477. if (this.$$handleEvent(event) === false) {
  478. returnValue = false;
  479. }
  480. }
  481. return returnValue;
  482. };
  483.  
  484. function fixEvent(event) {
  485. // add W3C standard event methods
  486. event.preventDefault = fixEvent.preventDefault;
  487. event.stopPropagation = fixEvent.stopPropagation;
  488. return event;
  489. };
  490. fixEvent.preventDefault = function() {
  491. this.returnValue = false;
  492. };
  493. fixEvent.stopPropagation = function() {
  494. this.cancelBubble = true;
  495. };
  496.  
  497. // Denilson has moved "Dean's forEach" to the top of the script
  498.  
  499. // End of code from sorttable.js
  500. //////////////////////////////////////////////////////////////////////
  501.  
  502.  
  503.  
  504.  
  505. (function() {
  506.  
  507. // Configuration
  508.  
  509. // Colors:
  510. var table_head_bg="#525d76";
  511. var table_head_fg="white";
  512.  
  513. var table_row0_bg="#d6d7e9"; // Old 1.0 color: #ffffff
  514. var table_row0_fg="black";
  515. var table_row1_bg="#eaebff"; // Old 1.0 color: #d6d7e9
  516. var table_row1_fg="black";
  517.  
  518. var table_row0_hover_bg="white";
  519. var table_row0_hover_fg="black";
  520. var table_row1_hover_bg="white";
  521. var table_row1_hover_fg="black";
  522.  
  523. var table_border="black";
  524. var td_border="#AAA";
  525.  
  526. var pre_bg="#eaebff";
  527. var pre_fg="black";
  528. var pre_border="black";
  529.  
  530. //
  531. // DO NOT EDIT BELOW THIS LINE!
  532. //
  533.  
  534. // Handy function
  535. function getInnerText(el) {
  536. var s='';
  537. for(var i=0,node; node=el.childNodes[i]; i++) {
  538. if (node.nodeType == 1) s += getInnerText(node);
  539. else if (node.nodeType == 3) s += node.nodeValue;
  540. }
  541. return s;
  542. }
  543.  
  544. // Main code below
  545. var head=document.getElementsByTagName('head')[0];
  546. if(head) {
  547. // Adding the style sheet
  548. var style=document.createElement('style');
  549. style.setAttribute('type','text/css');
  550. style.appendChild(document.createTextNode(
  551. 'html,body { background: white; color: black; padding: 0; margin: 0;}\n'+
  552. 'body { padding: 1em; }\n'+
  553. 'pre { border: 2px solid '+pre_border+'; padding: 1ex; margin: 1em 0; background: '+pre_bg+'; color: '+pre_fg+'; }\n'+
  554. 'table { border: 2px solid '+table_border+'; border-collapse: collapse; margin: 1em 0; }\n'+
  555. 'td,th { border: 1px solid '+td_border+'; border-width: 0 1px; padding: 0.1em 0.5ex; white-space: nowrap; }\n'+
  556. 'th { background: '+table_head_bg+'; color: '+table_head_fg+'; text-align: center; font-weight: bold; }\n'+
  557. '#connectionsheadtable th { background: transparent; color: inherit; text-align: right; font-weight: bold; }\n'+
  558. '#scoreboardtable th { background: transparent; color: inherit; text-align: center; font-weight: bold; }\n'+
  559. '#scoreboardtable, #connectionsheadtable { float: left; margin: 0 1em 0 0;}\n'+
  560. 'hr { float: none; clear: both; }\n'+
  561. 'tr:nth-child(even) { background: '+table_row0_bg+'; color: '+table_row0_fg+'; }\n'+
  562. 'tr:nth-child(odd) { background: '+table_row1_bg+'; color: '+table_row1_fg+'; }\n'+
  563. 'tr:nth-child(even):hover { background: '+table_row0_hover_bg+'; color: '+table_row0_hover_fg+'; }\n'+
  564. 'tr:nth-child(odd):hover { background: '+table_row1_hover_bg+'; color: '+table_row1_hover_fg+'; }\n'
  565. ));
  566. head.appendChild(style);
  567.  
  568. // Naming some tables (putting IDs)
  569. var tables=document.getElementsByTagName('table');
  570. // I will suppose I will get two tables
  571. tables[0].setAttribute('id','connectionstable');
  572. var connectionstable=tables[0];
  573. tables[1].setAttribute('id','connectionsheadtable');
  574. var connectionsheadtable=tables[1];
  575. tables=false;
  576.  
  577. // Removing incorrect P element. (it is written <p />
  578. // at source, it was supposed to be a close-tag, I guess)
  579. var temp=document.getElementsByTagName('p');
  580. if( temp.length==2 ) {
  581. temp=temp[1];
  582. while( temp.hasChildNodes() ) {
  583. temp.parentNode.insertBefore(temp.childNodes[0],temp);
  584. }
  585. temp.parentNode.removeChild(temp);
  586. }
  587.  
  588. // Removing an HR element between the two tables
  589. var temp=connectionsheadtable;
  590. do{
  591. temp=temp.previousSibling;
  592. }while( temp && temp.nodeType!=1);
  593. // Firefox bug: Node.ELEMENT_NODE is not defined when this script is run.
  594. // Node, however, is already a Node object.
  595. // http://www.mozdev.org/bugs/show_bug.cgi?id=13193
  596. //while( temp && temp.nodeType!=Node.ELEMENT_NODE);
  597. if( temp && temp.tagName.toLowerCase() == 'hr' )
  598. temp.parentNode.removeChild(temp);
  599.  
  600. // Trying to style each column separately
  601. var firstchild=connectionstable.firstChild;
  602. var connectionstablecolumns=new Array();
  603. for( var i = 0; i < 13; i++ ) {
  604. var temp=document.createElement('colgroup');
  605. connectionstablecolumns[i]=temp;
  606. connectionstable.insertBefore(temp,firstchild);
  607. }
  608. connectionstablecolumns[0].setAttribute('align','left'); // Srv
  609. connectionstablecolumns[1].setAttribute('align','right'); // PID
  610. connectionstablecolumns[2].setAttribute('align','center'); // Acc
  611. connectionstablecolumns[3].setAttribute('align','center'); // M
  612. connectionstablecolumns[4].setAttribute('align','right'); // CPU
  613. connectionstablecolumns[5].setAttribute('align','right'); // SS
  614. connectionstablecolumns[6].setAttribute('align','right'); // Req
  615. connectionstablecolumns[7].setAttribute('align','right'); // Conn
  616. connectionstablecolumns[8].setAttribute('align','right'); // Child
  617. connectionstablecolumns[9].setAttribute('align','right'); // Slot
  618. connectionstablecolumns[10].setAttribute('align','right'); // Client
  619. connectionstablecolumns[11].setAttribute('align','center'); // VHost
  620. connectionstablecolumns[12].setAttribute('align','left'); // Request
  621.  
  622. // Creating/getting the THEAD and TFOOT
  623. var connectionstablethead=connectionstable.getElementsByTagName('thead')[0];
  624. if(!connectionstablethead) {
  625. connectionstablethead=document.createElement('thead');
  626. connectionstable.insertBefore(connectionstablethead,firstchild);
  627. }
  628. var connectionstabletfoot=connectionstable.getElementsByTagName('tfoot')[0];
  629. if(!connectionstabletfoot) {
  630. connectionstabletfoot=document.createElement('tfoot');
  631. connectionstable.insertBefore(connectionstabletfoot,firstchild);
  632. }
  633. // Moving headers to THEAD
  634. connectionstablethead.appendChild(connectionstable.getElementsByTagName('tr')[0]);
  635. // Copying headers to TFOOT
  636. connectionstabletfoot.appendChild(connectionstablethead.firstChild.cloneNode(true));
  637. // Making it sortable
  638. connectionstable.setAttribute('class', 'sortable');
  639.  
  640. // Transforming a paragraph in a table
  641. var scoreboardtable=false;
  642. var scoreboard=connectionstable;
  643. do{
  644. scoreboard=scoreboard.previousSibling;
  645. }while( scoreboard && scoreboard.nodeType!=1);
  646. // Firefox bug: Node.ELEMENT_NODE is not defined when this script is run.
  647. // Node, however, is already a Node object.
  648. // http://www.mozdev.org/bugs/show_bug.cgi?id=13193
  649. //while( scoreboard && scoreboard.nodeType!=Node.ELEMENT_NODE);
  650. if( scoreboard && scoreboard.tagName.toLowerCase() == 'p' ) {
  651.  
  652. var text=getInnerText(scoreboard);
  653.  
  654. text=text.replace(/^[^:]+:/,'');
  655. text=text.replace(/[\r\n]/g,'');
  656.  
  657. var elements=text.split(',');
  658.  
  659. var scoreboardtable=document.createElement('table');
  660. var tbody=document.createElement('tbody');
  661. scoreboardtable.appendChild(tbody);
  662. scoreboardtable.setAttribute('id','scoreboardtable');
  663. var regex=new RegExp('');
  664. regex.compile('"(.)" +(.*[^ ]) *');
  665. for(var i=0, s; s=elements[i]; i++) {
  666. var tr=document.createElement('tr');
  667. var th=document.createElement('th');
  668. var td=document.createElement('td');
  669. regex.exec(s);
  670. th.appendChild(document.createTextNode(RegExp.$1));
  671. td.appendChild(document.createTextNode(RegExp.$2));
  672. tr.appendChild(th);
  673. tr.appendChild(td);
  674. tbody.appendChild(tr);
  675. }
  676. scoreboard.parentNode.insertBefore(scoreboardtable,connectionsheadtable);
  677. scoreboard.parentNode.removeChild(scoreboard);
  678. }
  679.  
  680. // Finally, calling sorttable.init()
  681. sorttable.init();
  682. }
  683. })();