BRDTS_KeyboardScript

BR大逃杀全键盘操作脚本

目前为 2015-12-12 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name BRDTS_KeyboardScript
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description BR大逃杀全键盘操作脚本
  6. // @author StingX
  7. // @match http://123.57.37.3/*
  8. // @match http://www.dtsgame.com/*
  9. // @require http://code.jquery.com/jquery-1.11.0.min.js
  10. // ==/UserScript==
  11.  
  12. function postCommand(mode,command){
  13. if(arguments.length){
  14. $('#submit').attr("disabled",true);
  15. var oXmlHttp = zXmlHttp.createRequest();
  16. var sBody = 'mode='+mode+'&command='+command+'&=%E6%8F%90%E4%BA%A4';
  17. oXmlHttp.open("post", "command.php", true);
  18. oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  19. oXmlHttp.onreadystatechange = function () {
  20. if (oXmlHttp.readyState == 4) {
  21. if (oXmlHttp.status == 200) {
  22. showGamedata(oXmlHttp.responseText);
  23. $('#submit').attr("disabled",false);
  24. } else {
  25. showNotice(oXmlHttp.statusText);
  26. }
  27. }
  28. };
  29. oXmlHttp.send(sBody);
  30. }
  31. else{
  32. $('#submit').attr("disabled",true);
  33. var oXmlHttp = zXmlHttp.createRequest();
  34. var sBody = getRequestBody(document.forms['cmd']);
  35. oXmlHttp.open("post", "command.php", true);
  36. oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  37. oXmlHttp.onreadystatechange = function () {
  38. if (oXmlHttp.readyState == 4) {
  39. if (oXmlHttp.status == 200) {
  40. showGamedata(oXmlHttp.responseText);
  41. $('#submit').attr("disabled",false);
  42. } else {
  43. showNotice(oXmlHttp.statusText);
  44. }
  45. }
  46. };
  47. oXmlHttp.send(sBody);
  48. }
  49. }
  50.  
  51. //展开select
  52. function open(elem) {
  53. if (document.createEvent) {
  54. var e = document.createEvent("MouseEvents");
  55. e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  56. elem[0].dispatchEvent(e);
  57. } else if (element.fireEvent) {
  58. elem[0].fireEvent("onmousedown");
  59. }
  60. }
  61.  
  62. var scroll = {
  63. '!' : function() {
  64. postCommand('special','pose0');
  65. },
  66. '@' : function() {
  67. postCommand('special','pose1');
  68. },
  69. '#' : function() {
  70. postCommand('special','pose2');
  71. },
  72. '$' : function() {
  73. postCommand('special','pose3');
  74. },
  75. '%' : function() {
  76. postCommand('special','pose4');
  77. },
  78. '^' : function() {
  79. postCommand('special','pose5');
  80. },
  81. 'Q' : function() {
  82. postCommand('special','tac0');
  83. },
  84. 'W' : function() {
  85. postCommand('special','tac2');
  86. },
  87. 'E' : function() {
  88. postCommand('special','tac3');
  89. },
  90. 'R' : function() {
  91. postCommand('special','tac4');
  92. },
  93. '1' : function() {
  94. $("select[name='moveto']").val(1);
  95. sl('move');
  96. postCommand();
  97. },
  98. '2' : function() {
  99. $("select[name='moveto']").val(2);
  100. sl('move');
  101. postCommand();
  102. },
  103. '3' : function() {
  104. $("select[name='moveto']").val(3);
  105. sl('move');
  106. postCommand();
  107. },
  108. '4' : function() {
  109. $("select[name='moveto']").val(4);
  110. sl('move');
  111. postCommand();
  112. },
  113. '5' : function() {
  114. $("select[name='moveto']").val(5);
  115. sl('move');
  116. postCommand();
  117. },
  118. '6' : function() {
  119. $("select[name='moveto']").val(6);
  120. sl('move');
  121. postCommand();
  122. },
  123. '7' : function() {
  124. $("select[name='moveto']").val(7);
  125. sl('move');
  126. postCommand();
  127. },
  128. '8' : function() {
  129. $("select[name='moveto']").val(8);
  130. sl('move');
  131. postCommand();
  132. },
  133. '9' : function() {
  134. $("select[name='moveto']").val(9);
  135. sl('move');
  136. postCommand();
  137. },
  138. '0' : function() {
  139. $("select[name='moveto']").val(10);
  140. sl('move');
  141. postCommand();
  142. },
  143. '-' : function() {
  144. $("select[name='moveto']").val(11);
  145. sl('move');
  146. postCommand();
  147. },
  148. 'q' : function() {
  149. $("select[name='moveto']").val(12);
  150. sl('move');
  151. postCommand();
  152. },
  153. 'w' : function() {
  154. $("select[name='moveto']").val(13);
  155. sl('move');
  156. postCommand();
  157. },
  158. 'e' : function() {
  159. $("select[name='moveto']").val(14);
  160. sl('move');
  161. postCommand();
  162. },
  163. 'r' : function() {
  164. $("select[name='moveto']").val(15);
  165. sl('move');
  166. postCommand();
  167. },
  168. 't' : function() {
  169. $("select[name='moveto']").val(16);
  170. sl('move');
  171. postCommand();
  172. },
  173. 'y' : function() {
  174. $("select[name='moveto']").val(17);
  175. sl('move');
  176. postCommand();
  177. },
  178. 'u' : function() {
  179. $("select[name='moveto']").val(18);
  180. sl('move');
  181. postCommand();
  182. },
  183. 'i' : function() {
  184. $("select[name='moveto']").val(19);
  185. sl('move');
  186. postCommand();
  187. },
  188. 'o' : function() {
  189. $("select[name='moveto']").val(20);
  190. sl('move');
  191. postCommand();
  192. },
  193. 'p' : function() {
  194. $("select[name='moveto']").val(21);
  195. sl('move');
  196. postCommand();
  197. },
  198. ' ':function() {
  199. postCommand();
  200. },
  201. 'a':function() {
  202. sl('search_');
  203. postCommand();
  204. },
  205. //left
  206. '37':function() {
  207. var radios = $("input[type='radio']");
  208. var checkedIndex;
  209. radios.each(function(i,e){
  210. if(e.checked){
  211. checkedIndex = i;
  212. return false;
  213. }
  214. });
  215. radios.get(checkedIndex+1).click();
  216. },
  217. //up
  218. '38':function() {
  219. var radios = $("input[type='radio']");
  220. var checkedIndex;
  221. radios.each(function(i,e){
  222. if(e.checked){
  223. checkedIndex = i;
  224. return false;
  225. }
  226. });
  227. if(checkedIndex>0)
  228. radios.get(checkedIndex-1).checked = true;
  229. else
  230. radios.get(radios.length-1).checked = true;
  231.  
  232. },
  233. //right
  234. '39':function() {
  235. var radios = $("input[type='radio']");
  236. var checkedIndex;
  237. radios.each(function(i,e){
  238. if(e.checked){
  239. checkedIndex = i;
  240. return false;
  241. }
  242. });
  243. open(radios.eq(checkedIndex).next().children().first());
  244. },
  245. //down
  246. '40':function() {
  247. var radios = $("input[type='radio']");
  248. var checkedIndex;
  249. radios.each(function(i,e){
  250. if(e.checked){
  251. checkedIndex = i;
  252. return false;
  253. }
  254. });
  255. if(checkedIndex<radios.length-1)
  256. radios.get(checkedIndex+1).checked = true;
  257. else
  258. radios.get(0).checked = true;
  259. },
  260. };
  261.  
  262.  
  263.  
  264. var run =function () {
  265. create_right();
  266.  
  267. window.addEventListener('keydown',
  268. function(e) {
  269. if (e.metaKey || e.ctrlKey || e.target.isContentEditable || document.designMode ==="on") {
  270. console.log('block key2');
  271. return; }
  272. if (e.keyCode<37||e.keyCode>40)
  273. return;
  274. if (scroll[e.keyCode]) {
  275. scroll[e.keyCode]();
  276. e.preventDefault();
  277. e.stopPropagation();
  278. }
  279. }, false);
  280. window.addEventListener('keypress',
  281. function(e) {
  282. if (e.metaKey || e.ctrlKey || e.target.isContentEditable || document.designMode ==="on") {
  283. console.log('block key1');
  284. return; }
  285. var key = String.fromCharCode(e.charCode);
  286. if (scroll[key]) {
  287. scroll[key]();
  288. e.preventDefault();
  289. e.stopPropagation();
  290. }
  291. }, false);
  292. }
  293.  
  294.  
  295.  
  296. function create_right(){
  297. if($("td[rowspan='2']").length>0){
  298. $("td[rowspan='2']").parent().append("\
  299. <td rowspan=\"2\"> <table border=\"1\" width=\"250\" height=\"550\" cellspacing=\"0\" cellpadding=\"0\"> \
  300. <tbody> <tr><td valign=\"top\" class=\"b3\" style=\"text-align: left\"> <div id=\"log\"> <span class=\"yellow b\" style=\"letter-spacing: 2px;\">\
  301. 基础快捷键:<br/>\
  302. 选择--方向键↑→↓,Esc<br/>\
  303. 提交,确定--空格<br/>\
  304. 探索--a<br/>\
  305. <br/>\
  306. 移动:<br/>\
  307. 北海岸--1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;北村住宅区--2<br/>\
  308. 北村公所--3&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;邮电局--4<br/>\
  309. 消防署--5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;观音堂--6<br/>\
  310. 清水池--7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;西村神社--8<br/>\
  311. 墓地--9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;山丘地带--0<br/>\
  312. 隧道---&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;西村住宅区--q<br/>\
  313. 寺庙--w&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;废校--e<br/>\
  314. 南村神社--r&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;森林地带--t<br/>\
  315. 源二郎池--y&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;南村住宅区--u<br/>\
  316. 诊所--i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;灯塔--o<br/>\
  317. 南海岸--p<br/>\
  318. <br/>\
  319. 基础姿态:<br/>\
  320. 通常--shift+1<br/>\
  321. 攻击姿态--shift+2<br/>\
  322. 防守姿态--shift+3 <br/>\
  323. 探索姿态--shift+4<br/>\
  324. 隐藏姿态--shift+5 <br/>\
  325. 治疗姿态--shift+6 <br/>\
  326. <br/>\
  327. 应战策略:<br/>\
  328. 通常--shift+q<br/>\
  329. 重视防御 --shift+w<br/>\
  330. 重视反击 --shift+e<br/>\
  331. 重视躲避 --shift+r<br/>\
  332. </span><br> </div> </td> </tr> </tbody></table> </td>");
  333. }
  334. }
  335.  
  336.  
  337. run();