-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnippets.js
48 lines (46 loc) · 1.6 KB
/
snippets.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
// https://stackoverflow.com/questions/17341122/link-and-execute-external-javascript-file-hosted-on-github
// https://cdn.jsdelivr.net/gh/SaulLawliet/UserScripts/snippets.js
/** 获取Steam已有游戏ID, 只包含在售游戏, 速度快 */
function getAppidListByApi(steamId) {
// let url = `http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=1470922A6B6E5C001546E51ACA5D987B&include_played_free_games=true&steamid=${steamId}`;
let url = `https://steamdb.keylol.com/syncProxy.php?type=own&id=${steamId}`;
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'get',
url: url,
responseType: 'json',
onload: function (result) {
resolve(result.response);
},
onerror: reject,
ontimeout: reject,
})
});
}
/** 获取Steam已有游戏ID, 包含所有游戏, 速度较慢 */
function getAppidListByWeb(steamId) {
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: 'get',
url: `http://steamcommunity.com/profiles/${steamId}/games/?tab=all`,
onload: function (result) {
result.responseText.split('\n').forEach((line) => {
if (line.indexOf('var rgGames') >= 0) {
line = line.replace('var rgGames = ', '');
line = line.replace('];', ']');
const games = JSON.parse(line);
const data = {
response: {
game_count: games.length,
games: games,
}
};
resolve(data);
}
});
},
onerror: reject,
ontimeout: reject,
});
});
}