-
Notifications
You must be signed in to change notification settings - Fork 4
/
stayfocused.js
66 lines (58 loc) · 2.07 KB
/
stayfocused.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
var stayfocused = {};
stayfocused.DEFAULT_DELAY_SECONDS = 20 // *1000 for milliseconds used by js
if (localStorage.stayfocused_DELAY_SECONDS) {
stayfocused.PAUSE = localStorage.stayfocused_DELAY_SECONDS*1000;
} else {
stayfocused.PAUSE = stayfocused.DEFAULT_DELAY_SECONDS*1000;
}
if (localStorage.stayfocused_ALLOWED_URLS) {
var allowed_urls = localStorage.stayfocused_ALLOWED_URLS;
} else {
var allowed_urls = ["venmo.com",
"devvenmo.com",
"google.com",
"stackoverflow.com",
"s-static.ak.fbcdn.net",
"asana.com",
"assistly.com",
"venmohelp.com",
"amazonaws.com",
"amazon.com",
"facebook.com",
"secure.linkpt.net",
"braintreepaymentgateway.com",
"mongodb.org",
"myclientline.net",
"dropbox.com",
"screencast.com",
"djangoproject.com"];
}
stayfocused.delay_page_load = function() {
if (localStorage.stayfocused_ON_OR_OFF && localStorage.stayfocused_ON_OR_OFF != "off") {
var on_or_off = 1;
} else {
var on_or_off = 0;
}
on_or_off = 1;
if (on_or_off) {
var host = location.href;
var num_allowed = allowed_urls.length;
var allowed = 0;
for (i=0; i<num_allowed; i++) {
reg_exp = "^.*"+allowed_urls[i]+".*$";
if (host.match(reg_exp)) {
allowed = 1;
break;
}
}
if (!allowed) {
console.log("not an important page: pausing pageload for "+ (stayfocused.PAUSE/1000) +" seconds");
console.log(host);
var date = new Date();
var curDate;
do { curDate = new Date(); }
while ( curDate-date < stayfocused.PAUSE);
}
}
};
stayfocused.delay_page_load();