-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.user.js
73 lines (63 loc) · 2.75 KB
/
code.user.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
// ==UserScript==
// @name SteamTrades Enhancer
// @namespace https://github.com/Nuklon
// @author Nuklon
// @license MIT
// @version 1.0.0
// @description Enhances SteamTrades
// @require https://code.jquery.com/jquery-3.1.1.min.js
// @require https://raw.githubusercontent.com/caolan/async/master/dist/async.min.js
// @match *://www.steamtrades.com/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function($, async) {
// You can request an API key here: http://steamcommunity.com/dev/apikey
const apiKey = '';
var cache = new Map();
var summaryQueue = async.queue(function (task, next) {
var url = task;
var link = url.attr('href');
var hasAuthorName = typeof url.attr('class') !== 'undefined' && (url.attr('class').includes('author_name') || url.attr('class').includes('underline'));
if (hasAuthorName && typeof link !== 'undefined' && link.includes('/user/')) {
link = link.replace('/user/', '');
var apiUrl = 'https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=' + apiKey +'&steamids=' + link;
if (cache.has(apiUrl)) {
var originalText = url.text();
url.text(originalText + ' → ' + cache.get(apiUrl));
url.attr('title', originalText);
next();
}
else {
GM_xmlhttpRequest({
method: "GET",
url: apiUrl,
onload: function (data) {
if (data.status != 200) {
next();
return;
}
data = data.response;
var json = JSON.parse(data);
if (typeof json !== 'undefined' && typeof json.response !== 'undefined' && typeof json.response.players !== 'undefined') {
if (json.response.players.length > 0) {
if (typeof json.response.players[0].personaname !== 'undefined') {
cache.set(apiUrl, json.response.players[0].personaname);
var originalText = url.text();
url.text(originalText + ' → ' + cache.get(apiUrl));
url.attr('title', originalText);
}
}
}
next();
}});
}
} else {
next();
}
}, 4);
$(document).ready(function() {
$('a').each(function(i) {
summaryQueue.push($(this));
});
});
})(jQuery, async);