BRDTS_KeyboardScript

BR大逃杀全键盘操作脚本

Fra og med 13.01.2016. Se den nyeste version.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         BRDTS_KeyboardScript
// @namespace    http://tampermonkey.net/
// @version      0.7
// @description  BR大逃杀全键盘操作脚本
// @author       StingX
// @match        http://123.57.37.3/*
// @match        http://www.dtsgame.com/*
// @match        http://br.265g.com/*
// @require      http://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==

//发请求
function postCommand(mode,command){
    if(arguments.length){
    $('#submit').attr("disabled",true);
    var oXmlHttp = zXmlHttp.createRequest();
    var sBody = 'mode='+mode+'&command='+command+'&=%E6%8F%90%E4%BA%A4';
    oXmlHttp.open("post", "command.php", false);
    oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                showGamedata(oXmlHttp.responseText);
                $('#submit').attr("disabled",false);
            } else {
                showNotice(oXmlHttp.statusText);
            }
        }
    };
    oXmlHttp.send(sBody);
    }
    else{
        //提交按钮变灰
         $('#submit').attr("disabled",true);
        //初始化请求类
    var oXmlHttp = zXmlHttp.createRequest();
        //复制表单内容
    var sBody = getRequestBody(document.forms['cmd']);
        //设置请求类型为post,页面为command.php
    oXmlHttp.open("post", "command.php", false);
        //设置请求头
    oXmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        //设置响应
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                showGamedata(oXmlHttp.responseText);
                $('#submit').attr("disabled",false);
            } else {
                showNotice(oXmlHttp.statusText);
            }
        }
    };
        //发请求
    oXmlHttp.send(sBody);   
        
    }
}

