This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
forked from mikecann/Chrome-Crawler
-
Notifications
You must be signed in to change notification settings - Fork 3
/
helpers.js
69 lines (60 loc) · 1.62 KB
/
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
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
var settings = {
get maxDepth() { return localStorage["max-crawl-depth"]!=null?localStorage["max-crawl-depth"]:2; },
set maxDepth(val) { localStorage['max-crawl-depth'] = val; },
get root() { return localStorage["root"]!=null?localStorage["root"]:""; },
set root(val) { localStorage['root'] = val; },
}
function startsWith(s, str){
return (s.indexOf(str) === 0);
}
function tabQuery(query) {
return new Promise((resolve, reject) => {
chrome.tabs.query(query, resolve);
});
}
function debounce(func, wait, immediate) {
var timeout, args, context, timestamp, result;
var later = function () {
var last = Date.now() - timestamp;
if (last < wait) {
timeout = setTimeout(later, wait - last);
} else {
timeout = null;
if (!immediate) {
result = func.apply(context, args);
context = args = null;
}
}
};
return function () {
context = this;
args = arguments;
timestamp = Date.now();
var callNow = immediate && !timeout;
if (!timeout) {
timeout = setTimeout(later, wait);
}
if (callNow) {
result = func.apply(context, args);
context = args = null;
}
return result;
};
}
function timeout(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms);
});
}
function symbolKey(symbol) {
return '__URL__' + symbol.scriptUrl + '__NAME__' + symbol.name;
}
function uniq(a, keyFunc) {
var seen = {};
return a.filter(function(item) {
var key = keyFunc(item);
return (key in seen) ? false : (seen[key] = true);
});
}