This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
commons.js
55 lines (48 loc) · 1.71 KB
/
commons.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* global systemLang, systemDictionary, io */
// const socket = io.connect();
(function ($) {
$.extend({
// Case insensative $.inArray (http://api.jquery.com/jquery.inarray/)
// $.inArrayIn(value, array [, fromIndex])
// value (type: String)
// The value to search for
// array (type: Array)
// An array through which to search.
// fromIndex (type: Number)
// The index of the array at which to begin the search.
// The default is 0, which will search the whole array.
inArrayIn: function (elem, arr, i) {
// not looking for a string anyways, use default method
if (typeof elem !== 'string') {
return $.inArray.apply(this, arguments);
}
// confirm array is populated
if (arr) {
var len = arr.length;
i = i ? (i < 0 ? Math.max(0, len + i) : i) : 0;
elem = elem.toLowerCase();
for (; i < len; i++) {
if (i in arr && arr[i].toLowerCase() == elem) {
return i;
}
}
}
// stick with inArray/indexOf and return -1 on no match
return -1;
}
});
})(jQuery);
async function asyncForEach(array, callback) {
for (let index = 0; index < array.length; index++) {
await callback(array [index], index, array);
}
}
function _(word) {
let text = translateWord(word, systemLang, systemDictionary);
for (let i = 1; i < arguments.length; i++) {
if (text.indexOf('%s') !== -1) {
text = text.replace('%s', arguments[i]);
}
}
return text;
}