BRDTS_KeyboardScript

BR大逃杀全键盘操作脚本

当前为 2016-01-13 提交的版本,查看 最新版本

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