-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
40 lines (35 loc) · 1.4 KB
/
main.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
// we use github as a prefix because this reduces latency on updates
var prefix = 'https://raw.githubusercontent.com/mafiaclub/mafiaclub.github.io/master';
var tierFileFor = function(tierID) {
return 'tiers/' + tierID + '.json';
}
// Takes a json object of all of the role data and a role name and produces
// the object representing that role, with additional information.
// Returns undefined if the role is not defined.
var getRoleData = function(allRoleData, roleName) {
return allRoleData.find(x => x.name === roleName);
}
var toArray = function(x) {
if (x === undefined) {
return [];
} else {
return [x];
}
}
// https://stackoverflow.com/questions/7753448/how-do-i-escape-quotes-in-html-attribute-values
function quoteattr(s, preserveCR) {
preserveCR = preserveCR ? ' ' : '\n';
return ('' + s) /* Forces the conversion to string. */
.replace(/&/g, '&') /* This MUST be the 1st replacement. */
.replace(/'/g, ''') /* The 4 other predefined entities, required. */
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
/*
You may add other replacements here for HTML only
(but it's not necessary).
Or for XML, only if the named entities are defined in its DTD.
*/
.replace(/\r\n/g, preserveCR) /* Must be before the next replacement. */
.replace(/[\r\n]/g, preserveCR);
}