forked from willmoffat/Sample-Freebase-Chrome-Extension
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.html
47 lines (41 loc) · 1.29 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
<html>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script> <!-- TODO: switch to .min -->
<script src="freebase.js"></script>
<script>
function setIconEnabled(enabled,tabId) {
var image = 'favicon' + (enabled?'':'-gray') + '.ico';
chrome.browserAction.setIcon( {path:image, tabId:tabId} );
}
function updateBadge(tab) {
fbCache.get(tab.url,function(topic) {
var badge = topic ? '1' : '0';
chrome.browserAction.setBadgeText({ text:badge, tabId:tab.id });
});
}
function setCurrentTopic(topic,callback) {
chrome.tabs.getSelected(null, function(tab) {
fbCache.set(tab.url,topic);
updateBadge(tab);
callback();
});
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (tab.url.indexOf('http://') !== 0) {
setIconEnabled(false, tab.id);
} else {
setIconEnabled(true,tab.id);
if (changeInfo.status == "loading" && changeInfo.url) {
updateBadge(tab); // force fbCache to be updated if this is a new url
}
}
});
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.command == "get_local"){
var url = chrome.extension.getURL(request.resource);
$.get(url, function(data){
sendResponse({data:data});
});
}});
</script>
</html>