This commit is contained in:
Mathew committed 2019-06-20 12:41:43 +02:00
1 parent e2809ef61a
commit 6357571f7d
1 file changed
-635
-635
View File
@@ -1,45 +1,3 @@
// function escapeh(unsafe) {
// if (typeof unsafe != "string") return unsafe;
// return unsafe
// .replace(/&/g, "&")
// .replace(/</g, "&lt;")
// .replace(/>/g, "&gt;")
// .replace(/"/g, "&quot;")
// .replace(/'/g, "&#039;")
// }
// function argq(arg){
// var v = 0;
// var g = [];
// for (var ar in arg) {
// if((arg[ar].startsWith("\"")) || (arg[ar].startsWith("\'"))){
// v=1;
// // g.push(arg[ar].slice(1));
// if((arg[ar].endsWith("\"")) || (arg[ar].endsWith("\'"))){
// g.push(arg[ar].slice(1, arg[ar].length-1));
// v=0;
// }
// else
// g.push(arg[ar].slice(1));
// continue;
// };
// if((arg[ar].endsWith("\"")) || (arg[ar].endsWith("\'"))){
// v=0;
// g[g.length-1] += " "+arg[ar].slice(0, arg[ar].length-1);
// // g[g.length-1] = g[g.length-1].slice(1, g[g.length-1].length-1);
// continue;
// };
// if(!v){
// g.push(arg[ar]);
// }else{
// g[g.length-1] += " "+arg[ar]
// }
// }
// return g
// }
function isDefined(...d) {
/**
* Check if argument is defined
@@ -205,273 +163,6 @@ function download(content, filename) {
a.remove()
}
// function toTree(obj, mdepth) {
// /**
// * Creates tree visualization of variable
// * @param {any} obj variable to visualize
// * @param {number} mdepth max visualization depth
// *
// * @returns {H} html visualization
// */
// var typeOf = function (o) {
// var t = typeof o;
// if (o instanceof Array) return "array";
// if (o instanceof RegExp) return "regex";
// if (o === null) return "null";
// return t
// }
// var contentType = function (v, name) {
// var type = typeOf(v)
// switch (type) {
// case 'number': return $("<txred></txred>").append(name ? name : "number")
// case 'string': return $("<txgrn></txgrn>").append(name ? name : "string")
// case 'boolean': return $("<txorn></txorn>").append(name ? name : "boolean")
// case 'function': return $("<txcya></txcya>").append(name ? name : "function")
// case 'array': return $("<txyel></txyel>").append(name ? name : "array")
// case 'object': return $("<txblu></txblu>").append(name ? name : "object")
// case 'regex': return $("<txprp></txprp>").append(name ? name : "regex")
// case 'null': return $("<txblk></txblk>").append(name ? name : "null")
// case 'undefined': return $("<txblk></txblk>").append(name ? name : "undefined")
// default: return $("<txblk></txblk>").append(name ? name : "?")
// }
// }
// var $collapse = function (n) {
// if (n) {
// return $("<span></span>")
// .addClass("collapse")
// .append(
// $("<i></i>")
// .addClass('icon-plus-squared')
// )
// } else {
// return $("<span></span>")
// .addClass("collapse")
// .append(
// $("<i></i>")
// .addClass('icon-minus-squared')
// )
// }
// }
// var $recur = function (obj, depth) {
// let m = isDefined(mdepth, Config.treeDepth, 4);
// const maxd = m <= 7 ? m : 7; // max depth
// const maxn = 50; // max level length
// const maxs = 150; // max string length
// const maxc = 2; // level to collapse after
// var $list = $("<ul></ul>");
// var i = 0;
// for (let key in obj) {
// i++;
// if (i > maxn) {
// continue
// }
// var content = obj[key]; // content
// var type = typeOf(obj[key]); // content type
// switch (type) {
// case 'object':
// case 'array':
// if ($.isEmptyObject(content)) { // is content epmty
// $list.append( // empty object
// $("<li></li>")
// .append(contentType(content, key))
// .append(": ")
// .append(`<txpnk>[empty]</txpnk>`)
// )
// } else { // content not empty
// if (depth > maxd) { // is max depth reached
// $list.append( // function description (max depth reached)
// $("<li></li>")
// .append(contentType(content, key))
// .append(": ")
// .append(`<txpnk>${isWhat(content)}</txpnk>`)
// )
// } else { // max depth not reached
// $list.append( // continue recursion
// $("<li></li>")
// .append(contentType(content, key))
// .append(": ")
// .append( // collapse button
// $collapse(depth >= maxc)
// )
// .append($recur(content, depth + 1))
// )
// }
// }
// break;
// case 'function':
// $list.append(
// $("<li></li>")
// .append(contentType(content, key))
// .append(": ")
// .append(
// `<txpnk>${isWhat(content)}</txpnk>`
// )
// )
// break;
// default:
// $list.append(
// $("<li></li>")
// .append(contentType(content, key))
// .append(": ")
// .append(content)
// )
// break;
// }
// }
// if (i > maxn) {
// $list.append(
// $("<li></li>")
// .append(
// $("<txprp></txprp>")
// .append(`... ${i - maxn} more`)
// )
// )
// }
// if (depth > maxc) {
// $list.hide()
// }
// return $list
// }
// if (typeOf(obj) != "array" && typeOf(obj) != "object")
// return $("<span></span>").append(contentType(obj)).append(": ").append(obj + "")
// var $ascii = $("<ul></ul>")
// .addClass("ascii")
// .append(
// $("<li></li>")
// .append(contentType(obj))
// .append(
// $collapse(false)
// )
// .append($recur(obj, 1))
// )
// return $ascii;
// }
function toTable(content) {
/**
* Creates html table from 2D array
* @param {array} content 2d array
*
* @returns {H} html table from array
*/
var $table = $("<table></table>")
for (let row of content) {
let tr = $("<tr></tr>")
for (let col of row) {
tr.append(
$("<td></td>").append(col + "")
)
}
$table.append(tr)
}
return $table
}
function toGraph(data, x, y) {
/**
* Create chart.js graph
* @param {object} data chart.js configuration object
* @param {number} x graph width
* @param {number} y grap height
*
* @returns {H} chart.js html element with init script
*/
var id = makeID(6);
return `<div class="chartdiv"><canvas id="${id}" width="${isDefined(x, 400)}" height="${isDefined(y, 400)}"></canvas></div><script>var ctx = document.getElementById("${id}").getContext("2d");var myChart = new Chart(ctx, JSON.parse('${JSON.stringify(data)}'));</script>`
}
function toSyntax(data, lang) {
/**
* Text syntax highlighting
* @param {string} data text to highlight
* @param [lang] syntax language
*/
if (lang) {
var langs = [];
langs.push(lang)
}
var hl = hljs.highlightAuto(data, lang);
var out = "";
var r = /(\<.*?\>)(.*?)(\<\/[\S]*?\>)/g;
out = hl.value.replace(r, function (match, beg, mid, end) {
// console.log(beg+"|"+mid+"|"+end);
// console.log(beg+ mid.replace(/\n/g, `[\n]`) +end)
return beg + mid.replace(/\n/g, `${end}\n${beg}`) + end
})
// var match = r.exec(hl.value);
// while (match != null) {
// console.log(match[0])
// out += match[1] + match[2].replace("\n", `${match[3]}\n${match[2]}`) + match[3]
// match = r.exec(hl.value);
// }
var lines = out.split("\n");
var code = $("<code></code>")
.append(`<!-- language: ${hl.language}, r: ${hl.r}, second: ${hl.second_best ? hl.second_best.language : undefined}-->`)
/*for(let index in lines){
code.append(
$("<span></span>")
.addClass('hljs-newline')
.append(lines[index])
// .prop( "data-int", " ".repeat( (lines.length.toString().length) - ((parseInt(index)+1).toString().length) ) + (parseInt(index)+1) )
)
.append("\n")
}*/
code.append(hl.value)
return $("<pre></pre>").append(code)
/*for(let index in lines){
indexed+=`<span class="hljs-newline" data-int="${
" ".repeat( (lines.length.toString().length) - ((parseInt(index)+1).toString().length) ) + (parseInt(index)+1)
}">${lines[index]}</span>\n`
}
return `<pre><code>${indexed}</code></pre>`*/
}
function getLocal(key) {
return JSON.parse(localStorage.getItem(key))
}
@@ -523,332 +214,6 @@ function requiresStyle(url) {
}
// function updateInfo(res) {
// // refresh status informations
// // var rp = JSON.parse(res); // parse json
// if (($(".info0")[0]) && (res.type == "uptime")) {
// $(".info0").html(res["uptime"]);
// $(".info1").html(res["load1"]);
// $(".info2").html(res["load2"]);
// $(".info3").html(res["load3"]);
// $(".info4").html(res["memory"]);
// $(".info5").html(res["users"]);
// }
// // update uptime section
// if (($(".info6")[0]) && (res.type == "stats")) {
// $(".info6").html(res["tempout"]);
// $(".info7").html(res["tempin"]);
// $(".info8").html(res["humout"]);
// $(".info9").html(res["humin"]);
// }
// // update stats section
// if (($(".info10")[0]) && (res.type == "network")) {
// var nl = "";
// for (var i = 0; i < res['network'].length; i++) {
// nl += "<li><txcya>" + res['network'][i] + "</txcya></li>";
// }
// nl += '<li><txblu>Raspberry</txblu><ul><li><txred>I2C</txred><ul></ul></li><li><txred>Serial</txred><ul></ul></li></ul></li>';
// $(".info10").html(nl);
// }
// // update devices section
// }
// function setStyle() {
// setstyle: function setstyle(name){ // set style theme
// if(!name) var name = "";
// if(name != ""){
// log("Style: "+name, "info");
// setCookie("style", name);
// $('head').append('<link rel="stylesheet" href="styles/'+name+'.css" type="text/css" />');
// }else{
// log("Style "+name+" doesn't exist, using default preset", "warning");
// setstyle("default");
// }
// },
// }
// function mesparse(data, amount, con) { // parse mesenger chat information
// var response = "";
// var perf = performance.now();
// // check if json is loaded\
// if (typeof data != "undefined") {
// // check if participants are defined\
// if (typeof data.participants != "undefined") {
// l = []; // links
// p = 0; // pics
// a = []; // unique words
// ac = []; // unique words counter
// w = 0; // word counter
// d = [0, 0, 0, 0, 0, 0, 0] // weekdays
// h = new Array(24).fill(0);
// // unique words by participant
// for (let key in data.participants) {
// data.participants[key].w = [];
// }
// // check if messages are defined\
// if (typeof data.messages != "undefined") {
// // parse every message in file
// for (let key in data.messages) {
// // check if content is present
// if (typeof data.messages[key].content != "undefined") {
// let x = new Date();
// x.setTime(data.messages[key].timestamp_ms);
// d[x.getDay()] += 1;
// h[x.getHours()] += 1;
// // check if message is a photo
// if (data.messages[key].photos) {
// p++;
// continue;
// }
// data.messages[key].content = data.messages[key].content.replace(/ +(?= )/g, '');
// words = data.messages[key].content.split(" ");
// for (let word in words) {
// let i = a.indexOf(words[word]);
// if (i == -1) {
// a.push(words[word]);
// ac.push(1);
// } else {
// ac[i] += 1;
// }
// for (let p in data.participants) {
// if (data.messages[key].sender_name == data.participants[p].name)
// data.participants[p].w.push(words[word])
// }
// // if(data.messages[key].sender_name == "Sebastian Fudalej") s.push(words[word]);
// // else if(data.messages[key].sender_name == "Mateusz Pstrucha") m.push(words[word]);
// w++;
// }
// }
// // break if requested amount is parsed
// if (typeof amount != "undefined")
// if (amount > 0)
// if (key == amount) break;
// }
// // merging words and count arrays
// b = [];
// for (let key in a) {
// b.push([a[key], ac[key]]);
// }
// // sorting words by count
// b.sort(function (a, b) {
// if (a[1] === b[1]) {
// return 0;
// }
// else {
// return (a[1] > b[1]) ? -1 : 1;
// }
// });
// response += "<br>" + con.returnError("Done", "ok");
// response += "<br><txpnk>#### " + data.title + ": ####</txpnk>"
// // top #10 words
// let v = b.slice(0, 10);
// var tp = [];
// for (let key in v) {
// tp.push(["<txyel>" + decodeURIComponent(escape(v[key][0])) + "</txyel>", v[key][1]]);
// }
// response += toTable(tp);
// // words by participant
// var partic = [];
// for (let key in data.participants) {
// partic.push(["<txorn>" + decodeURIComponent(escape(data.participants[key].name)) + "</txorn>", data.participants[key].w.length])
// // response += "<br><txorn>"+decodeURIComponent(escape(data.participants[key].name))+"</txorn> words: "+data.participants[key].w.length;
// }
// response += toTable(partic);
// // response += toTable([
// // ["<txred>Monday</txred>", d[0]],
// // ["<txred>Tuesday</txred>", d[1]],
// // ["<txred>Wednesday</txred>", d[2]],
// // ["<txred>Thursday</txred>", d[3]],
// // ["<txred>Friday</txred>", d[4]],
// // ["<txred>Saturday</txred>", d[5]],
// // ["<txred>Sunday</txred>", d[6]]
// // ])
// // let hrs = [];
// // for(let hours in h){
// // hrs.push([hours+":00", h[hours]]);
// // }
// response += toGraph({
// type: 'line',
// data: {
// labels: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23],
// datasets: [{
// label: '# per hour of day',
// data: h,
// backgroundColor: "#ffffff66",
// borderColor: "#ffffff66",
// borderWidth: 1
// }]
// },
// options: {
// maintainAspectRatio: false,
// responsive: false,
// scales: {
// yAxes: [{
// ticks: {
// beginAtZero: true
// }
// }]
// }
// }
// }, 400, 200);
// response += toGraph({
// type: 'line',
// data: {
// labels: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
// datasets: [{
// label: '# per weekday',
// data: d,
// backgroundColor: "#ffffff66",
// borderColor: "#ffffff66",
// borderWidth: 1
// }]
// },
// options: {
// maintainAspectRatio: false,
// responsive: false,
// scales: {
// yAxes: [{
// ticks: {
// beginAtZero: true
// }
// }]
// }
// }
// }, 400, 200);
// response += toTable([
// ["<txcya>Total messages</txcya>", data.messages.length],
// ["<txcya>Total words</txcya>", w],
// ["<txcya>Unique words</txcya>", a.length],
// ["<txcya>Total photos</txcya>", p],
// ["<txcya>Parsing time</txcya>", (performance.now() - perf) + "ms"]
// ])
// // response += "<br>"+"<txcya>Unique words</txcya>: "+a.length;
// // response += "<br>"+"<txcya>Total photos</txcya>: "+p;
// // response += "<br>"+"<txcya>Total words</txcya>: "+w;
// // response += "<br>"+"<txcya>Parsing time</txcya>: "+(performance.now()-perf)+"ms";
// } else {
// response += "<br>" + con.returnError("JSON structure invalid", "error");
// }
// } else {
// response += "<br>" + con.returnError("Invalid message file", "error");
// }
// } else {
// response += "<br>" + con.returnError("No json data loaded", "error");
// }
// return response;
// }
// function mesall(data, amount, con) { // parse mesenger chat information
// var response = "";
// var perf = performance.now();
// // check if json is loaded
// response += "<br>" + con.returnError("Checking data", "info");
// if (typeof data != "undefined") {
// // check if participants are defined
// response += "<br>" + con.returnError("Loading participants", "info");
// if (typeof data.participants != "undefined") {
// response += "<br>" + con.returnError("Initializing variables", "info");
// var colors = {};
// // unique words by participant
// for (let key in data.participants) {
// switch (key) {
// case "0":
// colors[data.participants[key].name] = "txgrn";
// break;
// case "1":
// colors[data.participants[key].name] = "txblu";
// break;
// case "2":
// colors[data.participants[key].name] = "txcya";
// break;
// case "3":
// colors[data.participants[key].name] = "txyel";
// break;
// case "4":
// colors[data.participants[key].name] = "txorn";
// break;
// case "5":
// colors[data.participants[key].name] = "txred";
// break;
// case "6":
// colors[data.participants[key].name] = "txpnk";
// break;
// case "7":
// colors[data.participants[key].name] = "txred";
// break;
// default:
// colors[data.participants[key].name] = "txblk";
// break;
// }
// }
// // check if messages are defined
// response += "<br>" + con.returnError("Parsing messages", "info");
// if (typeof data.messages != "undefined") {
// // parse every message in file
// var messages = data.messages.slice().reverse()
// for (let key in messages) {
// let col = colors[messages[key].sender_name] ? colors[messages[key].sender_name] : "txblk";
// con.log("<" + col + ">" + decodeURIComponent(escape(messages[key].sender_name)) + "</" + col + ">: " + decodeURIComponent(escape(messages[key].content)));
// // break if requested amount is parsed
// if (typeof amount != "undefined")
// if (amount > 0)
// if (key == amount) break;
// }
// } else {
// response += "<br>" + con.returnError("JSON structure invalid", "error");
// }
// } else {
// response += "<br>" + con.returnError("Invalid message file", "error");
// }
// } else {
// response += "<br>" + con.returnError("No json data loaded", "error");
// }
// return null;
// }
class Waiter {
constructor(list, f){
this.list = {}