forked from lg188/volafile-scripts
-
Notifications
You must be signed in to change notification settings - Fork 2
/
volafile-checkban-anti-ip-leaker.user.js
162 lines (128 loc) · 4.74 KB
/
volafile-checkban-anti-ip-leaker.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// ==UserScript==
// @name Volafile Checkban anti IP address leaker
// @namespace volafile.checkban.anti.ip.address.leaker
// @description Tries to prevent you from leaking IP addresses when you're checking bans with the /checkban chat command. Remember, this is not bulletproof. This will stop IP address leaks 99% of the time
// @include https://volafile.org/r/*
// @match https://volafile.org/r/*
// @version 2
// @grant none
// ==/UserScript==
// The higher it is, the stricter it is. If you want it to be more lax, lower it.
// But don't go over 1.5 because then the word "check" will be marked as misspelled.
var misspell_tolerance = 1.49;
var needle = "checkban";
var needle_regex = new RegExp(needle, "i");
// The possible misspellings for the cb shorthand is hardcoded because I don't trust the algo will be good for just 2 letters.
var possible_misspellings = ["cb",
"/cb",
"/c",
"cbb",
"/cbb",
"ccb",
"/ccb",
"/b"];
var chat = document.getElementById('chat_input');
chat.addEventListener("keydown", function(e) {
if(e.keyCode === 13) {
modify_message();
}
}, true);
function modify_message() {
var message = chat.value;
var split = message.split(" ");
var i = 0;
//for(var i = 0; i < 0; i++) {
if(split[i][0] !== "\\" && split[i][0] !== "@") {
for(var j = 0; j < possible_misspellings.length; j++) {
if(split[i] === possible_misspellings[j]) {
split[i] = needle;
}
}
var number = /\d/.exec(split[i]);
if(number) {
var index = split[i].indexOf(number) + 1;
var sub_pos = split[i].substring(index - 1);
var sub_neg = split[i].substring(-1, index - 1);
if(is_misspelled(sub_neg, needle) < misspell_tolerance) {
split[i] = sub_neg + " " + sub_pos;
}
}
//console.log("SPLIT1: " + split[i]);
//split[i] = split[i].replace("/", "");
//console.log(split[i].split(" ").length);
var ip = "";
if(split[i].split(" ").length == 2) {
var new_split = split[i].split(" ")[0];
if(new_split === "") {
split[i] = split[i].split(" ")[1];
var ip = "";
} else {
var ip = " " + split[i].split(" ")[1];
//console.log("IP: " + ip);
split[i] = split[i].split(" ")[0];
}
//console.log("Fixed");
}
//console.log(ip);
//console.log("SPLIT2: " + split[i]);
if(is_misspelled(needle, split[i]) < misspell_tolerance) {
split[i] = needle + ip;
}
if(split[i].toLowerCase() === needle || needle_regex.test(split[i]) && split[i].toLowerCase() !== "/" + needle) {
split[i] = "/" + split[i];
} else if(split[i].toLowerCase() === needle || needle_regex.test(split[i])) {
split[i] = split[i].replace("/", "");
split[i] = "/" + split[i];
}
//console.log("SPLIT3: " + split[i]);
}
//}
var joined = split.join(" ");
//console.log("JOINED: " + joined);
chat.value = joined;
}
function is_misspelled(seq1,seq2) {
var len1=seq1.length;
var len2=seq2.length;
var i, j;
var dist;
var ic, dc, rc;
var last, old, column;
var weighter={
insert:function(c) { return 1.; },
delete:function(c) { return 0.5; },
replace:function(c, d) { return 0.3; }
};
/* don't swap the sequences, or this is gonna be painful */
if (len1 == 0 || len2 == 0) {
dist = 0;
while (len1)
dist += weighter.delete(seq1[--len1]);
while (len2)
dist += weighter.insert(seq2[--len2]);
return dist;
}
column = []; // malloc((len2 + 1) * sizeof(double));
//if (!column) return -1;
column[0] = 0;
for (j = 1; j <= len2; ++j)
column[j] = column[j - 1] + weighter.insert(seq2[j - 1]);
for (i = 1; i <= len1; ++i) {
last = column[0]; /* m[i-1][0] */
column[0] += weighter.delete(seq1[i - 1]); /* m[i][0] */
for (j = 1; j <= len2; ++j) {
old = column[j];
if (seq1[i - 1] == seq2[j - 1]) {
column[j] = last; /* m[i-1][j-1] */
} else {
ic = column[j - 1] + weighter.insert(seq2[j - 1]); /* m[i][j-1] */
dc = column[j] + weighter.delete(seq1[i - 1]); /* m[i-1][j] */
rc = last + weighter.replace(seq1[i - 1], seq2[j - 1]); /* m[i-1][j-1] */
column[j] = ic < dc ? ic : (dc < rc ? dc : rc);
}
last = old;
}
}
dist = column[len2];
return dist;
}