Virtual Manager Stat-sum

Giver summen af stats'ne for hver spiller.

  1. // ==UserScript==
  2. // @name Virtual Manager Stat-sum
  3. // @namespace http://www.mathemaniac.org
  4. // @description Giver summen af stats'ne for hver spiller.
  5. // @include http://www.virtualmanager.com/player/index.php*
  6. // @version 0.0.1.20140827095732
  7. // ==/UserScript==
  8.  
  9. (function(){
  10. var totalSum = GM_getValue('totalSum',1);
  11. GM_registerMenuCommand('Vis sum af alle stats ['+(totalSum > 0 ? 'x' : ' ')+']', function() {
  12. GM_setValue('totalSum',GM_getValue('totalSum',1) ? 0 : 1);
  13. window.location.reload();
  14. });
  15. var delSum = GM_getValue('delSum',1);
  16. GM_registerMenuCommand('Vis delsum af hver stat-gruppe ['+(delSum > 0 ? 'x' : ' ')+']', function() {
  17. GM_setValue('delSum',GM_getValue('delSum',1) ? 0 : 1);
  18. window.location.reload();
  19. });
  20.  
  21. if (totalSum || delSum) {
  22. var delSummer = Array(0,0,0);
  23. var i=0;
  24. var it = document.evaluate('//div[@class="box" and descendant::h2[text()="Egenskaber"]]//td[contains(@class,"right")]//span/text()', document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
  25. var stat;
  26. while (stat = it.iterateNext()) {
  27. delSummer[i++ % 3]+=parseInt(stat.nodeValue);
  28. }
  29. if (delSum) {
  30. var statTable = document.evaluate('//div[@class="box" and descendant::h2[text()="Egenskaber"]]//table', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
  31. var delSumTR = document.createElement('tr');
  32. for(var j=0; j<3; j++) {
  33. var delSumTDTitel = document.createElement('td');
  34. delSumTDTitel.setAttribute('style','font-weight: bold; background-color: #20882D; color: #FFF');
  35. delSumTDTitel.appendChild(document.createTextNode('Sum'));
  36. delSumTR.appendChild(delSumTDTitel);
  37. var delSumTDValue = document.createElement('td');
  38. delSumTDValue.setAttribute('style','font-weight: bold; background-color: #20882D; color: #FFF;');
  39. delSumTDValue.className = 'right';
  40. delSumTDValue.appendChild(document.createTextNode(delSummer[j]));
  41. delSumTR.appendChild(delSumTDValue);
  42. }
  43. statTable.appendChild(delSumTR);
  44. }
  45. if (totalSum) {
  46. var overskrift = document.evaluate('//h2[text()="Egenskaber"]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
  47. overskrift.appendChild(document.createTextNode(" [Sum: "+(delSummer[0]+delSummer[1]+delSummer[2])+"]"));
  48. }
  49. }
  50. })();