-
Notifications
You must be signed in to change notification settings - Fork 1
/
PHhotkeys.user.js
138 lines (121 loc) · 4.38 KB
/
PHhotkeys.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// ==UserScript==
// @name PROHARDVER hotkeys in editor
// @author dqdb, dobragab, milangfx
// @namespace https://www.prohardver.hu/
// @match https://www.prohardver.hu/muvelet/*
// @match https://prohardver.hu/muvelet/*
// @match https://www.mobilarena.hu/muvelet/*
// @match https://mobilarena.hu/muvelet/*
// @match https://www.logout.hu/muvelet/*
// @match https://logout.hu/muvelet/*
// @match https://www.itcafe.hu/muvelet/*
// @match https://itcafe.hu/muvelet/*
// @match https://www.gamepod.hu/muvelet/*
// @match https://gamepod.hu/muvelet/*
// @match https://www.hardverapro.hu/muvelet/*
// @match https://hardverapro.hu/muvelet/*
// @updateURL https://raw.githubusercontent.com/dobragab/prohardver-userscripts/master/PHhotkeys.user.js
// @version 1.5
// ==/UserScript==
function event_handler()
{
var editor = document.evaluate("//textarea[@name=\"content\"]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if (editor == null)
return;
var buttons = document.evaluate("//input", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var is_comment = buttons.snapshotItem(0).type == "radio";
var n = is_comment ? 2 : 0;
editor.hotkeys =
{
"ctrl-enter" : buttons.snapshotItem(n++), // send comment
//"ctrl-s" : ":)",
//"ctrl-x" : function() { window.alert("pressed"); },
"ctrl-b" : buttons.snapshotItem(n++), // bold
"ctrl-i" : buttons.snapshotItem(n++), // italic
"ctrl-u" : buttons.snapshotItem(n++), // underlined
"ctrl-s" : buttons.snapshotItem(n++), // strike-through
"ctrl-o" : buttons.snapshotItem(n++), // off topic
"ctrl-k" : buttons.snapshotItem(n++), // link
"ctrl-g" : buttons.snapshotItem(n++), // image
"ctrl-d" : buttons.snapshotItem(n++), // code
"ctrl-m" : buttons.snapshotItem(n++), // monospace
"ctrl-w" : buttons.snapshotItem(n++), // raw
"ctrl-l" : buttons.snapshotItem(n++), // left-aligned
"ctrl-r" : buttons.snapshotItem(n++), // right-aligned
"ctrl-e" : buttons.snapshotItem(n++), // centered
"ctrl-j" : buttons.snapshotItem(n++) // justified
};
if (is_comment)
{
editor.hotkeys["ctrl-alt-n"] = buttons.snapshotItem(0); // normal comment
editor.hotkeys["ctrl-alt-o"] = buttons.snapshotItem(1); // off-topic comment
}
var onhotkeycancel = function (e)
{
e.returnValue = false;
if (e.stopPropagation)
e.stopPropagation();
if (e.preventDefault)
e.preventDefault();
return false;
};
var onhotkeypress = function (e)
{
if (editor.hotkey == null)
return true;
var hotkey = editor.hotkey;
if (typeof(hotkey) == "function")
hotkey(e);
else if (typeof(hotkey) == "string")
editor.value = editor.value.substr(0, editor.selectionStart) + hotkey + editor.value.substr(editor.selectionEnd);
else if (typeof(hotkey) == "object" && hotkey.tagName == "INPUT" && 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];
editor.hotkey = editor.hotkeys[key];
if (editor.hotkey == null)
return true;
return onhotkeypress(e);
};
var onhotkeyup = function (e)
{
if (editor.hotkey == null)
return true;
editor.hotkey = null;
return onhotkeycancel(e);
}
editor.addEventListener("keydown", onhotkeydown, false);
editor.addEventListener("keyup", onhotkeyup, false);
}
if (document.body)
event_handler();
else
window.addEventListener("load", event_handler, false);
//////////////////////////////////////////
// 1.4 https
// 1.3 FF4 kompatibilitás
// 1.2 Chrome kompatibilitás
// 1.1 privát írásakor elcsúszott a billentyűkiosztás
// 1.0 eredeti változat