-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
113 lines (104 loc) · 3.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Browser API compatibility
const browserAPI = typeof browser !== 'undefined' ? browser : chrome;
browserAPI.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.contentScriptQuery == "queryGame") {
var url = `https://www.protondb.com/api/v1/reports/summaries/${request.appId}.json`;
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((response) => {
sendResponse(response);
})
.catch((error) => {
sendResponse({ error: error.message }); // Send an error response if needed
});
return true; // Keep the message channel open
} else if (request.contentScriptQuery == "queryReview") {
var url = `http://protondb.solidet.com/api/reports/${request.appId}`;
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
sendResponse(data);
})
.catch((error) => {
sendResponse({ error: error.message }); // Send an error response if needed
});
return true; // Keep the message channel open
} else if (request.contentScriptQuery == "queryDeckStats") {
var url = `https://store.steampowered.com/saleaction/ajaxgetdeckappcompatibilityreport?nAppID=${request.appId}`;
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
let status = "";
if (!data.success) {
throw new Error(`Error! No game found, success: ${data.success}`);
}
let icon;
const category = data.results.resolved_category;
switch (category) {
case 0:
status = "unknown";
icon = "deck_unknown";
break;
case 1:
status = "unsupported";
icon = "deck_unsupported";
break;
case 2:
status = "playable";
icon = "deck_playable";
break;
case 3:
status = "verified";
icon = "deck_verified";
break;
default:
return;
}
const deckInfo = {
status: status,
icon: icon,
};
sendResponse(deckInfo);
})
.catch((error) => {
sendResponse({ error: error.message }); // Send an error response if needed
});
return true; // Keep the message channel open
} else if (request.contentScriptQuery == "queryPlatforms") {
var url = `https://www.protondb.com/proxy/steam/api/appdetails/?appids=${request.appId}`;
fetch(url)
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then((data) => {
let responseObject=data[request.appId]
let status = "";
if (!responseObject.success) {
throw new Error(`Error! No game found, success: ${data.success}`);
}
sendResponse(responseObject.data.platforms);
})
.catch((error) => {
sendResponse({ error: error.message }); // Send an error response if needed
});
return true; // Keep the message channel open
}
});