Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @include http://prohardver.hu/*
- // @include http://mobilarena.hu/*
- // @include http://itcafe.hu/*
- // @include http://logout.hu/*
- // ==/UserScript==
- function keylib_initialize(obj, hotkeys)
- {
- obj.hotkey = null;
- if (obj == null)
- return;
- var onhotkeycancel = function (e)
- {
- e.returnValue = false;
- if (e.stopPropagation)
- e.stopPropagation();
- if (e.preventDefault)
- e.preventDefault();
- return false;
- };
- var onhotkeypress = function (e)
- {
- if (obj.hotkey == null)
- return true;
- var hotkey = obj.hotkey;
- if (typeof(hotkey) == "function")
- hotkey(e);
- else if (typeof(hotkey) == "string" && typeof(obj) == "object" && obj.tagName == "TEXTAREA")
- obj.value = obj.value.substr(0, obj.selectionStart) + hotkey + obj.value.substr(obj.selectionEnd);
- else if (typeof(hotkey) == "object" && (hotkey.tagName == "INPUT" || hotkey.tagName == "A"))// && window.opera == null)
- hotkey.click();
- return onhotkeycancel(e);
- }
- var onhotkeydown = function (e)
- {
- var code = e.keyCode ? e.keyCode : e.which;
- if (code == null)
- return true;
- var named_keys =
- {
- 8: "backspace", 9: "tab", 13: "enter", 32: "space", 27: "esc",
- 33: "pageup", 34: "pagedown", 35: "end", 36: "home",
- 37: "left", 38: "up", 39 : "right", 40: "down",
- 45: "insert", 46: "delete",
- 112: "f1", 113 : "f2", 114 : "f3", 115 : "f4", 116 : "f5", 117 : "f6",
- 118: "f7", 119 : "f8", 120 : "f9", 121 : "f10", 122 : "f11", 123 : "f12"
- };
- var key =
- (e.ctrlKey ? "ctrl-" : "") + (e.altKey ? "alt-" : "") + (e.shiftKey ? "shift-" : "");
- if ((code >= 65 && code <= 90) || (code >= 48 && code <= 57))
- key += String.fromCharCode(code).toLowerCase();
- else if (named_keys[code] == null)
- return true;
- else
- key += named_keys[code];
- obj.hotkey = hotkeys[key];
- if (obj.hotkey == null)
- return true;
- return onhotkeypress(e);
- };
- var onhotkeyup = function (e)
- {
- if (obj.hotkey == null)
- return true;
- obj.hotkey = null;
- return onhotkeycancel(e);
- }
- obj.addEventListener("keydown", onhotkeydown, false);
- obj.addEventListener("keyup", onhotkeyup, false);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement