telebit.js/lib/html/js/app.js

50 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2018-06-08 06:46:07 +00:00
(function () {
'use strict';
document.body.hidden = false;
2019-05-28 23:07:45 +00:00
var hash = window.location.hash.replace(/^[\/#?]+/, '');
2018-06-08 08:50:00 +00:00
var query = window.location.search;
2018-06-08 06:46:07 +00:00
function parseQuery(search) {
var args = search.substring(1).split('&');
var argsParsed = {};
var i, arg, kvp, key, value;
for (i=0; i < args.length; i++) {
arg = args[i];
if (-1 === arg.indexOf('=')) {
argsParsed[decodeURIComponent(arg).trim()] = true;
} else {
kvp = arg.split('=');
key = decodeURIComponent(kvp[0]).trim();
value = decodeURIComponent(kvp[1]).trim();
argsParsed[key] = value;
}
}
return argsParsed;
}
2018-06-08 08:50:00 +00:00
document.querySelectorAll('.js-servername').forEach(function ($el) {
$el.innerText = window.location.host;
});
2018-06-08 06:46:07 +00:00
console.log(parseQuery(hash));
2018-06-08 08:50:00 +00:00
console.log(parseQuery(query));
var port = parseQuery(hash).serviceport || parseQuery(query).serviceport;
if (port) {
document.querySelector('.js-port').hidden = false;
document.querySelectorAll('.js-serviceport').forEach(function ($el) {
$el.innerText = port;
});
}
2018-06-08 06:46:07 +00:00
}());