-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
110 lines (103 loc) · 3.86 KB
/
Copy pathscript.js
File metadata and controls
110 lines (103 loc) · 3.86 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
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
//JSON syntax highlighting. Found this somewhere on stackoverflow
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
json = json.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
function getURL(eP, key, params) {
var url = "https://api.guildwars2.com"+eP+"?1";
key ? url += "&access_token="+key : "";
if (params) {
params.ids ? url += "&ids=" + params.ids : "";
params.lang ? url += "&lang=" + params.lang : "";
params.cid ? url = url.replace(":id", params.cid) : "";
params.cbo ? url = url.replace(":board", params.cbo) : "";
params.cre ? url = url.replace(":region", params.cre) : "";
params.cgi ? url = url.replace(":guild_id", params.cgi) : "";
params.cte ? url = url.replace(":team", params.cte) : "";
}
return url;
}
var guids = JSON.parse(localStorage.getItem("guids") || "[]");
$.each(guids, function(i, key) {
$.getJSON(getURL("/v2/account", key), function(accData) {
$("#comptes").append("<label><input type=\"radio\" name=\"compte\" value=\""+key+"\">"+accData.name+"</label><br>");
$.getJSON(getURL("/v2/characters", key), function(result) {
var thediv = $("<persos/>").addClass("hidden");
$.each(result, function(i, perso) {
thediv.append("<label><input type=\"radio\" name=\"perso\" value=\""+perso+"\">"+perso+"</label><br>");
});
$("input[value=\""+key+"\"]").parent().next("br").after(thediv);
}).done(addEv);
});
});
$.getJSON("https://api.guildwars2.com/v2.json", function(data) {
$.each(data.routes, function(i, ep) {
var ald = ep.lang === true ? "l" : "";
ald += ep.auth === true ? " a" : "";
ald += ep.active === true ? "" : " d";
$("#eps").append($("<label/>", {class: ald, text: ep.path}).prepend($("<input/>", {type: "radio", name: "ep"})), $("<br/>"));
});
}).done(addEv);
$(window).on("load", function() {
if (guids) {
$.each(guids, function() {
$("#keyList").append(this+"\n");
});
$("#keyList").html($("#keyList").val().replace(/\n$/, ""));
}
$("#saveKeys").click(function() {
localStorage.setItem("guids", JSON.stringify($("#keyList").val().split(/\n| |,/)));
});
$("#delKeys").click(function() {
localStorage.removeItem("guids");
$("#keyList").empty();
});
$(".flag").click(function() {
$(this).siblings().addClass("d");
$(this).is(":not(.d)") ? $(this).addClass("d") : $(this).removeClass("d");
getData();
});
});
function addEv() {
$("input").off();
$("input").change(getData);
$("label").off();
$("input[name=\"compte\"]").parent().click(function() {
$("input[name=\"perso\"]").prop("checked",false);
$("persos").addClass("hidden");
$(this).next().next("persos").removeClass("hidden");
});
}
function getData() {
var params = {
lang: $(".flag:not(.d)").attr("lang"),
ids: $("#ids").val(),
cid: $("input[name=\"perso\"]").is(":checked") ? $("input[name=\"perso\"]:checked").val() : $("#cid").val(),
cbo: $("#cbo").val(),
cre: $("#cre").val(),
cgi: $("#cgi").val(),
cte: $("#cte").val()
};
$.getJSON(getURL($("input[name=\"ep\"]:checked").parent().text(), $("input[name=\"compte\"]:checked").val(), params), function(data) {
$("#content").html($("<pre/>").html(syntaxHighlight(data)));
}).fail(function(data, err) {
$("#content").html($("<pre/>").html(syntaxHighlight(data.responseText)));
});
}