@@ -34,10 +34,56 @@ const observer2 = new MutationObserver(callback);
34
34
observer2 . observe ( document . getElementsByClassName ( "content" ) [ 0 ] , { childList : true , subtree : true } ) ;
35
35
36
36
37
- // Run custom code once the kernel is ready
37
+ // Listen to the kernel status changes
38
38
// https://thebe.readthedocs.io/en/stable/events.html
39
39
thebelab . on ( "status" , function ( evt , data ) {
40
- if ( data . status === 'ready' ) {
40
+ if ( data . status === 'building' ) {
41
+ const elements = document . querySelectorAll ( '.thebelab-cell' ) ;
42
+ elements . forEach ( element => {
43
+ element . style . filter = 'opacity(50%)' ;
44
+ } ) ;
45
+ const element = document . getElementById ( "thebelab-activate-button" ) ;
46
+ element . innerHTML = "Building" ;
47
+ element . style . right = '.4rem' ;
48
+ }
49
+ else if ( data . status === 'built' ) {
50
+ const elements = document . querySelectorAll ( '.thebelab-cell' ) ;
51
+ elements . forEach ( element => {
52
+ element . style . filter = 'opacity(60%)' ;
53
+ } ) ;
54
+ const element = document . getElementById ( "thebelab-activate-button" ) ;
55
+ element . innerHTML = "Built" ;
56
+ element . style . right = '.4rem' ;
57
+ }
58
+ else if ( data . status === 'launching' ) {
59
+ const elements = document . querySelectorAll ( '.thebelab-cell' ) ;
60
+ elements . forEach ( element => {
61
+ element . style . filter = 'opacity(70%)' ;
62
+ } ) ;
63
+ const element = document . getElementById ( "thebelab-activate-button" ) ;
64
+ element . innerHTML = "Launching" ;
65
+ element . style . right = '.4rem' ;
66
+ }
67
+ else if ( data . status === 'failed' ) {
68
+ const elements = document . querySelectorAll ( '.thebelab-cell' ) ;
69
+ elements . forEach ( element => {
70
+ element . style . filter = 'opacity(50%)' ;
71
+ } ) ;
72
+ const element = document . getElementById ( "thebelab-activate-button" ) ;
73
+ element . innerHTML = 'Failed: ' + data . message ;
74
+ element . style . right = '.4rem' ;
75
+ element . style . width = 'auto' ;
76
+ element . style . color = 'red' ;
77
+ }
78
+ else if ( data . status === 'ready' ) {
79
+ const elements = document . querySelectorAll ( '.thebelab-cell' ) ;
80
+ elements . forEach ( element => {
81
+ element . style . filter = 'opacity(100%)' ;
82
+ } ) ;
83
+ const element = document . getElementById ( "thebelab-activate-button" ) ;
84
+ element . innerHTML = "Ready" ;
85
+ element . style . right = null ;
86
+ // Run custom code when the kernel is ready
41
87
const kernel = data . kernel ;
42
88
kernel . requestExecute ( { code : "%display latex" } ) ;
43
89
}
0 commit comments