forked from latestchatty/chromeshack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.js
47 lines (42 loc) · 1.02 KB
/
common.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
function getDescendentByTagAndClassName(parent, tag, class)
{
var descendents = parent.getElementsByTagName(tag);
for (var i = 0; i < descendents.length; i++)
{
if (descendents[i].className.indexOf(class) == 0)
return descendents[i];
}
}
function stripHtml(html)
{
return String(html).replace(/(<([^>]+)>)/ig, '');
}
function insertStyle(css)
{
var style = document.createElement("style");
style.type = "text/css";
style.appendChild(document.createTextNode(css));
document.getElementsByTagName("head")[0].appendChild(style);
}
Array.prototype.contains = function(obj)
{
var i = this.length;
while (i--)
{
if (this[i] == obj)
return true;
}
return false;
}
String.prototype.trim = function()
{
return this.replace(/^\s+|\s+$/g,"");
}
// utility function to make an XMLHttpRequest
function getUrl(url, callback)
{
chrome.extension.sendRequest({"name": "getUrl", "url": url}, function(response)
{
callback(response);
});
}