//展开select
function open(elem) {
    if (document.createEvent) {
        var e = document.createEvent("MouseEvents");
        e.initMouseEvent("mousedown", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        elem[0].dispatchEvent(e);
    } else if (element.fireEvent) {
        elem[0].fireEvent("onmousedown");
    }
}

//键盘-操作映射组
var scroll = {
    '!' : function() { 
            $("select[name='sp_cmd']").val('sp_pose');
            sl('special');
            postCommand(); 
            postCommand('special','pose0');
        }, 
    '@' : function() { 
            $("select[name='sp_cmd']").val('sp_pose');
            sl('special');
            postCommand(); 
            postCommand('special','pose1'); 
        }, 
    '#' : function() { 
            $("select[name='sp_cmd']").val('sp_pose');
            sl('special');
            postCommand(); 
            postCommand('special','pose2'); 
        }, 
    '$' : function() { 
             $("select[name='sp_cmd']").val('sp_pose');
            sl('special');
            postCommand(); 
            postCommand('special','pose3'); 
        }, 
    '%' : function() { 
            $("select[name='sp_cmd']").val('sp_pose');
            sl('special');
            postCommand(); 
            postCommand('special','pose4'); 
        }, 
    '^' : function() { 
             $("select[name='sp_cmd']").val('sp_pose');
            sl('special');
            postCommand(); 
            postCommand('special','pose5'); 
        }, 
    'Q' : function() { 
            $("select[name='sp_cmd']").val('sp_tac');
            sl('special');
            postCommand(); 
            postCommand('special','tac0'); 
        }, 
    'W' : function() { 
             $("select[name='sp_cmd']").val('sp_tac');
            sl('special');
            postCommand(); 
            postCommand('special','tac2'); 
        }, 
    'E' : function() { 
             $("select[name='sp_cmd']").val('sp_tac');
            sl('special');
            postCommand(); 
            postCommand('special','tac3'); 
        }, 
    'R' : function() { 
             $("select[name='sp_cmd']").val('sp_tac');
            sl('special');
            postCommand(); 
            postCommand('special','tac4'); 
        }, 
        '1' : function() { 
            $("select[name='moveto']").val(1);
            sl('move');
            postCommand(); 
        }, 
        '2' : function() { 
            $("select[name='moveto']").val(2);
            sl('move');
            postCommand(); 
        }, 
        '3' : function() { 
            $("select[name='moveto']").val(3);
            sl('move');
            postCommand(); 
        }, 
        '4' : function() { 
            $("select[name='moveto']").val(4);
            sl('move');
            postCommand(); 
        }, 
        '5' : function() { 
            $("select[name='moveto']").val(5);
            sl('move');
            postCommand(); 
        }, 
        '6' : function() { 
            $("select[name='moveto']").val(6);
            sl('move');
            postCommand(); 
        }, 
        '7' : function() { 
            $("select[name='moveto']").val(7);
            sl('move');
            postCommand(); 
        }, 
        '8' : function() { 
            $("select[name='moveto']").val(8);
            sl('move');
            postCommand(); 
        }, 
        '9' : function() { 
            $("select[name='moveto']").val(9);
            sl('move');
            postCommand(); 
        }, 
        '0' : function() { 
            $("select[name='moveto']").val(10);
            sl('move');
            postCommand(); 
        }, 
        '-' : function() { 
            $("select[name='moveto']").val(11);
            sl('move');
            postCommand(); 
        }, 
        'q' : function() { 
            $("select[name='moveto']").val(12);
            sl('move');
            postCommand(); 
        }, 
        'w' : function() { 
            $("select[name='moveto']").val(13);
            sl('move');
            postCommand(); 
        }, 
        'e' : function() { 
            $("select[name='moveto']").val(14);
            sl('move');
            postCommand(); 
        }, 
        'r' : function() { 
            $("select[name='moveto']").val(15);
            sl('move');
            postCommand(); 
        }, 
        't' : function() { 
            $("select[name='moveto']").val(16);
            sl('move');
            postCommand(); 
        }, 
        'y' : function() { 
            $("select[name='moveto']").val(17);
            sl('move');
            postCommand(); 
        }, 
        'u' : function() { 
            $("select[name='moveto']").val(18);
            sl('move');
            postCommand(); 
        }, 
        'i' : function() { 
            $("select[name='moveto']").val(19);
            sl('move');
            postCommand(); 
        }, 
        'o' : function() { 
            $("select[name='moveto']").val(20);
            sl('move');
            postCommand(); 
        }, 
        'p' : function() { 
            $("select[name='moveto']").val(21);
            sl('move');
            postCommand(); 
        },
        ' ':function() { 
            postCommand(); 
        },
        'a':function() { 
            sl('search_');
            postCommand(); 
        },
    //left
        '37':function() { 
            var radios =  $("input[type='radio']");
            var checkedIndex;
            radios.each(function(i,e){
                if(e.checked){
                    checkedIndex = i;
                    return false;
                }
            });
            radios.get(checkedIndex+1).click();
        },
    //up
        '38':function() { 
            var radios =  $("input[type='radio']");
            var checkedIndex;
            radios.each(function(i,e){
                if(e.checked){
                    checkedIndex = i;
                    return false;
                }
            });
            if(checkedIndex>0)
                radios.get(checkedIndex-1).checked = true;
            else
                radios.get(radios.length-1).checked = true;

        },
    //right
    '39':function() { 
            var radios =  $("input[type='radio']");
            var checkedIndex;
            radios.each(function(i,e){
                if(e.checked){
                    checkedIndex = i;
                    return false;
                }
            });
           open(radios.eq(checkedIndex).next().children().first());
        },
    //down
        '40':function() { 
            var radios =  $("input[type='radio']");
            var checkedIndex;
            radios.each(function(i,e){
                if(e.checked){
                    checkedIndex = i;
                    return false;
                }
            });
            if(checkedIndex<radios.length-1)
                radios.get(checkedIndex+1).checked = true;
            else
                radios.get(0).checked = true;
        },
    };


//主程序入口
var run =function () {
    create_right();
    

    //绑定按键事件
    window.addEventListener('keydown',
        function(e) {
            if (document.activeElement.type=='text'||e.metaKey || e.ctrlKey   || e.target.isContentEditable || document.designMode ==="on") {
                                console.log('block key2');
                return; }
            if (e.keyCode<37||e.keyCode>40)
                return;
            if (scroll[e.keyCode]) {
                //触发映射
                scroll[e.keyCode]();
                //无效化按键原来的效果
                e.preventDefault();
                e.stopPropagation();
            }
        }, false);
    //组合键映射
        window.addEventListener('keypress',
        function(e) {
            if (document.activeElement.type=='text'||e.metaKey || e.ctrlKey   || e.target.isContentEditable || document.designMode ==="on") {
                console.log('block key1');
                return; }
            var key =  String.fromCharCode(e.charCode);
            if (scroll[key]) {
                scroll[key]();
                e.preventDefault();
                e.stopPropagation();
            }
        }, false);
}


//插在屏幕右端

function create_right(){
    if($("td[rowspan='2']").length>0){
$("td[rowspan='2']").parent().append("\
<td rowspan=\"2\">         <table border=\"1\" width=\"250\" height=\"550\" cellspacing=\"0\" cellpadding=\"0\">     \
<tbody>             <tr><td valign=\"top\" class=\"b3\" style=\"text-align: left\">                 <div id=\"log\">                 <span class=\"yellow b\" style=\"letter-spacing: 2px;\">\
基础快捷键:<br/>\
选择--方向键↑→↓,Esc<br/>\
提交,确定--空格<br/>\
探索--a<br/>\
<br/>\
移动:<br/>\
北海岸--1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;北村住宅区--2<br/>\
北村公所--3&nbsp;&nbsp;&nbsp;邮电局--4<br/>\
消防署--5&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;观音堂--6<br/>\
清水池--7&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;西村神社--8<br/>\
墓地--9&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;山丘地带--0<br/>\
隧道---&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;西村住宅区--q<br/>\
寺庙--w&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;废校--e<br/>\
南村神社--r&nbsp;&nbsp;&nbsp;森林地带--t<br/>\
源二郎池--y&nbsp;&nbsp;&nbsp;南村住宅区--u<br/>\
诊所--i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;灯塔--o<br/>\
南海岸--p<br/>\
<br/>\
基础姿态:<br/>\
通常--shift+1<br/>\
攻击姿态--shift+2<br/>\
防守姿态--shift+3 <br/>\
探索姿态--shift+4<br/>\
隐藏姿态--shift+5 <br/>\
治疗姿态--shift+6 <br/>\
<br/>\
应战策略:<br/>\
通常--shift+q<br/>\
重视防御 --shift+w<br/>\
重视反击 --shift+e<br/>\
重视躲避 --shift+r<br/>\
</span><br>                 </div>                                  </td>             </tr>         </tbody></table>         </td>");
    }
}


run();