From 6357571f7d75f2540423deb1fc74b6c90615b2b7 Mon Sep 17 00:00:00 2001 From: Mathew Date: Thu, 20 Jun 2019 12:41:43 +0200 Subject: [PATCH] cleanup --- public/main.js | 635 ------------------------------------------------- 1 file changed, 635 deletions(-) diff --git a/public/main.js b/public/main.js index 3e755bf..3f31054 100644 --- a/public/main.js +++ b/public/main.js @@ -1,45 +1,3 @@ -// function escapeh(unsafe) { -// if (typeof unsafe != "string") return unsafe; -// return unsafe -// .replace(/&/g, "&") -// .replace(//g, ">") -// .replace(/"/g, """) -// .replace(/'/g, "'") -// } - -// 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 $("").append(name ? name : "number") -// case 'string': return $("").append(name ? name : "string") -// case 'boolean': return $("").append(name ? name : "boolean") -// case 'function': return $("").append(name ? name : "function") -// case 'array': return $("").append(name ? name : "array") -// case 'object': return $("").append(name ? name : "object") -// case 'regex': return $("").append(name ? name : "regex") -// case 'null': return $("").append(name ? name : "null") -// case 'undefined': return $("").append(name ? name : "undefined") -// default: return $("").append(name ? name : "?") -// } - -// } - -// var $collapse = function (n) { -// if (n) { -// return $("") -// .addClass("collapse") -// .append( -// $("") -// .addClass('icon-plus-squared') -// ) -// } else { -// return $("") -// .addClass("collapse") -// .append( -// $("") -// .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 = $(""); - -// 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 -// $("
  • ") -// .append(contentType(content, key)) -// .append(": ") -// .append(`[empty]`) -// ) -// } else { // content not empty -// if (depth > maxd) { // is max depth reached -// $list.append( // function description (max depth reached) -// $("
  • ") -// .append(contentType(content, key)) -// .append(": ") -// .append(`${isWhat(content)}`) -// ) -// } else { // max depth not reached -// $list.append( // continue recursion -// $("
  • ") -// .append(contentType(content, key)) -// .append(": ") -// .append( // collapse button -// $collapse(depth >= maxc) -// ) -// .append($recur(content, depth + 1)) -// ) -// } -// } -// break; - -// case 'function': -// $list.append( -// $("
  • ") -// .append(contentType(content, key)) -// .append(": ") -// .append( -// `${isWhat(content)}` -// ) -// ) -// break; - -// default: -// $list.append( -// $("
  • ") -// .append(contentType(content, key)) -// .append(": ") -// .append(content) -// ) -// break; -// } - -// } - -// if (i > maxn) { - -// $list.append( -// $("
  • ") -// .append( -// $("") -// .append(`... ${i - maxn} more`) -// ) -// ) - -// } - -// if (depth > maxc) { -// $list.hide() -// } - -// return $list - -// } - -// if (typeOf(obj) != "array" && typeOf(obj) != "object") -// return $("").append(contentType(obj)).append(": ").append(obj + "") - -// var $ascii = $("") -// .addClass("ascii") -// .append( -// $("
  • ") -// .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 = $("
    ") - - for (let row of content) { - let tr = $("") - for (let col of row) { - tr.append( - $("").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 `
    ` -} - -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 = $("") - .append(``) - - /*for(let index in lines){ - code.append( - $("") - .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 $("
    ").append(code)
    -
    -	/*for(let index in lines){
    -		indexed+=`${lines[index]}\n`
    -	}
    -
    -	return `
    ${indexed}
    `*/ -} - - 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 += "
  • " + res['network'][i] + "
  • "; -// } -// nl += '
  • Raspberry
  • '; -// $(".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(''); -// }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 += "
    " + con.returnError("Done", "ok"); -// response += "
    #### " + data.title + ": ####" - -// // top #10 words -// let v = b.slice(0, 10); -// var tp = []; -// for (let key in v) { -// tp.push(["" + decodeURIComponent(escape(v[key][0])) + "", v[key][1]]); -// } -// response += toTable(tp); - -// // words by participant -// var partic = []; -// for (let key in data.participants) { -// partic.push(["" + decodeURIComponent(escape(data.participants[key].name)) + "", data.participants[key].w.length]) -// // response += "
    "+decodeURIComponent(escape(data.participants[key].name))+" words: "+data.participants[key].w.length; -// } -// response += toTable(partic); - -// // response += toTable([ -// // ["Monday", d[0]], -// // ["Tuesday", d[1]], -// // ["Wednesday", d[2]], -// // ["Thursday", d[3]], -// // ["Friday", d[4]], -// // ["Saturday", d[5]], -// // ["Sunday", 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([ -// ["Total messages", data.messages.length], -// ["Total words", w], -// ["Unique words", a.length], -// ["Total photos", p], - -// ["Parsing time", (performance.now() - perf) + "ms"] -// ]) - -// // response += "
    "+"Unique words: "+a.length; -// // response += "
    "+"Total photos: "+p; -// // response += "
    "+"Total words: "+w; -// // response += "
    "+"Parsing time: "+(performance.now()-perf)+"ms"; - -// } else { -// response += "
    " + con.returnError("JSON structure invalid", "error"); -// } -// } else { -// response += "
    " + con.returnError("Invalid message file", "error"); -// } -// } else { -// response += "
    " + 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 += "
    " + con.returnError("Checking data", "info"); -// if (typeof data != "undefined") { - -// // check if participants are defined -// response += "
    " + con.returnError("Loading participants", "info"); -// if (typeof data.participants != "undefined") { - -// response += "
    " + 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 += "
    " + 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)) + ": " + decodeURIComponent(escape(messages[key].content))); - -// // break if requested amount is parsed -// if (typeof amount != "undefined") -// if (amount > 0) -// if (key == amount) break; -// } - -// } else { -// response += "
    " + con.returnError("JSON structure invalid", "error"); -// } -// } else { -// response += "
    " + con.returnError("Invalid message file", "error"); -// } -// } else { -// response += "
    " + con.returnError("No json data loaded", "error"); -// } - -// return null; -// } - class Waiter { constructor(list, f){ this.list = {}