-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContentScript.js
58 lines (47 loc) · 1.54 KB
/
ContentScript.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
Main();
chrome.runtime.onMessage.addListener(Main);
function Main() {
["span", "title", "a", "p", "h1", "h2", "h3", "h4", "h5", "h6", "td"].forEach(tag => Typoifier(tag));
}
function getRandomIntInclusive(min, max) {
const randomBuffer = new Uint32Array(1);
window.crypto.getRandomValues(randomBuffer);
let randomNumber = randomBuffer[0] / (0xffffffff + 1);
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(randomNumber * (max - min + 1)) + min;
}
function getRandom(max) {
return getRandomIntInclusive(0, max - 1);
}
function AtPos(str, position, newStr) {
return str.slice(0, position) + newStr + str.slice(position);
}
function TypoSTR(str) {
if (str.length === 0) return;
let words = str.split(' ');
words.forEach((word, index) => {
if (word.length === 0) return;
// For security links and email addresses wont get a typo
if (word.includes('://') || word.includes('@')) return;
if (getRandom(2)) words[index] = Typo(word);
});
return words.join(' ');
}
function Typo(word) {
let index = getRandom(word.length);
let letter = word[index];
// If chosen is a number then ignore
if (!isNaN(letter)) return word;
let newString = AtPos(word, index, letter);
if (getRandom(2)) newString = AtPos(newString, index, letter);
return newString;
}
function Typoifier(tagName) {
document.querySelectorAll(tagName).forEach(e => {
e.childNodes.forEach(node => {
if (node.data === "" || node.data === undefined) return
node.data = TypoSTR(node.data);
})
});
};