Nexus Clash Stat Bars Alternative Version

Adds bars to AP HP and MP

  1. // ==UserScript==
  2. // @name Nexus Clash Stat Bars Alternative Version
  3. // @namespace http://userscripts.org/users/125692
  4. // @description Adds bars to AP HP and MP
  5. // @include http://nexusclash.com/modules.php?name=Game*
  6. // @include http://www.nexusclash.com/modules.php?name=Game*
  7. // @grant GM_getValue
  8. // @grant GM_setValue
  9. // @grant GM_addStyle
  10. // @version 1.08
  11. // ==/UserScript==
  12. //for nexus clash. this script
  13. // adds coloured bars to under AP/HP/MP to provide visual referenece to depletion of these stats.
  14. //1.01 - changed to math.round from parseInt for negligible increase in accuracy
  15. //1.02 - added border to bars
  16. //1.03 - added colour change for when over max
  17. //1.04 - handles negative stats properly now.
  18. //1.05 - this version has differing colors for the bars so make it easier to distinguish at a glance
  19. //1.06 - add try catch to chrome test
  20.  
  21. try{
  22. if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
  23. this.GM_getValue=function (key,def) {
  24. return localStorage[key] || def;
  25. };
  26. this.GM_setValue=function (key,value) {
  27. return localStorage[key]=value;
  28. };
  29. this.GM_deleteValue=function (key) {
  30. return delete localStorage[key];
  31. };
  32. }
  33. } catch (err) { console.log('Test if GM_getValue supported error:\n' + err.message); }
  34.  
  35. //check if start screen and store max values.
  36. var isstart = document.evaluate(
  37. "//h2[starts-with(.,'Welcome back to Nexus Clash!')]",
  38. document,
  39. null,
  40. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  41. null);
  42.  
  43. if (isstart.snapshotLength == 1) {
  44. //we on start screen.
  45. //Store max ap/hp/mp values.
  46. var charlinks = document.evaluate(
  47. "//a[starts-with(@href,'modules.php?name=Game&op=character&id=')]",
  48. document,
  49. null,
  50. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  51. null );
  52. var charid;
  53. var charmaxhp=0;
  54. var charmaxap=0;
  55. var charmaxmp=0;
  56. if (charlinks.snapshotLength > 1) {//found some charlinks
  57. var charlink=0;
  58. for (i=0;charlink=charlinks.snapshotItem(i);i++){
  59. //alert(i);
  60. charid=charlink.href.match(/id=(\d+)/)[1];
  61. charlink=charlink.parentNode.nextElementSibling.nextElementSibling;
  62. charmaxap=charlink.textContent.match(/\/(\d+)/)[1];
  63. charlink=charlink.nextElementSibling;
  64. charmaxhp=charlink.textContent.match(/\/(\d+)/)[1];
  65. charlink=charlink.nextElementSibling;
  66. charmaxmp=charlink.textContent.match(/\/(\d+)/)[1];
  67. //now store 'em away
  68. GM_setValue("maxap"+charid,charmaxap);
  69. GM_setValue("maxhp"+charid,charmaxhp);
  70. GM_setValue("maxmp"+charid,charmaxmp);
  71. }
  72. }
  73. return; //as that is all we want to do as we are on the start screen
  74. }
  75.  
  76.  
  77. //we not on start screen so we probably in game so apply rest of script.
  78. //add styles
  79. GM_addStyle(".barap{height:10px;background-color:#84f084;border-top:1px solid #000000;}");//COLOUR FOR BACKGROUND OF AP BAR ##0000ff is blue
  80. GM_addStyle(".barhp{height:10px;background-color:#ff0000;border-top:1px solid #000000;}"); //COLOUR FOR BACKGROUND OF HP BAR ##FF0000 is red
  81. GM_addStyle(".barmp{height:10px;background-color:#99d9ea;border-top:1px solid #000000;}");//COLOUR FOR BACKGROUND OF MP BAR ##8000ff is purple
  82. GM_addStyle(".barslider{height:9px;position:absolute;left:0px;background-color:#008800;}");// SET COLOUR FOR FOREGROUND OF BAR 00ff00 is green
  83. GM_addStyle(".statbardiv{width:100%;position:absolute;top:19px;bottom:0px;left:0px;right:0px;}");
  84. GM_addStyle(".bartd{position:relative;}");
  85.  
  86. var OVERMAXCOLOUR="#0000FF";//colour to make bar for when over max
  87.  
  88.  
  89. //ADD COLOUR BARS TO AP/HP/MP
  90. if(document.getElementById("CharacterInfo")){
  91.  
  92. var charinfodiv=document.getElementById("CharacterInfo");
  93. var charlinks = document.evaluate(
  94. ".//a[starts-with(@href,'modules.php?name=Game&op=character&id=')]",
  95. charinfodiv,
  96. null,
  97. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  98. null );
  99. var charid=0;
  100. if (charlinks.snapshotLength==1){
  101. charid=charlinks.snapshotItem(0).href.match(/id=(\d+)/)[1];
  102. }
  103. var charmax = new Array();//lol at this way. makes code a bit shorter in for
  104. charmax[0]=GM_getValue("maxap"+charid,0);
  105. charmax[1]=GM_getValue("maxhp"+charid,0);
  106. charmax[2]=GM_getValue("maxmp"+charid,0);
  107. //alert("heh");
  108. if (charmax[0]&&charmax[1]&&charmax[2]){//only if all are true(ie we got a proper value)
  109. for(i=0;i<3;i++){//for each stat add bar
  110. var statbardiv=document.createElement('div');
  111. var backdiv=document.createElement('div');
  112. var frontdiv=document.createElement('div');
  113. statbardiv.className="statbardiv";
  114. backdiv.className = i==0?"barap":i==1?"barhp":"barmp";
  115. frontdiv.className="barslider";
  116. var font=charinfodiv.getElementsByTagName("font")[i];//get font
  117. charstat=font.innerHTML.match(/-?\d+/); //get ap/hp/mp and if -ve
  118. if(i==1){//the hp doesn't refill automatically most of the time.
  119. backdiv.title=charstat+"/"+charmax[i]+" Need "+
  120. (Number(charmax[i])-Number(charstat))+"hp healed";
  121. }
  122. else{// for ap and mp
  123. backdiv.title = charstat+"/"+charmax[i]+" Full in "+
  124. (Number(charmax[i])-Number(charstat))/4+" hours";//assume ap/mp +1 per tick
  125. }
  126.  
  127. var frontwidth=Math.round(100*(Number(charstat)/Number(charmax[i])));
  128. if (frontwidth>100){//for some reason we over max
  129. frontwidth=100;
  130. frontdiv.style.backgroundColor=OVERMAXCOLOUR;//set to blue to signify over max
  131. }
  132. else if (frontwidth<0){//for some reason we at -ve values
  133. frontwidth=0;
  134. }
  135. frontdiv.style.width=""+frontwidth+"%";//Doing it as %;
  136. frontdiv.title=charstat+"/"+charmax[i];
  137. //alert('here');
  138. var hptd = charinfodiv.getElementsByTagName("td")[i+2];
  139. hptd.className='bartd';
  140. backdiv.appendChild(frontdiv);
  141. statbardiv.appendChild(backdiv);
  142. hptd.appendChild(statbardiv);
  143. }
  144. }
  145. }