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.3
  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. if(window.location.href.match(/name=Game&op=faction&do=roster$/)){
  21. characterlinks = document.evaluate(
  22. "//a[starts-with(@href,'modules.php?name=Game&op=character&id=')]",
  23. document,
  24. null,
  25. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  26. null
  27. );
  28. //alert("running");
  29. if (characterlinks.snapshotLength>0){
  30. //alert(characterlinks.snapshotLength);
  31. for(i=0;characterlink=characterlinks.snapshotItem(i);i++){
  32. charid=characterlink.href.match(/\d+$/);
  33. //charid='#'+charid+"#";//non fixed length number needs to be made unique.
  34. charclass=characterlink.parentNode.nextElementSibling.nextElementSibling.textContent;
  35. //alert(charid+":"+charclass);
  36. GM_setValue(''+charid,charclass);
  37. }
  38. }
  39. }
  40. else if(window.location.href.match(/name=Game&op=character&id=/)){
  41. //we are at a character page. Might as well take the id and the highest class.
  42. //as the class line has the undelimited class plus previous classes we instead look for the class headings and take from there
  43. //<a href="wiki/index.php/Eternal Soldier">
  44. //<b>Eternal Soldier</b>
  45. //</a>
  46. characterlinks = document.evaluate(
  47. "//a[starts-with(@href,'wiki/index.php/')]",
  48. document,
  49. null,
  50. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  51. null
  52. );
  53. if (characterlinks.snapshotLength>0){
  54. charid=window.location.href.match(/\d+$/);
  55. if (!isNaN(charid)){
  56. //class we want is the last in the list
  57. charpagemaxtier=characterlinks.snapshotLength-1;//2 here equals t3
  58. //if (characterlinks.snapshotItem(1).href.match(/wiki\/index.php\/$/)){//if no t2 then set to t1
  59. // charpagemaxtier=0;//no t2 means we are a mortal.
  60. //}
  61. //else if(characterlinks.snapshotItem(2).href.match(/wiki\/index.php\/$/)){//if no t3 then set to t2
  62. // charpagemaxtier=1;//1 is t2
  63. //}
  64. while(characterlinks.snapshotItem(charpagemaxtier).href.match(/wiki\/index.php\/$/)&&charpagemaxtier>0){
  65. charpagemaxtier-=1;
  66. }
  67. charclass=characterlinks.snapshotItem(charpagemaxtier).firstElementChild.textContent;// text of the <b> child node
  68. if (charclass!=""){
  69. GM_setValue(''+charid,charclass);
  70. }
  71. }
  72. }
  73. //while we are on the character page we ought to set a button and store away the settings.
  74. //either we have character class as text inline or we set as title text.
  75. var anewdiv=document.createElement('div');
  76. var anewp=document.createElement('p');
  77. var anewform=document.createElement('form');
  78. var radbut1=document.createElement('input');
  79. var radbut1text=document.createTextNode("As inline text");
  80. var radbut2=document.createElement('input');
  81. var radbut2text=document.createTextNode("As mouse over text");
  82. var brtag=document.createElement('br');
  83. anewp.textContent="Set the display type for Nexus Clash Display Known Classes";
  84. radbut1.name="classlistsetting";
  85. radbut1.value="inline";
  86. radbut1.type='radio';
  87. radbut2.name="classlistsetting";
  88. radbut2.value="titletext";
  89. radbut2.type='radio';
  90. //radbut1.appendChild(radbut1text);
  91. //radbut2.appendChild(radbut2text);
  92. anewdiv.style="background-color:lightgrey";
  93. //anewdiv.style="display:inline-block";
  94. anewform.insertBefore(radbut2,anewform.lastElementChild);
  95. anewform.insertBefore(radbut1,anewform.lastElementChild);
  96. anewform.insertBefore(brtag,anewform.lastElementChild);
  97. anewform.insertBefore(radbut1text,radbut1.nextElementSibling);
  98. anewform.insertBefore(radbut2text,radbut2.nextElementSibling);
  99. anewdiv.insertBefore(anewform,anewdiv.firstElementChild);
  100. anewdiv.insertBefore(anewp,anewdiv.firstElementChild);
  101. currentsetting=GM_getValue('textsetting','');
  102. if (currentsetting=='titletext'){
  103. radbut2.checked=true;
  104. }
  105. else if (currentsetting==""){
  106. GM_setValue('textsetting','inline');
  107. currentsetting='inline';
  108. radbut1.checked=true;
  109. }
  110. else {
  111. radbut1.checked=true;
  112. }
  113. var setevent=function(e) {
  114. var ebutton=e.target;
  115. GM_setValue('textsetting',ebutton.value);
  116. }
  117. //value="Visit User Profile"
  118. characterlinks = document.evaluate(
  119. // "//input[starts-with(@value,'Visit User Profile')]",
  120. "//body",
  121. document,
  122. null,
  123. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  124. null
  125. );
  126. if (characterlinks.snapshotLength>0){
  127. characterlinks.snapshotItem(0).insertBefore(anewdiv,characterlinks.snapshotItem(0).lastElementChild);
  128. radbut1.addEventListener("click",setevent,true);
  129. radbut2.addEventListener("click",setevent,true);
  130. }
  131. }
  132. 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.
  133. //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.
  134. //<a href="javascript:SelectItem('target_id','996')" class="faction">a playful otter </a>
  135. characterlinks = document.evaluate(
  136. "//a[starts-with(@href,'javascript:SelectItem')]",
  137. document,
  138. null,
  139. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  140. null
  141. );
  142. //alert("running");
  143. if (characterlinks.snapshotLength>0){
  144. //get setting
  145. currentsetting=GM_getValue('textsetting','');
  146. if (currentsetting==""){
  147. GM_setValue('textsetting','inline');
  148. currentsetting='inline';
  149. }
  150. //alert(characterlinks.snapshotLength);
  151. for(i=0;characterlink=characterlinks.snapshotItem(i);i++){
  152. charid=characterlink.href.match(/\d+/);
  153. //charid='#'+charid+"#";//non fixed length number needs to be made unique.
  154. charclass = GM_getValue(""+charid,"");
  155. if(charclass!=""){
  156. if(currentsetting=='inline'){
  157. GM_addStyle("A.classlevel{color:#666666;}");
  158. //charclass=charclass[0].match(/[AEIOU]/)?", an "+charclass:", a "+charclass; // and a or an
  159. characterlink.nextElementSibling.textContent=charclass+"-"+characterlink.nextElementSibling.textContent;
  160. characterlink.nextElementSibling.className='classlevel';
  161. }
  162. else{
  163. characterlink.nextElementSibling.title=charclass;
  164. }
  165. }
  166. }
  167. }
  168. }