Nexus Clash Add Drop Item Safety Check Box

Make it a tad harder to drop things

  1. // ==UserScript==
  2. // @name Nexus Clash Add Drop Item Safety Check Box
  3. // @namespace http://userscripts.org/users/125692
  4. // @include http://nexusclash.com/modules.php?name=Game*
  5. // @include http://www.nexusclash.com/modules.php?name=Game*
  6. // @exclude http://nexusclash.com/modules.php?name=Game&op=disconnect
  7. // @exclude http://www.nexusclash.com/modules.php?name=Game&op=disconnect
  8. // @description Make it a tad harder to drop things
  9. // @grant none
  10. // @version 1.1.2
  11. // ==/UserScript==
  12. //for nexus clash. this script adds a checkbox for each drop button and disables the button until the checkbox is checked.
  13. (function() {
  14.  
  15. function addGlobalStyle(css,idname) {
  16. var head, style;
  17. head = document.getElementsByTagName('head')[0];
  18. if (!head) { return; }
  19. style = document.createElement('style');
  20. if(!(typeof idname === "undefined")){style.id=idname;}
  21. style.type = 'text/css';
  22. style.innerHTML = css;
  23. head.appendChild(style);
  24. }
  25.  
  26. addGlobalStyle('a.MageHide { display: none !important; }');
  27. addGlobalStyle('td.Magedropcell {position:relative;white-space: nowrap !important;overflow-x:visible;}');
  28. addGlobalStyle('td.MageNoWrap {white-space: nowrap !important;overflow-x:visible;}');
  29. addGlobalStyle('span.magedropboxdiv{position:absolute;padding:0px;}');
  30. addGlobalStyle('form.magedropcheckbox{position:relative;padding:0px 3px 0px 0px;top:-5px;vertical-align:middle;}');
  31. addGlobalStyle('a.magesmallerdroptext{font-size:smaller;}');
  32. var newbox;
  33. var acell;
  34. var loc=location+'';//lol cludgy
  35.  
  36. //1 - drop buttons
  37. //if (loc.match(/buyskills/)){
  38. //do the item drop first by assuming we are on the right page and just looking for things with the item_drop class
  39. var elementsDropButtons = document.getElementsByClassName('item_drop');
  40. if(elementsDropButtons.length>0){//skip if we have none
  41. var elementDropButton;
  42. var rchange=function(e) {
  43. var targetbutton=e.target.parentNode.previousElementSibling;
  44. if(e.target.checked){
  45. targetbutton.style.visibility='visible';
  46. }
  47. else{
  48. targetbutton.style.visibility='hidden';
  49. }
  50. }
  51. for (i=0;i<elementsDropButtons.length;i++){
  52. elementDropButton=elementsDropButtons[i];
  53. if (!elementDropButton.hasAttribute('mageconfirmflag')){//see if flag not set
  54. elementDropButton.setAttribute('mageconfirmflag',1);//set flag
  55. newbox=document.createElement('input');
  56. newboxdiv=document.createElement('span');//the containing div
  57. newboxdiv.className="magedropboxdiv";
  58. newbox.type='checkbox';
  59. newbox.checked=false;
  60. newbox.className='magedropcheckbox';
  61. newbox.addEventListener("click",rchange,false);
  62. acell=elementDropButton.parentNode;
  63. acell.className='Magedropcell';//set class for nowrap so doesn't fubar page
  64. //acell.align='left';
  65. newboxdiv.insertBefore(newbox,newboxdiv.firstChild);//appendChild(newbox);
  66. acell.insertBefore(newboxdiv,elementDropButton.nextElementSibling);
  67. elementDropButton.style.visibility='hidden';
  68. }
  69. }
  70. }
  71. //2 - learn spell gem buttons
  72. //now we do the spellgem learn buttons
  73. elementsDropButtons = document.getElementsByClassName('item_use');
  74. if(elementsDropButtons.length>0){
  75. // elementDropButton;
  76. var rchange=function(e) {
  77. var targetbutton=e.target.nextElementSibling;//button should be next element
  78. if(e.target.checked){
  79. targetbutton.style.visibility='visible';
  80. }
  81. else{
  82. targetbutton.style.visibility='hidden';
  83. }
  84. }
  85. for (i=0;i<elementsDropButtons.length;i++){
  86. elementDropButton=elementsDropButtons[i];
  87. if (!elementDropButton.innerHTML.match(/Learn/)){
  88. continue;
  89. }
  90. if (!elementDropButton.hasAttribute('mageconfirmflag')){//see if flag not set
  91. elementDropButton.setAttribute('mageconfirmflag',1);//set flag
  92. newbox=document.createElement('input');
  93. newbox.type='checkbox';
  94. newbox.checked=false;
  95. newbox.addEventListener("click",rchange,false);
  96. acell=elementDropButton.parentNode;
  97. //acell.className='MageNoWrap';//set class for nowrap so doesn't fubar page
  98. //acell.align='center';
  99. acell.insertBefore(newbox,elementDropButton);
  100. elementDropButton.style.visibility='hidden';
  101. }
  102. }
  103. }
  104.  
  105. //TWEAK 3- craft button safety
  106. //and now we do craft button
  107. //elementsDropButtons = document.getElementsByClassName('item_use');
  108. var elementsCraftButtons = document.getElementsByTagName('input');//get all input
  109. var elementCraftButton;
  110. var rchange2=function(e) {
  111. var targetbutton=e.target.nextElementSibling;//button should be next element
  112. if(e.target.checked){
  113. targetbutton.disabled=false;
  114. }
  115. else{
  116. targetbutton.disabled=true;
  117. }
  118. }
  119. for (i=0;i<elementsCraftButtons.length;i++){
  120. elementCraftButton=elementsCraftButtons[i];
  121. if (elementCraftButton.type!="submit"||elementCraftButton.value!="Craft"){//but sometimes isn't
  122. continue;//well we tried to find it but couldn't so abort it all.
  123. }
  124. if (!elementCraftButton.hasAttribute('mageconfirmflag')){//see if flag not set
  125. elementCraftButton.setAttribute('mageconfirmflag',1);//set flag
  126. var craftbox=document.createElement('input');
  127. craftbox.type='checkbox';
  128. craftbox.checked=false;
  129. craftbox.addEventListener("click",rchange2,false);
  130. acell=elementCraftButton.parentNode;
  131. //acell.className='MageNoWrap';//set class for nowrap so doesn't fubar page
  132. //acell.align='center';
  133. acell.insertBefore(craftbox,elementCraftButton);
  134. //elementCraftButton.style.display='None';
  135. //elementCraftButton.style.visibility='hidden';
  136. elementCraftButton.disabled=true;
  137. }
  138. }
  139. //}
  140.  
  141. //4-learn skill buttons
  142. //if on buy skills page;
  143. //var loc=location+'';//lol cludgy
  144. //well in any event check if we are on the buyskills page and add saftey boxs to skill buttons
  145. //if this works the above code really should have been avoided by having some kind of test i suppose.
  146. //TWEAK 4-learn skill buttons safeties
  147. //if on buy skills page;
  148. //var loc=location+'';//lol cludgy
  149. //well in any event check if we are on the buyskills page and add saftey boxs to skill buttons
  150. //if this works the above code really should have been avoided by having some kind of test i suppose.
  151. if (loc.match(/buyskills/)||loc.match(/executepurchase/)){
  152. var rskillchange=function(e) {
  153. var targetbutton=e.target.nextElementSibling;//button should be next element
  154. if(e.target.checked){
  155. targetbutton.disabled=false;
  156. }
  157. else{
  158. targetbutton.disabled=true;
  159. }
  160. }
  161. var elementsSkillButtons = document.getElementsByTagName('input')//get all input
  162. var elementSkillButton;
  163. for (i=0;i<elementsSkillButtons.length;i++){
  164. elementSkillButton=elementsSkillButtons[i];
  165. if (elementSkillButton.type!="submit"){//but sometimes isn't
  166. continue;//well we tried to find it but couldn't so abort it all.
  167. }
  168. if (!elementSkillButton.hasAttribute('mageconfirmflag')){//see if flag not set
  169. elementSkillButton.setAttribute('mageconfirmflag',1);//set flag
  170. //now check if we have a confirm button and if so make it red
  171. if (elementSkillButton.value.match(/Confirm/)){
  172. elementSkillButton.style.color='red'//make it red to hightlight it
  173. }//'Confirm (10 CP)'
  174. newbox=document.createElement('input');
  175. newbox.type='checkbox';
  176. newbox.checked=false;
  177. newbox.addEventListener("click",rskillchange,false);
  178. acell=elementSkillButton.parentNode;
  179. //acell.className='MageNoWrap';//set class for nowrap so doesn't fubar page
  180. //acell.align='left';
  181. acell.insertBefore(newbox,elementSkillButton);
  182. //elementDropButton.style.display='None';
  183. //elementDropButton.style.visibility='hidden';
  184. elementSkillButton.disabled=true;
  185. }
  186. }
  187. }
  188. //5-leave faction button
  189. //or perhaps we are viewing the faction page
  190. else if (loc.match(/faction&do=view/)){//viewing faction page
  191. var elementsSkillButtons = document.getElementsByTagName('input')//get all input
  192. var elementSkillButton;
  193. var rfactionchange=function(e) {
  194. var targetbutton=e.target.nextElementSibling;//button should be next element
  195. if(e.target.checked){
  196. targetbutton.disabled=false;
  197. }
  198. else{
  199. targetbutton.disabled=true;
  200. }
  201. }
  202. for (i=0;i<elementsSkillButtons.length;i++){
  203. elementSkillButton=elementsSkillButtons[i];
  204. if (elementSkillButton.type!="submit"){//but sometimes isn't
  205. continue;//well we tried to find it but couldn't so abort it all.
  206. }
  207. if (!elementSkillButton.hasAttribute('mageconfirmflag')){//see if flag not set
  208. elementSkillButton.setAttribute('mageconfirmflag',1);//set flag
  209. if (elementSkillButton.value=="Leave Faction"){//just do the one button here. very ineffiecent code i think
  210. newbox=document.createElement('input');
  211. newbox.type='checkbox';
  212. newbox.checked=false;
  213. newbox.addEventListener("click",rfactionchange,false);
  214. acell=elementSkillButton.parentNode;
  215. acell.insertBefore(newbox,elementSkillButton);
  216. elementSkillButton.disabled=true;
  217. }
  218. }
  219. }
  220. }
  221. //6- revoke faction button
  222. //do the revoke faction button
  223. //TWEAK 6- revoke faction button
  224. //do the revoke faction button
  225. var factionbuttons= document.evaluate("//form[@name='stronghold']", document, null,
  226. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  227. if (factionbuttons.snapshotLength>0){//if we have a faction box
  228. var factionbutton=factionbuttons.snapshotItem(0).firstElementChild.nextElementSibling;
  229. if (factionbutton.type=="submit"){//but sometimes isn't
  230. if (!factionbutton.hasAttribute('mageconfirmflag')){//see if flag not set
  231. factionbutton.setAttribute('mageconfirmflag',1);//set flag
  232. if (factionbutton.value.slice(0,17)=="Revoke Stronghold"){//just do the one button here.
  233. //alert("doing it")
  234. var anewbox=document.createElement('input');
  235. anewbox.type='checkbox';
  236. anewbox.checked=false;
  237. var rrevokechange=function(e) {
  238. var targetbutton=e.target.nextElementSibling;//button should be next element
  239. if(e.target.checked){
  240. targetbutton.disabled=false;
  241. }
  242. else{
  243. targetbutton.disabled=true;
  244. }
  245. }
  246. anewbox.addEventListener("click",rrevokechange,false);
  247. acell=factionbutton.parentNode
  248. acell.insertBefore(anewbox,factionbutton);
  249. factionbutton.disabled=true;
  250. }
  251. }
  252. }
  253. }
  254.  
  255.  
  256.  
  257. //EOF
  258. })();