@@ -11,11 +11,27 @@ class Dripper extends Model
11
11
{
12
12
public function getHtmlAttribute () : string
13
13
{
14
- return '<script>setInterval(function(){ '
15
- . "var e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject('Microsoft.XMLHTTP'); "
16
- . "e.open('GET',' {$ this ->url }',!0); "
17
- . "e.setRequestHeader('X-Requested-With','XMLHttpRequest'); "
18
- . "e.send();}, {$ this ->interval });</script> " ;
14
+
15
+ return '<script> '
16
+ . "let ld = new Date(); "
17
+ . "function caffeineSendDrip () { "
18
+ . " let e = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject('Microsoft.XMLHTTP'); "
19
+ . " e.onreadystatechange = function () { "
20
+ . " if (e.readyState === 4 && e.status === 204) { "
21
+ . " ld = new Date(); "
22
+ . " } "
23
+ . " }; "
24
+ . " e.open('GET', ' {$ this ->url }', !0); "
25
+ . " e.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); "
26
+ . " e.send(); "
27
+ . "} "
28
+ . "setInterval(function () { caffeineSendDrip(); }, $ this ->interval ); "
29
+ . "setInterval(function () { "
30
+ . " if (new Date() - ld >= $ this ->interval + $ this ->threshold ) { "
31
+ . " location.reload(true); "
32
+ . " } "
33
+ . "}, $ this ->checkInterval ); "
34
+ . "</script> " ;
19
35
}
20
36
21
37
public function getIntervalAttribute () : string
@@ -25,6 +41,22 @@ public function getIntervalAttribute() : string
25
41
300000
26
42
);
27
43
}
44
+
45
+ public function getThresholdAttribute () : int
46
+ {
47
+ return config (
48
+ 'genealabs-laravel-caffeine.thresholdDifference ' ,
49
+ 10000
50
+ );
51
+ }
52
+
53
+ public function getCheckIntervalAttribute () : int
54
+ {
55
+ return config (
56
+ 'genealabs-laravel-caffeine.checkLastDripInterval ' ,
57
+ 2000
58
+ );
59
+ }
28
60
29
61
public function getUrlAttribute () : string
30
62
{
0 commit comments