-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup_script.js
198 lines (178 loc) · 5.88 KB
/
popup_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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
let textfieldId = "text-field";
let resultId = "result";
let buttonId = "copy";
let button2Id = "regenerate";
let resultP = null;
let message = "Copy";
let message2 = "Get Text";
let message3 = "Text";
let message4 = "Save";
let keys = ["number", "deviation", "overlay", "double", "space", "english", "chaotic", "upper"];
let values = [];
const stringFromUTF8Array = function(data) {
const extraByteMap = [1, 1, 1, 1, 2, 2, 3, 0];
let count = data.length;
let str = "";
for (let index = 0; index < count;) {
let ch = data[index++];
if (ch & 0x80) {
let extra = extraByteMap[(ch >> 3) & 0x07];
if (!(ch & 0x40) || !extra || ((index + extra) > count))
return null;
ch = ch & (0x3F >> extra);
for (; extra > 0; extra -= 1) {
let chx = data[index++];
if ((chx & 0xC0) != 0x80)
return null;
ch = (ch << 6) | (chx & 0x3F);
}
}
str += String.fromCharCode(ch);
}
return str;
};
const randomInteger = function(from, to) {
return Math.floor(Math.random() * (to - from + 1)) + from;
};
const randomIntegerFromGroup = function(groups) {
let total = 0;
for (let i = 0; i < groups.length; i++) {
total += groups[i][1] - groups[i][0] + 1;
}
let random = Math.random();
let index = 0;
let total2 = 0;
while (index < groups.length - 1) {
total2 += groups[index][1] - groups[index][0] + 1;
if (random <= total2 / total) {
break;
}
index += 1;
}
return [groups[index][2], randomInteger(groups[index][0], groups[index][1])];
};
const randomUpperAccent = function() {
return randomIntegerFromGroup([[0x80, 0x94, 0xcc]]);
};
const randomLowerAccent = function() {
return randomIntegerFromGroup([[0xa9, 0xb3, 0xcc]]);
};
const allAccents = [[0x80, 0xb3, 0xcc], [0xb9, 0xbf, 0xcc], [0x80, 0x9b, 0xcd], [0xa3, 0xaf, 0xcd]];
const accents = [[0x80, 0x95, 0xcc], [0x9a, 0x9b, 0xcc], [0xbd, 0xbf, 0xcc], [0x80, 0x84, 0xcd], [0x86, 0x86, 0xcd], [0x8a, 0x8c, 0xcd], [0x90, 0x92, 0xcd], [0x97, 0x98, 0xcd], [0x9b, 0x9b, 0xcd], [0x9d, 0x9e, 0xcd], [0xa0, 0xa1, 0xcd], [0xa3, 0xaf, 0xcd]];
const accents2 = [[0x96, 0x99, 0xcc], [0x9c, 0xb3, 0xcc], [0xb9, 0xbc, 0xcc], [0x85, 0x85, 0xcd], [0x87, 0x89, 0xcd], [0x8d, 0x8f, 0xcd], [0x93, 0x96, 0xcd], [0x99, 0x9a, 0xcd], [0x9c, 0x9c, 0xcd], [0x9f, 0x9f, 0xcd], [0xa2, 0xa2, 0xcd]];
const randomAccent = function() {
return randomIntegerFromGroup(allAccents);
};
const randomAccent2 = function() {
return randomIntegerFromGroup(accents);
};
const randomAccent3 = function() {
return randomIntegerFromGroup(accents2);
};
const randomOverlay = function() {
return [0xcc, randomInteger(0xb4, 0xb8)];
};
const randomDouble = function() {
return [0xcd, randomInteger(0x9c, 0xa2)];
};
const pushAccent = function(array, accent) {
for (let k = 0; k < accent.length; k++) {
array.push(accent[k]);
}
};
const isEnglish = function(char) {
return (char >= "a".charCodeAt(0) && char <= "z".charCodeAt(0)) || (char >= "A".charCodeAt(0) && char <= "Z".charCodeAt(0));
};
const generateSpam = function(value) {
let array = [];
for (let i = 0; i < value.length; i++) {
array.push(value.charCodeAt(i));
if ((value.charCodeAt(i) == " ".charCodeAt(0) && !values[4]) || (value.charCodeAt(i) != " ".charCodeAt(0) && values[5] && !isEnglish(value.charCodeAt(i)))) {
continue;
}
let random = Math.random();
if (random < values[2]) {
pushAccent(array, randomOverlay());
}
let random2 = Math.random();
if (random2 < values[3]) {
pushAccent(array, randomDouble());
}
let number = values[0] + (Math.random() * 2 - 1) * values[1];
let number2 = number * values[7];
for (let j = 0; j < number; j++) {
if (j < number2) {
if (!values[6]) {
pushAccent(array, randomUpperAccent());
}
else {
pushAccent(array, randomAccent2());
}
}
else {
if (!values[6]) {
pushAccent(array, randomLowerAccent());
}
else {
pushAccent(array, randomAccent3());
}
}
}
}
return stringFromUTF8Array(array);
};
const copyToClipboard = function(str) {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0
? document.getSelection().getRangeAt(0)
: false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
};
for (let i = 0; i < keys.length; i++) {
chrome.storage.sync.get(keys[i], items => {
values.push(items[keys[i]]);
});
}
document.addEventListener("DOMContentLoaded", () => {
resultP = document.getElementById(resultId);
let textfield = document.getElementById(textfieldId);
textfield.addEventListener("input", () => {
let value = textfield.value;
chrome.runtime.sendMessage({message: message4, text: value}, () => {});
resultP.innerText = generateSpam(value);
});
let button = document.getElementById(buttonId);
button.addEventListener("click", () => {
copyToClipboard(resultP.innerText);
});
let button2 = document.getElementById(button2Id);
button2.addEventListener("click", () => {
let value = textfield.value;
resultP.innerText = generateSpam(value);
});
chrome.runtime.sendMessage(message2, () => {});
});
chrome.runtime.onMessage.addListener((msg, _, response) => {
if (msg == message) {
response();
copyToClipboard(resultP.innerText);
}
else if (msg.message == message3) {
response();
let textfield = document.getElementById(textfieldId);
textfield.value = msg.text;
resultP.innerText = generateSpam(textfield.value);
}
});