ad bind

Bind AD to <- ->

目前為 2019-02-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name         ad bind
// @namespace    http://rainsims.com/
// @version      0.1
// @description  Bind AD to <- ->
// @author       Rain Sims
// @match        http*://*/*
// @exclude      http*://*pr0gramm.com/*
// ==/UserScript==

(function() {
    'use strict';

    var keyMap = {
        65: {
            "keyCode" : 37,
            "which" : 37,
            "charCode" : 0
            },
        68: {
            "keyCode" : 39,
            "which" : 39,
            "charCode" : 0
            }
    };

    function getKeyCode(key){
        return (key in keyMap) ? keyMap[key] : undefined;
    }

    function fireEvent(evt) {
        var keyCode = getKeyCode(evt.keyCode);

        if(keyCode){
            var eventObj;

            if(document.createEventObject) {
                eventObj = document.createEventObject();
                eventObj.keyCode = keyCode.keyCode;
                eventObj.which = keyCode.which;
                eventObj.charCode = keyCode.charCode;
                document.body.fireEvent("on" + evt.type, eventObj);
            } else if(document.createEvent) {
                eventObj = document.createEvent("Events");
                eventObj.initEvent(evt.type, true, true);
                eventObj.keyCode = keyCode.keyCode;
                eventObj.which = keyCode.which;
                eventObj.charCode = keyCode.charCode;
                document.body.dispatchEvent(eventObj);
            }
            console.log("fired");
        }

    }

    function addEvent(element, eventName, callback) {
        if (element.addEventListener) {
            element.addEventListener(eventName, callback, false);
        } else if (element.attachEvent) {
            element.attachEvent("on" + eventName, callback);
        }
    }

    addEvent(document, "keydown", fireEvent);
    addEvent(document, "keyup", fireEvent);
    addEvent(document, "keypress", fireEvent);
})();