-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent_script.js
54 lines (50 loc) · 1.05 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
// Object to hold information about the current page
function filterText(text)
{
var maxlength = 90;
var badchars = ["#","@","-","<",">","\n","!","?","&",'"'," "];
var replaces = ["","","","","","","","","","+and+",""," "]
for(var i in badchars)
{
text = text.split(badchars[i]).join(replaces[i]);
}
txtlen = text.length;
if(txtlen > maxlength)
{
text = text.split(' ');
strlen = 0; j = 0; str = [];
lastword = 0; i=0;
while (j < Math.floor(txtlen/maxlength))
{
for(i;strlen<maxlength;i++)
{
if(text[i] === undefined)
{
strlen = maxlength;
}
else
{
strlen = strlen + text[i].length;
if(str[j] == null)
{
str[j] = text[i];
}
else
{
str[j] += '+'+text[i];
}
}
}
strlen = 0;
j++;
}
}
else
{
str[0] = text.split(' ').join('+');
}
return str;
}
var selected = {"text": filterText(window.getSelection().toString()),"unfiltered": window.getSelection().toString()};
// Send the information back to the extension
chrome.extension.sendRequest(selected);