Nexus Clash Display Known Classes

Stores some known character classes and adds then to Game interface.

当前为 2015-11-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Nexus Clash Display Known Classes
  3. // @namespace http://userscripts.org/users/125692
  4. // @description Stores some known character classes and adds then to Game interface.
  5. // @include http://nexusclash.com/modules.php?name=Game*
  6. // @include http://www.nexusclash.com/modules.php?name=Game*
  7. // @exclude http://nexusclash.com/modules.php?name=Game&op=disconnect
  8. // @exclude http://www.nexusclash.com/modules.php?name=Game&op=disconnect
  9. // @version 1.4
  10. // @grant GM_setValue
  11. // @grant GM_getValue
  12. // @grant GM_addStyle
  13. // ==/UserScript==
  14. var characterlinks;
  15. var characterlink;
  16. var charid;
  17. var charclass;
  18. var charpagemaxtier;
  19. var currentsetting;
  20. var attacksetting;
  21. if(window.location.href.match(/name=Game&op=faction&do=roster$/)){
  22. characterlinks = document.evaluate(
  23. "//a[starts-with(@href,'modules.php?name=Game&op=character&id=')]",
  24. document,
  25. null,
  26. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  27. null
  28. );
  29. //alert("running");
  30. if (characterlinks.snapshotLength>0){
  31. //alert(characterlinks.snapshotLength);
  32. for(i=0;characterlink=characterlinks.snapshotItem(i);i++){
  33. charid=characterlink.href.match(/\d+$/);
  34. //charid='#'+charid+"#";//non fixed length number needs to be made unique.
  35. charclass=characterlink.parentNode.nextElementSibling.nextElementSibling.textContent;
  36. //alert(charid+":"+charclass);
  37. GM_setValue(''+charid,charclass);
  38. }
  39. }
  40. }
  41. else if(window.location.href.match(/name=Game&op=character&id=/)){
  42. //we are at a character page. Might as well take the id and the highest class.
  43. //as the class line has the undelimited class plus previous classes we instead look for the class headings and take from there
  44. //<a href="wiki/index.php/Eternal Soldier">
  45. //<b>Eternal Soldier</b>
  46. //</a>
  47. characterlinks = document.evaluate(
  48. "//a[starts-with(@href,'wiki/index.php/')]",
  49. document,
  50. null,
  51. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  52. null
  53. );
  54. if (characterlinks.snapshotLength>0){
  55. charid=window.location.href.match(/\d+$/);
  56. if (!isNaN(charid)){
  57. //class we want is the last in the list
  58. charpagemaxtier=characterlinks.snapshotLength-1;//2 here equals t3
  59. while(characterlinks.snapshotItem(charpagemaxtier).href.match(/wiki\/index.php\/$/)&&charpagemaxtier>0){
  60. charpagemaxtier-=1;
  61. }
  62. charclass=characterlinks.snapshotItem(charpagemaxtier).firstElementChild.textContent;// text of the <b> child node
  63. if (charclass!=""){
  64. GM_setValue(''+charid,charclass);
  65. }
  66. }
  67. }
  68. //while we are on the character page we ought to set a button and store away the settings.
  69. //either we have character class as text inline or we set as title text.
  70. var anewdiv=document.createElement('div');
  71. var anewp=document.createElement('p');
  72. var anewform=document.createElement('form');
  73. var radbut1=document.createElement('input');
  74. var radbut1text=document.createTextNode("As inline text");
  75. var radbut2=document.createElement('input');
  76. var radbut2text=document.createTextNode("As mouse over text");
  77. var brtag=document.createElement('br');
  78. var checkbox1=document.createElement('input');
  79. var checkbox1text=document.createTextNode("List known classes in attack dropdown");
  80. anewp.textContent="Set the display type for Nexus Clash Display Known Classes";
  81. radbut1.name="classlistsetting";
  82. radbut1.value="inline";
  83. radbut1.type='radio';
  84.  
  85. radbut2.name="classlistsetting";
  86. radbut2.value="titletext";
  87. radbut2.type='radio';
  88. checkbox1.name="attackdropdownsetting";
  89. checkbox1.value='showclass4attack';
  90. checkbox1.type='checkbox';
  91. anewdiv.style="background-color:lightgrey";
  92. //anewdiv.style="display:inline-block";
  93. anewform.insertBefore(checkbox1,anewform.lastElementChild);//this ends up last
  94. anewform.insertBefore(radbut2,anewform.lastElementChild);//then this before
  95. anewform.insertBefore(radbut1,anewform.lastElementChild);//then this ends up on top.
  96. anewform.insertBefore(brtag,anewform.lastElementChild);
  97. anewform.insertBefore(radbut1text,radbut1.nextElementSibling);
  98. anewform.insertBefore(radbut2text,radbut2.nextElementSibling);
  99. anewform.insertBefore(checkbox1text,checkbox1.nextElementSibling);
  100. anewdiv.insertBefore(anewform,anewdiv.firstElementChild);
  101. anewdiv.insertBefore(anewp,anewdiv.firstElementChild);
  102. // anewdiv.appendChild(checkbox1);//,anewdiv.lastElementChild);
  103.  
  104. //get setting for whether to show class info in attack dropdown.
  105. attacksetting=GM_getValue('attacksetting',false);
  106. if (attacksetting){
  107. checkbox1.checked=true;
  108. }
  109. else {
  110. checkbox1.checked=false;
  111. }
  112. //get the current description pane setting (or set it up if not already set)
  113. currentsetting=GM_getValue('textsetting','');
  114. if (currentsetting=='titletext'){
  115. radbut2.checked=true;
  116. }
  117. else if (currentsetting==""){
  118. GM_setValue('textsetting','inline');
  119. currentsetting='inline';
  120. radbut1.checked=true;
  121. }
  122. else {
  123. radbut1.checked=true;
  124. }
  125. //this event for the sett whether show class in attack dropdown
  126. var setattack=function(e) {
  127. var ebutton=e.target;
  128. GM_setValue('attacksetting',ebutton.checked);
  129. }
  130. //this the event for toggling the display type in description pane
  131. var setevent=function(e) {
  132. var ebutton=e.target;
  133. GM_setValue('textsetting',ebutton.value);
  134. }
  135. //value="Visit User Profile"
  136. characterlinks = document.evaluate(
  137. //"//input[starts-with(@value,'Visit User Profile')]",
  138. "//body",
  139. document,
  140. null,
  141. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  142. null
  143. );
  144. if (characterlinks.snapshotLength>0){
  145. characterlinks.snapshotItem(0).insertBefore(anewdiv,characterlinks.snapshotItem(0).lastElementChild);
  146. radbut1.addEventListener("click",setevent,true);
  147. radbut2.addEventListener("click",setevent,true);
  148. checkbox1.addEventListener("change",setattack,false);
  149. }
  150. }
  151. else{//if not on roster page storing the class value maybe we are on the game page and we ought to add the class names.
  152. //we want this link type and we want to grab the id number. gm_getvalue the class and then add it and a comma after the name.
  153. //<a href="javascript:SelectItem('target_id','996')" class="faction">a playful otter </a>
  154. characterlinks = document.evaluate(
  155. "//a[starts-with(@href,'javascript:SelectItem')]",
  156. document,
  157. null,
  158. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  159. null
  160. );
  161. //alert("running");
  162. if (characterlinks.snapshotLength>0){
  163. //get setting
  164. currentsetting=GM_getValue('textsetting','');
  165. if (currentsetting==""){
  166. GM_setValue('textsetting','inline');
  167. currentsetting='inline';
  168. }
  169. //alert(characterlinks.snapshotLength);
  170. for(i=0;characterlink=characterlinks.snapshotItem(i);i++){
  171. charid=characterlink.href.match(/\d+/);
  172. //charid='#'+charid+"#";//non fixed length number needs to be made unique.
  173. charclass = GM_getValue(""+charid,"");
  174. if(charclass!=""){
  175. if(currentsetting=='inline'){
  176. GM_addStyle("A.classlevel{color:#666666;}");
  177. //charclass=charclass[0].match(/[AEIOU]/)?", an "+charclass:", a "+charclass; // and a or an
  178. characterlink.nextElementSibling.textContent=charclass+"-"+characterlink.nextElementSibling.textContent;
  179. characterlink.nextElementSibling.className='classlevel';
  180. }
  181. else{
  182. characterlink.nextElementSibling.title=charclass;
  183. }
  184. }
  185. }
  186. }
  187. //now look to see if we have set to show in the attack dropdown and if so the list known classes there.
  188. attacksetting=GM_getValue('attacksetting',false);
  189. if(attacksetting){
  190. //<select id="combat_target_id" name="target_id">
  191. //<option value="996">a playful otter</option>
  192. //</select>
  193. characterlinks = document.evaluate(
  194. "//select[@id='combat_target_id']/option",
  195. document,
  196. null,
  197. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  198. null
  199. );
  200. if (characterlinks.snapshotLength>0){
  201. for(i=0;characterlink=characterlinks.snapshotItem(i);i++){
  202. charid=characterlink.value;
  203. charclass = GM_getValue(""+charid,"");
  204. if(charclass!=""){
  205. characterlink.textContent+=" - "+charclass;
  206. }
  207. }
  208. }
  209. }
  210. }