Zamiel's KoL Scripts - Monster Level Dropdown

v0.3 - Changes the ML device link on the charpane into a dropdown menu.

  1. // ==UserScript==
  2. // @name Zamiel's KoL Scripts - Monster Level Dropdown
  3. // @description v0.3 - Changes the ML device link on the charpane into a dropdown menu.
  4. // @namespace http://www.realultimatepower.com/
  5. // @include *kingdomofloathing.com/charpane.php*
  6. // @include *127.0.0.1:*charpane.php*
  7. // @version 0.0.1.20140812160330
  8. // ==/UserScript==
  9.  
  10. /*
  11.  
  12. Script notes:
  13.  
  14. - This script changes the detuned radio, MCD, or Annoy-o-Tron link on the charpane into a dropdown menu for easy access.
  15. - The dropdown menu will still be there even if your device is off.
  16. - You must turn your respective device on at least once for the script to "capture" it and detect which moon sign you are under.
  17.  
  18. Known Bugs:
  19.  
  20. - None; please PM me if you find any!
  21.  
  22. Shoutouts:
  23.  
  24. - This script is a modified version of Philip's MCD script (he has since retired from KoL). Thanks Phillip!
  25. - The password hash snatching was ripped off from clump's QuickUse script. Thanks clump!
  26. - The moon sign detection, Annoy-o-Tron parts, and basically everything that makes the functions work with all 3 devices was completely written by Clump. He's a total badass.
  27.  
  28. Version History:
  29.  
  30. - v0.3 - 17 Mar 09 - Clump fixed the MCD not going to 11. The Mafia bug is also fixed.
  31. - v0.2 - 16 Mar 09 - Clump helped me out; there is now moon sign detection and it works with all 3 devices.
  32. - v0.1 - 13 Mar 09 - This is the first version of my first script. It only works with the detuned radio.
  33.  
  34. */
  35.  
  36. var DetunedRadio, AnnoyoTron, MCD, select, loadingImg;
  37. findWhich();
  38.  
  39. function getPwdHash() {
  40. var page = document.documentElement.innerHTML;
  41. var find = 'pwdhash = ';
  42. if (page.indexOf(find) >= 0) {
  43. var i = page.indexOf(find);
  44. var j = find.length;
  45. var ps = page.substr(i+j+2);
  46. var foundit = page.substr(i+j+1,ps.indexOf('"')+1);
  47. return foundit;
  48. }
  49. return "";
  50. }
  51.  
  52. function getPlayerNameFromCharpane() {
  53. var username = document.getElementsByTagName("b");
  54. if (!username || username.length < 1) return false;
  55. username = username[0];
  56. if (!username) return false;
  57. username = username.firstChild;
  58. if (!username) return false;
  59. // in full mode the link is <a><b>Name</b></a>
  60. // in compact mode it's <b><a>Name</a></b>
  61. // so have to handle this, and also can use it to tell
  62. // whether it's in compact mode or not.
  63. var fullmode = true;
  64. while (username && username.nodeType == 1)
  65. {
  66. username = username.firstChild;
  67. fullmode = false;
  68. }
  69. if (!username) return false;
  70. username = username.nodeValue;
  71. if (!username) return false;
  72. username = username.toLowerCase();
  73. return username;
  74. }
  75.  
  76.  
  77. function findWhich() {
  78. // check for ascension
  79. var pn = getPlayerNameFromCharpane();
  80. if (document.evaluate("//img[contains(@src,'http://images.kingdomofloathing.com/otherimages/inf_small.gif')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue) {
  81. GM_setValue(pn+'_mcd','none');
  82. }
  83.  
  84. // check for existing
  85. if (!checkAllDevices('none',pn+'_mcd')) {
  86. var mcd = GM_getValue(pn+'_mcd','none');
  87. //GM_log("stored mcd for " +pn+" is "+mcd);
  88. checkAllDevices(mcd,pn+'_mcd');
  89. }
  90. }
  91.  
  92. function checkAllDevices(mcd,keyv) {
  93. DetunedRadio=findMLDevice(mcd,"'whichitem=2682'","radio","inv_use.php?pwd=" + getPwdHash() + "&whichitem=2682","Detuned Radio",changeDetunedRadio);
  94. if (!DetunedRadio) {
  95. MCD=findMLDevice(mcd,"'canadia.php?place=machine'","MCD","canadia.php?place=machine","Mind Control",changeMCD);
  96. if (!MCD) {
  97. AnnoyoTron=findMLDevice(mcd,"'gnomes.php?place=machine'","AnnoyoTron","gnomes.php?place=machine","Annoy-o-Tron 5k",changeAnnoyoTron);
  98. if (AnnoyoTron) {
  99. GM_setValue(keyv,'AnnoyoTron');
  100. return true;
  101. }
  102. } else {
  103. GM_setValue(keyv,'MCD');
  104. return true;
  105. }
  106. } else {
  107. GM_setValue(keyv,'radio');
  108. return true;
  109. }
  110. return false;
  111. }
  112.  
  113. function findMLDevice(mcdtype,urlsearch,type,addurl,addtext,addhandler)
  114. {
  115. var mcd = document.evaluate("//a[contains(@href,"+urlsearch+")]/following-sibling::b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  116. if (!mcd)
  117. {
  118. // try looking compact-mode-style
  119. mcd = document.evaluate("//a[contains(@href,"+urlsearch+")]/../..//b", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  120. }
  121. // appears to be off
  122. if (!mcd)
  123. {
  124. if (mcdtype==type) {
  125. mcd=addCharpaneBox(addurl,addtext);
  126. replaceCharpaneLink(mcd,addhandler,((type=='MCD') ? 11 : 10));
  127. }
  128. }
  129. else {
  130. replaceCharpaneLink(mcd,addhandler,((type=='MCD') ? 11 : 10));
  131. }
  132. return mcd;
  133. }
  134.  
  135.  
  136. function addCharpaneBox(href,text)
  137. {
  138. var mcd;
  139. // compact mode: add it directly under the "Adv:" row
  140. var adv = document.evaluate("//td[contains(.,'Adv:')]/ancestor::tr", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  141. if (adv)
  142. {
  143. // we're in compact mode
  144. // put it below "Ronin" if it's there
  145. var row = document.evaluate("//td[contains(.,'Ronin:') or contains(.,'Hardcore')]/ancestor::tr", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  146. if (!row)
  147. row = adv;
  148. var tr = document.createElement('tr');
  149. var td = document.createElement('td');
  150. td.style.textAlign = "right";
  151. var link = document.createElement('a');
  152. link.href = href;
  153. link.target = "mainpane";
  154. link.appendChild(document.createTextNode("DR"));
  155. td.appendChild(link);
  156. td.appendChild(document.createTextNode(":"));
  157. tr.appendChild(td);
  158. td = document.createElement('td');
  159. td.style.textAlign = "left";
  160. mcd = document.createElement('b');
  161. mcd.appendChild(document.createTextNode('0'));
  162. td.appendChild(mcd);
  163. tr.appendChild(td);
  164. row.parentNode.insertBefore(tr, row.nextSibling);
  165. }
  166. else
  167. {
  168. // we're in full mode
  169. // add it directly under the table that has the adventures counter
  170. adv = document.evaluate("//img[contains(@src,'hourglass.gif')]/ancestor::table", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  171. if (!adv)
  172. return;
  173. ronin = document.evaluate("//font[contains(.,'Ronin:') or contains(.,'Hardcore')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  174. var font = document.createElement('font');
  175. font.size = 2;
  176. var link = document.createElement('a');
  177. link.href = href;
  178. link.target = "mainpane";
  179. link.appendChild(document.createTextNode(text));
  180. font.appendChild(link);
  181. font.appendChild(document.createTextNode(": "));
  182. mcd = document.createElement('b');
  183. mcd.appendChild(document.createTextNode('0'));
  184. font.appendChild(mcd);
  185. if (ronin)
  186. {
  187. ronin.parentNode.insertBefore(font, ronin.nextSibling);
  188. ronin.parentNode.insertBefore(document.createElement('br'), ronin.nextSibling);
  189. ronin.parentNode.insertBefore(document.createElement('br'), ronin.nextSibling);
  190. }
  191. else
  192. {
  193. adv.parentNode.insertBefore(document.createElement('br'), adv.nextSibling);
  194. adv.parentNode.insertBefore(font, adv.nextSibling);
  195. adv.parentNode.insertBefore(document.createElement('br'), adv.nextSibling);
  196. }
  197. }
  198. return mcd
  199. }
  200.  
  201. function replaceCharpaneLink(mcd,handler,max)
  202. {
  203. var sel = parseInt(mcd.firstChild.nodeValue);
  204. var form = document.createElement('form');
  205. select = document.createElement('select');
  206. for (var i = 0; i <= max; i++)
  207. {
  208. var option = document.createElement('option');
  209. option.value = i;
  210. if (i == sel)
  211. option.selected = true;
  212. option.appendChild(document.createTextNode(i));
  213. select.appendChild(option);
  214. }
  215. select.setAttribute('style','font-size:10px;vertical-align:middle;');
  216. select.addEventListener("change", handler, false);
  217. form.appendChild(select);
  218. form.style.display = "inline";
  219. loadingImg = document.createElement('img');
  220. loadingImg.src = "data:image/gif;base64,R0lGODlhEgASAJECAMDAwNvb2%2F%2F%2F%2FwAAACH%2FC05FVFNDQVBFMi4wAwEAAAAh%2BQQFCgACACwAAAAAEgASAAACMpSPqQmw39o7IYjo6qpacpt8iKhoITiiG0qWnNGepjCv7u3WMfxqO0%2FrqVa1CdCIRBQAACH5BAUKAAIALAcAAQAIAAYAAAIOVCKZd2osAFhISmcnngUAIfkEBQoAAgAsCwADAAYACAAAAg5UInmnm4ZeAuBROq%2BtBQAh%2BQQFCgACACwLAAcABgAIAAACD5QTJojH2gQAak5jKdaiAAAh%2BQQFCgACACwHAAsACAAGAAACDpQdcZgKIFp4Lzq6RF0FACH5BAUKAAIALAMACwAIAAYAAAIOFCCZd2osQlhISmcnngUAIfkEBQoAAgAsAQAHAAYACAAAAg4UIHmnm4ZeCuFROq%2BtBQAh%2BQQFCgACACwBAAMABgAIAAACD5QBJojH2kQIak5jKdaiAAA7";
  221. loadingImg.setAttribute('style','display:none; vertical-align:middle;');
  222. mcd.parentNode.replaceChild(loadingImg, mcd);
  223. loadingImg.parentNode.insertBefore(form, loadingImg);
  224. }
  225.  
  226. function changeDetunedRadio(e)
  227. {
  228. loadingImg.style.display = "inline";
  229. GM_xmlhttpRequest({
  230. method: "POST",
  231. url: "http://" + location.host + "/inv_use.php",
  232. headers: {"Content-type": "application/x-www-form-urlencoded"},
  233. data: "pwd=" + getPwdHash() + "&whichitem=2682&tuneradio=" + select.value,
  234. onload: function(){ location.reload(); }
  235. });
  236. }
  237.  
  238. function changeMCD(e)
  239. {
  240. loadingImg.style.display = "inline";
  241. GM_xmlhttpRequest({
  242. method: "POST",
  243. url: "http://" + location.host + "/canadia.php",
  244. headers: {"Content-type": "application/x-www-form-urlencoded"},
  245. data: "action=changedial&whichlevel=" + select.value,
  246. onload: function(){ location.reload(); }
  247. });
  248. }
  249.  
  250. function changeAnnoyoTron(e)
  251. {
  252. loadingImg.style.display = "inline";
  253. GM_xmlhttpRequest({
  254. method: "POST",
  255. url: "http://" + location.host + "/gnomes.php",
  256. headers: {"Content-type": "application/x-www-form-urlencoded"},
  257. data: "&action=changedial&whichlevel=" + select.value,
  258. onload: function(){ location.reload(); }
  259. });
  260. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址