-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript-utils.js
More file actions
59 lines (59 loc) · 1.57 KB
/
Copy pathscript-utils.js
File metadata and controls
59 lines (59 loc) · 1.57 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
var timeout = null;
function recursiveCall(func, donefunc, delay, level, max_level, done_on_last) {
if (level < max_level) {
if (func) {
func(level);
}
timeout = setTimeout(function() {
recursiveCall(func, donefunc, delay, level + 1, max_level, done_on_last);
}, delay);
} else {
if ((done_on_last) && (donefunc)) {
donefunc();
}
}
if (((level+1) === max_level) && !done_on_last){
if (donefunc) {
donefunc();
}
}
}
function interrupt() {
clearTimeout(timeout);
}
function load_asset(url, outputList, customFunction = null) {
var httpGET = new XMLHttpRequest();
httpGET.onreadystatechange = function() {
if (httpGET.readyState == 4 && httpGET.status == 200) {
outputList.push.apply(outputList, JSON.parse(httpGET.responseText));
if (customFunction) {
customFunction();
}
}
};
httpGET.open("GET", url, true); // true for asynchronous
httpGET.send(null);
}
function getRandomListItem(list) {
return list[Math.floor(Math.random() * list.length)];
}
function getNotSoRandomListItem(list, historyList, maxItems) {
var clean = false;
while (!clean) {
var _item = getRandomListItem(getActiveList());
clean = true;
if ((historyList.length != 0) && (historyList.length < list.length)) {
for (var i = 0; i < historyList.length; i++) {
var previous_item = historyList[i];
if (_item === previous_item) {
clean = false;
break;
}
}
}
}
while (historyList.length > maxItems) {
historyList.shift();
}
return _item;
}