1
- < html >
1
+ < html lang =" en " >
2
2
< head >
3
3
< title > Log Viewer for Kodi</ title >
4
4
< script type ="text/javascript ">
5
- var offset = 0 ;
6
- var polling = null ;
5
+ let offset = 0 ;
6
+ let polling = null ;
7
7
8
- var param = function ( key , fallback ) {
9
- var query = window . location . search . substring ( 1 ) ;
10
- var parameters = query . split ( '&' ) ;
11
- for ( var i = 0 ; i < parameters . length ; i ++ ) {
12
- var pair = parameters [ i ] . split ( '=' ) ;
13
- if ( pair [ 0 ] == key ) {
14
- return unescape ( pair [ 1 ] ) ;
8
+ const param = function ( key , fallback ) {
9
+ const query = window . location . search . substring ( 1 ) ;
10
+ const parameters = query . split ( '&' ) ;
11
+ for ( let i = 0 ; i < parameters . length ; i ++ ) {
12
+ const pair = parameters [ i ] . split ( '=' ) ;
13
+ if ( pair [ 0 ] === key ) {
14
+ return decodeURI ( pair [ 1 ] ) ;
15
15
}
16
16
}
17
17
return fallback ;
18
- }
18
+ } ;
19
19
20
- var append = function ( text ) {
20
+ const append = function ( text ) {
21
21
if ( text ) {
22
- var element = document . getElementById ( 'tail' ) ;
23
- var scrollDown = element . scrollHeight - element . scrollTop - element . clientHeight < 1 ;
22
+ const element = document . getElementById ( 'tail' ) ;
23
+ const scrollDown = element . scrollHeight - element . scrollTop - element . clientHeight < 1 ;
24
24
element . textContent += text ;
25
25
if ( scrollDown ) {
26
26
element . scrollTop = element . scrollHeight ;
27
27
// element.scrollLeft = 0;
28
28
}
29
29
}
30
- }
30
+ } ;
31
31
32
- var request = function ( uri , callback ) {
33
- var xhr = new XMLHttpRequest ( ) ;
32
+ const request = function ( uri , callback ) {
33
+ const xhr = new XMLHttpRequest ( ) ;
34
34
xhr . open ( 'GET' , uri , true ) ;
35
35
xhr . onreadystatechange = function ( ) {
36
- if ( xhr . readyState == 4 && xhr . status == 200 ) {
37
- var newOffset = xhr . getResponseHeader ( 'X-Seek-Offset' ) ;
38
- if ( newOffset ) offset = parseInt ( newOffset ) ;
36
+ if ( xhr . readyState === 4 && xhr . status === 200 ) {
37
+ const newOffset = xhr . getResponseHeader ( 'X-Seek-Offset' ) ;
38
+ if ( newOffset ) {
39
+ offset = parseInt ( newOffset ) ;
40
+ }
39
41
callback ( xhr . responseText ) ;
40
42
}
41
43
} ;
42
44
xhr . send ( null ) ;
43
- }
45
+ } ;
44
46
45
- var tail = function ( ) {
46
- var uri = '/tail?offset=' + offset ;
47
+ const tail = function ( ) {
48
+ const uri = '/tail?offset=' + offset ;
47
49
request ( uri , append ) ;
48
- }
50
+ } ;
49
51
50
- var refresh = function ( ) {
52
+ const refresh = function ( ) {
51
53
tail ( ) ;
52
54
if ( polling == null ) {
53
- var interval = parseInt ( param ( 'interval' , 3000 ) ) ;
55
+ const interval = parseInt ( param ( 'interval' , 3000 ) ) ;
54
56
polling = window . setInterval ( tail , interval ) ;
55
57
}
56
- }
58
+ } ;
57
59
58
- var sleep = function ( ) {
60
+ const sleep = function ( ) {
59
61
if ( polling != null ) {
60
62
window . clearInterval ( polling ) ;
61
63
polling = null ;
62
64
}
63
- }
65
+ } ;
64
66
65
67
window . onload = refresh ;
66
68
window . onfocus = refresh ;
67
69
window . onblur = sleep ;
68
70
</ script >
69
71
</ head >
70
- < body style ="background: black; color: #ddd; margin: 0px ; ">
71
- < pre id ="tail " style ="white-space: pre-wrap; margin: 0px ; height: 100%; overflow: auto; "> </ pre >
72
+ < body style ="background: black; color: #ddd; margin: 0 ; ">
73
+ < pre id ="tail " style ="white-space: pre-wrap; margin: 0 ; height: 100%; overflow: auto; "> </ pre >
72
74
</ body >
73
75
</ html >
0 commit comments