-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
52 lines (45 loc) · 1.22 KB
/
Copy pathutils.js
File metadata and controls
52 lines (45 loc) · 1.22 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
function getRandomElement(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
function random(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
/**
* Returns a new array without duplicates. Does not modify original array.
*/
function removeDuplicates(list) {
return list.reduce((acc, element) => {
if (element && !acc.includes(element)) return [...acc, element];
return acc;
}, []);
}
/**
* Modifies the original array and whenever predicateFn returns true (given an array element),
* it removes that element from the array
*/
function remove(array, predicateFn) {
for (let i = array.length - 1; i > -1; i--) {
if (predicateFn(array[i])) array.splice(i, 1);
}
}
function clearBadge() {
chrome.browserAction.setBadgeText({ text: '' });
}
function getCurrentTab() {
return new Promise(resolve => {
chrome.tabs.query({ active: true, currentWindow: true }, tabs => {
resolve(tabs[0]);
});
});
}
function getDateFromTime(time) {
const date = new Date();
const [hourStr, minStr] = time.split(':');
date.setHours(Number(hourStr), Number(minStr), 0);
return date;
}
function getMidnightDate() {
const date = new Date();
date.setHours(0, 0, 0);
return date;
}