-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
62 lines (53 loc) · 1.89 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
var extensionId = "agnaejlkbiiggajjmnpmeheigkflbnoo"; //Chrome
if (typeof browser !== 'undefined' && typeof chrome !== "undefined") {
extensionId = "{57081fef-67b4-482f-bcb0-69296e63ec4f}"; //Firefox
}
let watching = false;
let watchingData = {}
chrome.runtime.onMessageExternal.addListener(function (request, sender, sendResponse) {
if (request.action === "presence") {
console.log('Presence requested', request);
sendResponse(getPresence(watchingData["title"], watchingData["paused"]));
}
return true;
});
// Register Presence
chrome.runtime.sendMessage(extensionId, {mode: 'passive'}, function (response) {
console.log('Presence registred', response)
});
function getPresence() {
console.log(watching ? 'Watching' : 'Idle')
if (!watching) {
return {
clientId: '1146413774245462037',
presence: {
//state: new Date().toLocaleString(),
instance: true,
largeImageKey: 'jellyfin',
state: "Idle",
}
};
}
let presence = {
clientId: '1146413774245462037',
presence: {
//state: new Date().toLocaleString(),
instance: true,
largeImageKey: watchingData["thumb"],
details: watchingData["seasonName"] !== undefined ? watchingData["seasonName"] : watchingData["type"],
state: watchingData["title"],
smallImageKey: watchingData["paused"] ? 'pause' : 'play',
}
};
if (watchingData["serieName"] !== undefined) {
presence.presence.state = watchingData["serieName"] + " - " + watchingData["title"];
}
return presence;
}
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === "jellyPresence") {
watching = request.watching;
watchingData = request.watchingData;
}
return true;
});