2022-03-30 00:03:30 +02:00
|
|
|
<script type="text/discourse-plugin" async>
|
2018-08-01 13:19:01 +02:00
|
|
|
// GNU-GPL-3.0-or-later
|
|
|
|
|
2018-08-01 13:15:59 +02:00
|
|
|
var its = (function() {
|
|
|
|
if(!$ || !$.ajax || !WebSocket) {
|
|
|
|
console.log('')
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
const logos_small = {
|
2022-03-30 00:03:30 +02:00
|
|
|
'open': settings.theme_uploads.logo_green,
|
|
|
|
'closed': settings.theme_uploads.logo_red,
|
|
|
|
'error': settings.theme_uploads.logo_yellow
|
2018-08-01 13:15:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const logos_big = {
|
2022-03-30 00:03:30 +02:00
|
|
|
'open': settings.theme_uploads.logo_name_green,
|
|
|
|
'closed': settings.theme_uploads.logo_name_red,
|
|
|
|
'error': settings.theme_uploads.logo_name_yellow
|
2018-08-01 13:15:59 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
var url = new URL(new URL(location.href).origin);
|
|
|
|
url.protocol = url.protocol == 'https:' ? 'wss' : 'ws';
|
|
|
|
url += 'its-open-ws/';
|
|
|
|
|
2018-08-01 13:49:07 +02:00
|
|
|
|
|
|
|
var reconnect_delay = 1000;
|
|
|
|
var reconnect_giveup = 1000000;
|
|
|
|
|
2018-08-01 13:15:59 +02:00
|
|
|
function connect() {
|
2018-08-01 13:49:07 +02:00
|
|
|
if(reconnect_delay > reconnect_giveup)
|
|
|
|
return;
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
console.log('isitopen: reconnecting');
|
|
|
|
var ws = new WebSocket(url);
|
|
|
|
register(ws);
|
|
|
|
|
|
|
|
}, reconnect_delay);
|
|
|
|
|
|
|
|
reconnect_delay *= 2;
|
2018-08-01 13:15:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function refresh() {
|
2018-08-06 17:32:54 +02:00
|
|
|
$.get('https://it-syndikat.org/api/status.txt')
|
|
|
|
.then(function(data) {
|
|
|
|
var a = data.split(',');
|
|
|
|
var isitopen = a[0];
|
|
|
|
var up_date = new Date(parseInt(a[1]) * 1000);
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
2018-08-01 13:15:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2021-01-17 11:15:18 +01:00
|
|
|
} else if($('.logo-mobile').length > 0) {
|
|
|
|
$('.logo-mobile').bind('DOMNodeRemoved', function(){ update_dom(state) });
|
|
|
|
$('.logo-mobile').attr('src', logos_big[state]).css('display', 'block');
|
2018-08-01 13:15:59 +02:00
|
|
|
} 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>
|