-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.js
146 lines (144 loc) ยท 7.01 KB
/
master.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
window.dvlt = {
data: {
maleEmojis: ["๐ผ", "๐ฆธโโ๏ธ", "๐ฆนโโ๏ธ", "๐ฎโโ๏ธ", "๐ทโโ๏ธ", "๐โโ๏ธ", "๐ต๏ธโโ๏ธ", "๐จโโ๏ธ", "๐จโ๐พ", "๐จโ๐ณ", "๐จโ๐", "๐จโ๐ค", "๐จโ๐ซ", "๐จโ๐ญ", "๐จโ๐ป", "๐จโ๐ผ", "๐จโ๐ง", "๐จโ๐ฌ", "๐จโ๐จ", "๐จโ๐", "๐จโโ๏ธ", "๐จโ๐", "๐จโโ๏ธ", "๐คต", "๐คด", "๐
", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ"],
femaleEmojis: ["๐ผ", "๐ฆธโโ๏ธ", "๐ฆนโโ๏ธ", "๐ฎโโ๏ธ", "๐ทโโ๏ธ", "๐โโ๏ธ", "๐ต๏ธโโ๏ธ", "๐ฉโโ๏ธ", "๐ฉโ๐พ", "๐ฉโ๐ณ", "๐ฉโ๐", "๐ฉโ๐ค", "๐ฉโ๐ซ", "๐ฉโ๐ญ", "๐ฉโ๐ป", "๐ฉโ๐ผ", "๐ฉโ๐ง", "๐ฉโ๐ฌ", "๐ฉโ๐จ", "๐ฉโ๐", "๐ฉโโ๏ธ", "๐ฉโ๐", "๐ฉโโ๏ธ", "๐ฐ", "๐ธ", "๐คถ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ", "๐งโโ๏ธ"],
},
clock: {
now: function () {
return new Date().getTime();
}
},
redirect: {
url: function (url) {
window.location.href = url;
},
},
formatter: {
toPerc: function (number) {
return Math.floor(number * 100) + '%';
}
},
dict: {
merge: function (d1, d2) {
return Object.assign({}, JSON.parse(JSON.stringify(d1)), JSON.parse(JSON.stringify(d2)));
},
},
storage: {
set: function (key, value, sync) {
sync = sync || false;
if (sync) {
firebase.database().ref(key).set(value);
}
return localStorage.setItem(key, JSON.stringify(value));
},
delete: function (key, sync) {
sync = sync || false;
if (sync) {
firebase.database().ref(key).remove();
}
return localStorage.removeItem(key);
},
getAll: function (prefix) {
var values = [];
var keys = Object.keys(localStorage);
for (var i = 0; i < keys.length; i++) {
if (!prefix || keys[i].startsWith(prefix)) {
values.push(dvlt.storage.get(keys[i]));
}
}
return values;
},
get: function (key, sync, callback) {
sync = sync || false;
if (sync && callback) {
firebase.database().ref(key).once('value', function (snapshot) {
var value = snapshot.val();
dvlt.storage.set(key, value, false);
callback(value);
});
}
else {
var item = localStorage.getItem(key);
return JSON.parse(item);
}
}
},
notify: function (text, type, options) {
var defaultOptions = {
text: text,
type: type,
timeout: 5000,
};
options = options || {};
type = type || 'success';
new Noty(Object.assign(defaultOptions, options)).show();
},
array: {
joinProps: function (arr, propName, separator) {
var items = [];
for (var i = 0; i < arr.length; i++) {
items.push(arr[i][propName]);
}
return items.join(separator);
},
},
utils: {
random: function (maxNumber) {
return Math.floor(Math.random() * maxNumber);
},
randomMaleEmoji: function () {
return dvlt.data.maleEmojis[dvlt.utils.random(dvlt.data.maleEmojis.length - 1)];
},
randomFemaleEmoji: function () {
return dvlt.data.femaleEmojis[dvlt.utils.random(dvlt.data.femaleEmojis.length - 1)];
},
randomEmoji: function () {
var emojis = dvlt.data.maleEmojis.concat(dvlt.data.femaleEmojis);
return emojis[dvlt.utils.random(emojis.length - 1)];
},
isMobile: function () {
return window.innerWidth <= 768;
},
uuid: function () {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
},
getUrlParameter: function(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
},
setPageHash: function (hash) {
window.location.href = '#' + hash;
},
getPageHash: function () {
if (window.location.hash) {
return decodeURIComponent(window.location.hash.substring(1));
}
},
},
string: {
capitalize: function (word) {
return word[0].toUpperCase() + word.slice(1);
},
randomName: function () {
var adjectives = ["adamant", "adroit", "amatory", "animistic", "antic", "arcadian", "baleful", "bellicose", "bilious", "boorish", "calamitous", "caustic", "cerulean", "comely", "concomitant", "contumacious", "corpulent", "crapulous", "defamatory", "didactic", "dilatory", "dowdy", "efficacious", "effulgent", "egregious", "endemic", "equanimous", "execrable", "fastidious", "feckless", "fecund", "friable", "fulsome", "garrulous", "guileless", "gustatory", "heuristic", "histrionic", "hubristic", "incendiary", "insidious", "insolent", "intransigent", "inveterate", "invidious", "irksome", "jejune", "jocular", "judicious", "lachrymose", "limpid", "loquacious", "luminous", "mannered", "mendacious", "meretricious", "minatory", "mordant", "munificent", "nefarious", "noxious", "obtuse", "parsimonious", "pendulous", "pernicious", "pervasive", "petulant", "platitudinous", "precipitate", "propitious", "puckish", "querulous", "quiescent", "rebarbative", "recalcitant", "redolent", "rhadamanthine", "risible", "ruminative", "sagacious", "salubrious", "sartorial", "sclerotic", "serpentine", "spasmodic", "strident", "taciturn", "tenacious", "tremulous", "trenchant", "turbulent", "turgid", "ubiquitous", "uxorious", "verdant", "voluble", "voracious", "wheedling", "withering", "zealous"];
var nouns = ["ninja", "chair", "pancake", "statue", "unicorn", "rainbows", "laser", "senor", "bunny", "captain", "nibblets", "cupcake", "carrot", "gnomes", "glitter", "potato", "salad", "toejam", "curtains", "beets", "toilet", "exorcism", "dragons", "jellybeans", "snakes", "dolls", "bushes", "cookies", "apples", "ukulele", "kazoo", "banjo", "circus", "trampoline", "carousel", "carnival", "locomotive", "animator", "artisan", "artist", "colorist", "inker", "coppersmith", "director", "designer", "flatter", "stylist", "leadman", "limner", "model", "musician", "penciller", "producer", "scenographer", "silversmith", "teacher", "beader", "foreman", "mechanic", "miller", "moldmaker", "beater", "patternmaker", "operator", "plumber", "sawfiler", "foreman", "soaper", "engineer", "wheelwright", "woodworkers"];
return dvlt.string.capitalize(adjectives[dvlt.utils.random(adjectives.length - 1)]) + dvlt.string.capitalize(nouns[dvlt.utils.random(nouns.length - 1)]);
},
},
ajax: {
getJSON: function (url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
callback(xhr.status, xhr.response);
};
xhr.send();
}
}
}