From f059a352774c19a084b3dddf4128ef911a210065 Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 10 Sep 2017 15:24:50 +0200 Subject: [PATCH 1/2] Add eslintignore and adhere or be ignored --- .eslintignore | 9 +++++++++ jssrc/term_input.js | 2 +- jssrc/term_screen.js | 32 ++++++++++++++------------------ jssrc/utils.js | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..5db3e80 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,9 @@ +# possibly minified output +js +out + +# libraries +jssrc/lib + +# php generated file +jssrc/lang.js diff --git a/jssrc/term_input.js b/jssrc/term_input.js index 31141ce..ea40585 100644 --- a/jssrc/term_input.js +++ b/jssrc/term_input.js @@ -228,7 +228,7 @@ window.Input = (function () { // Mouse events onMouseMove: function (x, y) { if (!opts.mt_move) return - const b = mb1 ? 1 : mb2 ? 2 : mb3 ? 3 : 0; + const b = mb1 ? 1 : mb2 ? 2 : mb3 ? 3 : 0 const m = packModifiersForMouse() Conn.send('m' + encode2B(y) + encode2B(x) + encode2B(b) + encode2B(m)) }, diff --git a/jssrc/term_screen.js b/jssrc/term_screen.js index e1df62f..689be1c 100644 --- a/jssrc/term_screen.js +++ b/jssrc/term_screen.js @@ -47,26 +47,22 @@ const themes = [ // should not be used to look up 0-15 (will return transparent) const colorTable256 = new Array(16).fill('rgba(0, 0, 0, 0)') -{ - // fill color table - - // colors 16-231 are a 6x6x6 color cube - for (let red = 0; red < 6; red++) { - for (let green = 0; green < 6; green++) { - for (let blue = 0; blue < 6; blue++) { - let redValue = red * 40 + (red ? 55 : 0) - let greenValue = green * 40 + (green ? 55 : 0) - let blueValue = blue * 40 + (blue ? 55 : 0) - colorTable256.push(`rgb(${redValue}, ${greenValue}, ${blueValue})`) - } +// fill color table +// colors 16-231 are a 6x6x6 color cube +for (let red = 0; red < 6; red++) { + for (let green = 0; green < 6; green++) { + for (let blue = 0; blue < 6; blue++) { + let redValue = red * 40 + (red ? 55 : 0) + let greenValue = green * 40 + (green ? 55 : 0) + let blueValue = blue * 40 + (blue ? 55 : 0) + colorTable256.push(`rgb(${redValue}, ${greenValue}, ${blueValue})`) } } - - // colors 232-255 are a grayscale ramp, sans black and white - for (let gray = 0; gray < 24; gray++) { - let value = gray * 10 + 8 - colorTable256.push(`rgb(${value}, ${value}, ${value})`) - } +} +// colors 232-255 are a grayscale ramp, sans black and white +for (let gray = 0; gray < 24; gray++) { + let value = gray * 10 + 8 + colorTable256.push(`rgb(${value}, ${value}, ${value})`) } class TermScreen { diff --git a/jssrc/utils.js b/jssrc/utils.js index a0c055b..aa09f9e 100755 --- a/jssrc/utils.js +++ b/jssrc/utils.js @@ -48,7 +48,7 @@ function extend (defaults, options) { /** Escape string for use as literal in RegExp */ function rgxe (str) { - return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&') + return str.replace(/[-[\]/{}()*+?.\\^$|]/g, '\\$&') } /** Format number to N decimal places, output as string */ From f6f804bd14b209a45e441fbc24bd7882c9678baf Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 10 Sep 2017 15:27:52 +0200 Subject: [PATCH 2/2] Remove String#format in favor of template strings --- jssrc/utils.js | 36 ------------------------------------ jssrc/wifi.js | 7 ++++--- 2 files changed, 4 insertions(+), 39 deletions(-) diff --git a/jssrc/utils.js b/jssrc/utils.js index aa09f9e..9b53a5b 100755 --- a/jssrc/utils.js +++ b/jssrc/utils.js @@ -72,42 +72,6 @@ Math.log10 = Math.log10 || function (x) { return Math.log(x) / Math.LN10 } -/** - * Perform a substitution in the given string. - * - * Arguments - array or list of replacements. - * Arguments numeric keys will replace {0}, {1} etc. - * Named keys also work, ie. {foo: "bar"} -> replaces {foo} with bar. - * - * Braces are added to keys if missing. - * - * @returns {String} result - */ -String.prototype.format = function () { - let out = this - let repl = arguments - - if (arguments.length == 1 && (Array.isArray(arguments[0]) || typeof arguments[0] == 'object')) { - repl = arguments[0] - } - - for (let ph in repl) { - if (repl.hasOwnProperty(ph)) { - const ph_orig = ph - - if (!ph.match(/^\{.*\}$/)) { - ph = '{' + ph + '}' - } - - // replace all occurrences - const pattern = new RegExp(rgxe(ph), 'g') - out = out.replace(pattern, repl[ph_orig]) - } - } - - return out -} - /** HTML escape */ function e (str) { return $.htmlEscape(str) diff --git a/jssrc/wifi.js b/jssrc/wifi.js index cab085b..3669241 100644 --- a/jssrc/wifi.js +++ b/jssrc/wifi.js @@ -82,10 +82,11 @@ } let inner = mk('div') + let escapedSSID = $.htmlEscape(ap.essid) $(inner).addClass('inner') - .htmlAppend('
{0}
'.format(ap.rssi_perc)) - .htmlAppend('
{0}
'.format($.htmlEscape(ap.essid))) - .htmlAppend('
{0}
'.format(authStr[ap.enc])) + .htmlAppend(`
${ap.rssi_perc}
`) + .htmlAppend(`
${escapedSSID}
`) + .htmlAppend(`
${authStr[ap.enc]}
`) $item.on('click', function () { let $th = $(this)