-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
77 lines (63 loc) · 1.92 KB
/
background.html
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
<script>
// Array to hold callback functions
var callbacks = [];
// This function is called onload in the popup code
function getPageInfo(callback)
{
// Add the callback to the queue
callbacks.push(callback);
// Injects the content script into the current page
chrome.tabs.executeScript(null, { file: "js/content_script.js" });
};
// Perform the callback when a request is received from the content script
chrome.extension.onRequest.addListener(function(request)
{
// Get the first callback in the callbacks array
// and remove it from the array
var callback = callbacks.shift();
// Call the callback function
callback(request);
});
</script>
<script>
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
if(changeInfo.status == "loading"){
//chrome.tabs.executeScript(tabId, { file: "js/pageLoaded.js" });
var q;
var tabURL = tab.url;
q = queryValue(tabURL, 'q');
if(q!=null) {
chrome.browserAction.setBadgeText({'text': '+'});
} else {
//Look at domain name and see if we can recognize it
var domain;
var re1='.*?'; // Non-greedy match on filler
var re2='((?:[a-z][a-z\\.\\d\\-]+)\\.(?:[a-z][a-z\\-]+))(?![\\w\\.])'; // Fully Qualified Domain Name 1
var p = new RegExp(re1+re2,["i"]);
var m = p.exec(tabURL);
if (m != null)
{
domain=m[1];
}
if(domain=='www.ncbi.nlm.nih.gov') {
if(queryValue(tabURL, 'term')!=null) {
chrome.browserAction.setBadgeText({'text': '+'});
}
}
else {
chrome.browserAction.setBadgeText({'text': ''});
}
}
function queryValue(url, name) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec(url);
if( results == null )
return;
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
}
});
</script>