98 lines
3.4 KiB
HTML
98 lines
3.4 KiB
HTML
<script async>
|
|
// GNU-GPL-3.0-or-later
|
|
|
|
var its = (function() {
|
|
if(!$ || !$.ajax || !WebSocket) {
|
|
console.log('')
|
|
return;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
const logos_small = {
|
|
'open': 'https://git.it-syndikat.org/IT-Syndikat/its-logo-ci-designs/raw/branch/master/Logo2013/meta/light/logo2013_green.svg',
|
|
'closed': 'https://git.it-syndikat.org/IT-Syndikat/its-logo-ci-designs/raw/branch/master/Logo2013/meta/light/logo2013_red.svg',
|
|
'error': 'https://git.it-syndikat.org/IT-Syndikat/its-logo-ci-designs/raw/branch/master/Logo2013/meta/light/logo2013_yellow.svg'
|
|
}
|
|
|
|
const logos_big = {
|
|
'open': 'https://git.it-syndikat.org/IT-Syndikat/its-logo-ci-designs/raw/branch/master/Logo2013/meta/light/logo2013_name_green.svg',
|
|
'closed': 'https://git.it-syndikat.org/IT-Syndikat/its-logo-ci-designs/raw/branch/master/Logo2013/meta/light/logo2013_name_red.svg',
|
|
'error': 'https://git.it-syndikat.org/IT-Syndikat/its-logo-ci-designs/raw/branch/master/Logo2013/meta/light/logo2013_name_yellow.svg'
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
var url = new URL(new URL(location.href).origin);
|
|
url.protocol = url.protocol == 'https:' ? 'wss' : 'ws';
|
|
url += 'its-open-ws/';
|
|
|
|
|
|
var reconnect_delay = 1000;
|
|
var reconnect_giveup = 1000000;
|
|
|
|
function connect() {
|
|
if(reconnect_delay > reconnect_giveup)
|
|
return;
|
|
|
|
setTimeout(function() {
|
|
console.log('isitopen: reconnecting');
|
|
var ws = new WebSocket(url);
|
|
register(ws);
|
|
|
|
}, reconnect_delay);
|
|
|
|
reconnect_delay *= 2;
|
|
}
|
|
|
|
function refresh() {
|
|
$.get('https://spaceapi.it-syndikat.org/api/status-s.php')
|
|
.then(function(isitopen) {
|
|
var state;
|
|
|
|
if(isitopen === 'true')
|
|
state = 'open';
|
|
else if(isitopen === 'false')
|
|
state = 'closed';
|
|
else
|
|
state = 'error';
|
|
|
|
console.log('isitopen: it is', state);
|
|
update_dom(state);
|
|
}, function() {
|
|
console.log('isitopen: it is', 'error');
|
|
update_dom('error');
|
|
});
|
|
}
|
|
|
|
function update_dom(state) {
|
|
setTimeout(function() {
|
|
console.log('update_dom', state);
|
|
|
|
if($('.logo-big').length > 0) {
|
|
$('.logo-big').bind('DOMNodeRemoved', function(){ update_dom(state) });
|
|
$('.logo-big').attr('src', logos_big[state]).css('display', 'block');
|
|
} else if($('.logo-mobile').length > 0) {
|
|
$('.logo-mobile').bind('DOMNodeRemoved', function(){ update_dom(state) });
|
|
$('.logo-mobile').attr('src', logos_big[state]).css('display', 'block');
|
|
} else if($('.logo-small').length > 0) {
|
|
$('.logo-small').bind('DOMNodeRemoved', function(){ update_dom(state) });
|
|
$('.logo-small').attr('src', logos_small[state]).css('display', 'block');
|
|
}
|
|
})
|
|
}
|
|
|
|
function register(ws) {
|
|
ws.onclose = function() { connect(); };
|
|
ws.onmessage = function(event) { refresh(); };
|
|
}
|
|
|
|
refresh();
|
|
connect();
|
|
|
|
return {
|
|
'update_dom': update_dom,
|
|
'refresh': refresh
|
|
};
|
|
})();
|
|
</script>
|