-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
33 lines (29 loc) · 911 Bytes
/
helpers.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
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}
function sanitizeNumber(num) {
/* Turns a number from its shortened form (e.g. $412.34m) into a full
* integer
*/
num = num.replace("$", "");
switch (num[num.length - 1]) {
case "b":
num = parseInt(num.slice(0, -1)) * Math.pow(10, 9);
break;
case "m":
num = parseInt(num.slice(0, -1)) * Math.pow(10, 6);
break;
case "k":
num = parseInt(num.slice(0, -1)) * Math.pow(10, 3);
break;
default:
num = parseInt(num);
}
return num;
}
function div(classname) {
return "div." + classname;
}