BRDTS_KeyboardScript

BR大逃杀全键盘操作脚本

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

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