forked from tjhrulz/WebNowPlaying-BrowserExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Background.js
72 lines (65 loc) · 1.81 KB
/
Background.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
function updateEvent()
{
var newURL = "https://github.com/tjhrulz/WebNowPlaying/releases/latest";
chrome.tabs.create(
{"url": newURL}
);
}
function helpEvent()
{
var newURL = "https://github.com/tjhrulz/WebNowPlaying-BrowserExtension/wiki/Troubleshooting";
chrome.tabs.create(
{"url": newURL}
);
}
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
if (request.method && request.method == "flagAsOutdated")
{
chrome.browserAction.setBadgeText(
{"text": "!"}
);
// Red, Green, Blue, Alpha
chrome.browserAction.setBadgeBackgroundColor(
{"color": [255, 0, 0, 255]}
);
chrome.browserAction.setTitle(
{"title": "Connected but plugin is outdated. Click to update"}
);
if (chrome.browserAction.onClicked.hasListeners())
{
chrome.browserAction.onClicked.removeListener(updateEvent);
chrome.browserAction.onClicked.removeListener(helpEvent);
}
chrome.browserAction.onClicked.addListener(updateEvent);
}
else if (request.method && request.method == "flagAsNotConnected")
{
chrome.browserAction.setBadgeText(
{"text": ''}
);
chrome.browserAction.setTitle(
{"title": "Not connected to Rainmeter. Click to troubleshoot"}
);
if (chrome.browserAction.onClicked.hasListeners())
{
chrome.browserAction.onClicked.removeListener(updateEvent);
chrome.browserAction.onClicked.removeListener(helpEvent);
}
chrome.browserAction.onClicked.addListener(helpEvent);
}
else if (request.method && request.method == "flagAsConnected")
{
chrome.browserAction.setBadgeText(
{"text": ''}
);
chrome.browserAction.setTitle(
{"title": "Connected and sending info"}
);
if (chrome.browserAction.onClicked.hasListeners())
{
chrome.browserAction.onClicked.removeListener(updateEvent);
chrome.browserAction.onClicked.removeListener(helpEvent);
}
}
});