-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotabuff.js
More file actions
62 lines (58 loc) · 1.77 KB
/
dotabuff.js
File metadata and controls
62 lines (58 loc) · 1.77 KB
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 api_key = "040FA36AB25776E7072B0B42CAB25A20";
$(document).keypress(e => {
var key = e.which;
if (key == 13) // the enter key code
{
$('#test').click();
return false;
}
});
$("#test").click(() => {
var div = "<div id='info'><img alt='loading' src='https://media.giphy.com/media/y1ZBcOGOOtlpC/giphy.gif'></div>";
$(".output").html(div);
var input = $("input").val();
// https/...../
if (input.slice(-1) === '/') {
input = input.slice(0, -1).replace(/.*\//, "");
} else if (input.includes('/')) {
input = input.replace(/.*\//, "");
}
if (isNaN(input)) {
$.ajax({
url: `https://cors-anywhere.herokuapp.com/https://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=${api_key}&vanityurl=${input}`,
dataType: 'json'
})
.done(data => {
var id_64bit = data.response.steamid;
if (!id_64bit) {
$(".output").html(`Not found 4Head`);
} else {
var id_32bit = convert(id_64bit);
$(".output").html(`<a href = "https://www.dotabuff.com/players/${id_32bit}">Dotabuff</a>`);
$("a").attr("target", "_blank");
}
});
} else {
$.ajax({
url: `https://cors-anywhere.herokuapp.com/http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${api_key}&steamids=${input}`,
dataType: 'json'
})
.done(data => {
if (!data.response.players[0]) {
$(".output").html(`Not found 4Head`);
} else {
var id_32bit = convert(input);
$(".output").html(`<a href = "https://www.dotabuff.com/players/${id_32bit}">Dotabuff</a>`);
$("a").attr("target", "_blank");
}
});
}
});
function convert(bit64) {
var big = bigInt(bit64);
var minus = bigInt('76561197960265728');
var result = big.subtract(minus);
return result.value;
}
});