-
Notifications
You must be signed in to change notification settings - Fork 4
/
content_script.js
117 lines (117 loc) · 2.83 KB
/
content_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
browser.runtime.onMessage.addListener((message) => {
let textarea = false;
let start = 0;
let end = 0;
let sel = window.getSelection();
var enc = sel.toString();
if (document.activeElement) {
let tagname = document.activeElement.tagName.toLowerCase();
if (tagname == "textarea" || tagname == "input") {
textarea = true;
}
}
if(textarea) {
let text = document.activeElement.value;
start = document.activeElement.selectionStart;
end = document.activeElement.selectionEnd;
sel = text.substring (start, end);
enc = sel.toString();
}
switch(message.command) {
case "base64encode":
enc = base64encode(sel.toString());
break;
case "base64decode":
enc = base64decode(sel.toString());
break;
case "disemvowel":
enc = disemowel(sel.toString());
break;
case "entityEncode":
enc = entityEncode(sel.toString());
break;
case "entityDecode":
enc = entityDecode(sel.toString());
break;
case "removeSpaces":
enc = removespaces(sel.toString());
break;
case "reverse":
enc = reverse(sel.toString());
break;
case "rot13":
enc = rot13(sel.toString());
break;
case "timestampEncode":
enc = timestampEncode(sel.toString());
break;
case "timestampDecode":
enc = timestampDecode(sel.toString());
break;
case "urlEncode":
enc = urlEncode(sel.toString());
break;
case "urlDecode":
enc = urlDecode(sel.toString());
break;
case "txt2bin":
enc = txt2bin(sel.toString());
break;
case "txt2hex":
enc = txt2hex(sel.toString());
break;
case "bin2dec":
enc = bin2dec(sel.toString());
break;
case "bin2hex":
enc = bin2hex(sel.toString());
break;
case "bin2oct":
enc = bin2oct(sel.toString());
break;
case "bin2txt":
enc = bin2txt(sel.toString());
break;
case "dec2bin":
enc = dec2bin(sel.toString());
break;
case "dec2hex":
enc = dec2hex(sel.toString());
break;
case "dec2oct":
enc = dec2oct(sel.toString());
break;
case "hex2bin":
enc = hex2bin(sel.toString());
break;
case "hex2dec":
enc = hex2dec(sel.toString());
break;
case "hex2oct":
enc = hex2oct(sel.toString());
break;
case "hex2txt":
enc = hex2txt(sel.toString());
break;
case "oct2bin":
enc = oct2bin(sel.toString());
break;
case "oct2dec":
enc = oct2dec(sel.toString());
break;
case "hex2oct":
enc = oct2hex(sel.toString());
break;
}
if (textarea) {
var prev = document.activeElement.value.substring(0, start);
var next = document.activeElement.value.substring(end);
var text = prev + enc + next;
document.activeElement.value = text;
}
else {
var range = sel.getRangeAt(0);
range.deleteContents();
range.insertNode(document.createTextNode(enc));
}
});