From aae10fbc3647a3b598b3fc763d53e9344e2718d4 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 16 Apr 2022 15:36:17 +1000 Subject: [PATCH] More code formatting and fix SQRL --- export.js | 8 +- load/defs.js | 2 +- load/edit.js | 70 +++++++++------- load/frame-ansi.js | 6 +- load/frame-page.js | 4 +- load/frame-viewdata.js | 16 ++-- load/funcs.js | 17 ++-- load/qrcode-make.js | 180 ++++++++++++++++++++--------------------- load/register.js | 14 ++-- load/sqrllogin.js | 11 +-- main.js | 18 ++--- save.js | 4 +- 12 files changed, 182 insertions(+), 168 deletions(-) diff --git a/export.js b/export.js index 655cc57..1f1dd2b 100644 --- a/export.js +++ b/export.js @@ -31,7 +31,7 @@ function getKey(page,signed) { // If it was signed, is the key a value one if (signed && signed.length) { - if (pk == signed) { + if (pk === signed) { //print('SIGNED key is valid:' + signed); key = signed; throw BreakException; @@ -73,7 +73,7 @@ function msgBaseExport(msgbase) { } // If pointer doesnt exist, reset it from the message base. - if (export_ptr == undefined) { + if (export_ptr === undefined) { var f = new File(file_getcase(msgbase.file+'.sbl')); if (f.open('rb')) { @@ -108,7 +108,7 @@ function msgBaseExport(msgbase) { highest = idx.number; // Only check messages from Videotex - if (idx.from != crc16_calc('videotex')) { + if (idx.from !== crc16_calc('videotex')) { log(LOG_DEBUG,'! IGNORING: Message offset ['+i+'] in ['+msgbase.file+']'); continue; } @@ -212,7 +212,7 @@ function msgBaseExport(msgbase) { } f.close(); - if (signed != getKey(frame.frame,signed)) { + if (signed !== getKey(frame.frame,signed)) { log(LOG_ERROR,'! ERROR: Key ['+signed+' is not authorised for message offset ['+i+'] in ['+msgbase.file+']'); continue; } diff --git a/load/defs.js b/load/defs.js index 981bdc2..88676f6 100644 --- a/load/defs.js +++ b/load/defs.js @@ -90,6 +90,6 @@ const HOME_FRAME_AUTH ={frame: 98,index: 'b'}; const HOME_FRAME_CONNECT ={frame: 980,index: 'a'}; /* Attributes saved/loaded from files */ -const SAVED_FRAME_ATTRS =['version','frame','index','owner','cost','content','isPublic','isAccessible','type','key']; +const SAVED_FRAME_ATTRS =['version','frame','frame_fields','index','owner','cost','content','isPublic','isAccessible','type','key']; this; diff --git a/load/edit.js b/load/edit.js index e9bb4f2..109e303 100644 --- a/load/edit.js +++ b/load/edit.js @@ -30,8 +30,8 @@ function edit(fo) { const frame = new Frame(1,1,console.screen_columns,console.screen_rows,BG_BLACK|LIGHTGRAY); frame.gotoxy(1,1); - header = '\1n'+fo.pageownerlogo+' '.repeat(fo.FRAME_PAGENUM-console.strlen(fo.pageownerlogo))+'\1n '+ - '\1W\1H'+fo.page+' '.repeat(fo.FRAME_PAGENUM-fo.page.length)+' '+ + header = '\1n'+fo.pageownerlogo+' '.repeat(fo.settings.FRAME_HEADER-console.strlen(fo.pageownerlogo))+'\1n '+ + '\1W\1H'+fo.page+' '.repeat(fo.settings.FRAME_PAGENUM-fo.page.length)+' '+ '\1G\1H'+' Edit'; frame.putmsg(header); frame.open(); @@ -74,40 +74,52 @@ function edit(fo) { frame.cycle(); this.handle=function(read) { - if (! js.terminated && ascii(read) != 27) { + if (! js.terminated) { + switch (ascii(read)) { + case 26: + if (inProperty) { + propFrame.close(); + frame.top(); + frame.cycle(); + inProperty = false; - if (inProperty) { - log(LOG_DEBUG, ' + FrameEdit properties(): read'); - propFrame.putmsg(read); - propFrame.cycle(); + } else { + properties(); + } - } else { - editor.getcmd(read); - editor.cycle(); - frame.cycle(); + return ''; + + case 27: + if (inProperty) { + log(LOG_DEBUG, ' + FrameEdit properties(): ESC'); + propFrame.close(); + frame.top(); + frame.cycle(); + inProperty = false; + } + + return ''; + + default: + if (inProperty) { + log(LOG_DEBUG, ' + FrameEdit properties(): read'); + propFrame.putmsg(read); + propFrame.cycle(); + + } else { + editor.getcmd(read); + editor.cycle(); + frame.cycle(); + } + + if (! complete) + return ''; } - - if (! complete) - return ''; - - // Ignore esc - } else if (ascii(read) == 27) { - if (inProperty) { - log(LOG_DEBUG, ' + FrameEdit properties(): ESC'); - propFrame.close(); - frame.top(); - frame.cycle(); - inProperty = false; - } - - return ''; } editor.close(); frame.close(); - - console.clear(LIGHTGRAY); - console.putmsg(fo.render()); + fo.render(); return ''; } diff --git a/load/frame-ansi.js b/load/frame-ansi.js index de7e20f..7129ff0 100644 --- a/load/frame-ansi.js +++ b/load/frame-ansi.js @@ -95,7 +95,7 @@ function FrameAnsi() { (console.screen_columns > 80 ? '\n\r' : ''); } - console.clear(); + console.clear(LIGHTGRAY); return console.putmsg(header+this.parse(base64_decode(this.content))); }; @@ -124,10 +124,10 @@ function FrameAnsi() { for (var y = 0; y < qr.size; y++) { // Top is white - if (((x==-1)? 0 : qr.getModule(x, y)) == 0) { + if (! ((x===-1)? 0 : qr.getModule(x, y))) { line += (qr.getModule(x+1, y)) ? top : full; - // Top is black + // Top is black } else { line += (qr.getModule(x+1, y)) ? blank : bot; } diff --git a/load/frame-page.js b/load/frame-page.js index 025e11f..902bfd2 100644 --- a/load/frame-page.js +++ b/load/frame-page.js @@ -97,7 +97,7 @@ function PageFrame() { */ Object.defineProperty(this,'page', { get: function() { - if (this.frame == null || this.index == null) return null; + if (this.frame === null || this.index === null) return null; return this.frame.toString()+this.index; } }); @@ -239,7 +239,7 @@ PageFrame.prototype.parse = function(text) { match = text.substr(p,cte).match(/[\r\n\x1b]/); //log(LOG_DEBUG,'SPECIAL CHAR ['+r+'x'+c+'] ['+p+'-'+cte+'] for: '+match); - if (match == null || match.index) { + if (match === null || match.index) { advance = match ? match.index : cte; //log(LOG_DEBUG,'INCLUDE: '+text.substr(p,advance)); diff --git a/load/frame-viewdata.js b/load/frame-viewdata.js index 44335b6..d946b3f 100644 --- a/load/frame-viewdata.js +++ b/load/frame-viewdata.js @@ -140,17 +140,17 @@ function FrameViewdata() { var char = 0; //TL - char |= ((x==-1) || (y==-1) || ! qr.getModule(x,y)) ? (1<<0) : (0<<0); + char |= ((x===-1) || (y===-1) || ! qr.getModule(x,y)) ? (1<<0) : (0<<0); //TR - char |= ((x==-1) || (y == qr.size-1) || ! qr.getModule(x,y+1)) ? (1<<1) : (0<<1); + char |= ((x===-1) || (y === qr.size-1) || ! qr.getModule(x,y+1)) ? (1<<1) : (0<<1); //ML - char |= ((y==-1) || ! qr.getModule(x+1,y)) ? (1<<2) : (0<<2); + char |= ((y===-1) || ! qr.getModule(x+1,y)) ? (1<<2) : (0<<2); //MR - char |= ((y == qr.size-1) || ! qr.getModule(x+1,y+1)) ? (1<<3) : (0<<3); + char |= ((y === qr.size-1) || ! qr.getModule(x+1,y+1)) ? (1<<3) : (0<<3); //BL - char |= ((x==qr.size-2) || (y==-1) || ! qr.getModule(x+2,y)) ? (1<<4) : (0<<4); + char |= ((x===qr.size-2) || (y===-1) || ! qr.getModule(x+2,y)) ? (1<<4) : (0<<4); //BR - char |= ((x==qr.size-2) || (y == qr.size-1) || ! qr.getModule(x+2,y+1)) ? (1<<5) : (0<<5); + char |= ((x===qr.size-2) || (y === qr.size-1) || ! qr.getModule(x+2,y+1)) ? (1<<5) : (0<<5); char += 0x20; if (char > 0x3f) @@ -163,7 +163,7 @@ function FrameViewdata() { if (y%2) line += ascii(0x35); - repeat_count = this.settings.FRAME_WIDTH-Math.ceil(qr.size/2)-offset-(offset ? 1 : 2)-(y%2 == 1 ? 0 : 1); + repeat_count = this.settings.FRAME_WIDTH-Math.ceil(qr.size/2)-offset-(offset ? 1 : 2)-(y%2 === 1 ? 0 : 1); qrcode += line+' '.repeat(repeat_count > 0 ? repeat_count : 0); @@ -186,7 +186,7 @@ function FrameViewdata() { } // Render the right column - if (y%2 == 0) { + if (y%2 === 0) { line += ascii(0x21); } diff --git a/load/funcs.js b/load/funcs.js index e3e0fd5..e3c0922 100644 --- a/load/funcs.js +++ b/load/funcs.js @@ -7,22 +7,22 @@ load('graphic.js'); if (!String.prototype.repeat) { String.prototype.repeat = function(count) { 'use strict'; - if (this == null) { + if (this === null) { throw new TypeError('can\'t convert ' + this + ' to object'); } var str = '' + this; count = +count; - if (count != count) { + if (count !== count) { count = 0; } if (count < 0) { - throw new RangeError('repeat count must be non-negative'); + throw new RangeError('repeat count must be non-negative: '+count); } - if (count == Infinity) { + if (count === Infinity) { throw new RangeError('repeat count must be less than infinity'); } count = Math.floor(count); - if (str.length == 0 || count == 0) { + if (str.length === 0 || count === 0) { return ''; } // Ensuring count is a 31-bit integer allows us to heavily optimize the @@ -33,11 +33,11 @@ if (!String.prototype.repeat) { } var rpt = ''; for (;;) { - if ((count & 1) == 1) { + if ((count & 1) === 1) { rpt += str; } count >>>= 1; - if (count == 0) { + if (count === 0) { break; } str += str; @@ -86,7 +86,7 @@ function findMsgBase(code) { for (var s in msg_area.sub) { var sub = msg_area.sub[s]; - if (sub.code.substr(-code.length).toLowerCase() == code) + if (sub.code.substr(-code.length).toLowerCase() === code) return sub.code; } @@ -98,6 +98,7 @@ function findMsgBase(code) { * * @param key * @param error + * @param abort */ function getArg(key,error,abort) { index = argv.indexOf(key); diff --git a/load/qrcode-make.js b/load/qrcode-make.js index 2c9d38a..8da5c43 100644 --- a/load/qrcode-make.js +++ b/load/qrcode-make.js @@ -1,4 +1,4 @@ -"use strict"; +'use strict'; /* * Module "qrcodegen", public members: * - Class QrCode: @@ -37,11 +37,11 @@ var qrcodegen = new function() { // Check scalar arguments if (version < MIN_VERSION || version > MAX_VERSION) - throw "Version value out of range"; + throw 'Version value out of range'; if (mask < -1 || mask > 7) - throw "Mask value out of range"; + throw 'Mask value out of range'; if (!(errCorLvl instanceof Ecc)) - throw "QrCode.Ecc expected"; + throw 'QrCode.Ecc expected'; var size = version * 4 + 17; // Initialize both grids to be size*size arrays of Boolean false @@ -61,7 +61,7 @@ var qrcodegen = new function() { drawCodewords(allCodewords); // Do masking - if (mask == -1) { // Automatically choose best mask + if (mask === -1) { // Automatically choose best mask var minPenalty = Infinity; for (var i = 0; i < 8; i++) { applyMask(i); @@ -75,7 +75,7 @@ var qrcodegen = new function() { } } if (mask < 0 || mask > 7) - throw "Assertion error"; + throw 'Assertion error'; applyMask(mask); // Apply the final choice of mask drawFormatBits(mask); // Overwrite old format bits @@ -86,19 +86,19 @@ var qrcodegen = new function() { // The version number of this QR Code, which is between 1 and 40 (inclusive). // This determines the size of this barcode. - Object.defineProperty(this, "version", {value:version}); + Object.defineProperty(this, 'version', {value:version}); // The width and height of this QR Code, measured in modules, between // 21 and 177 (inclusive). This is equal to version * 4 + 17. - Object.defineProperty(this, "size", {value:size}); + Object.defineProperty(this, 'size', {value:size}); // The error correction level used in this QR Code. - Object.defineProperty(this, "errorCorrectionLevel", {value:errCorLvl}); + Object.defineProperty(this, 'errorCorrectionLevel', {value:errCorLvl}); // The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive). // Even if a QR Code is created with automatic masking requested (mask = -1), // the resulting object still has a mask value between 0 and 7. - Object.defineProperty(this, "mask", {value:mask}); + Object.defineProperty(this, 'mask', {value:mask}); /*---- Accessor methods ----*/ @@ -119,14 +119,14 @@ var qrcodegen = new function() { // The scale must be a positive integer and the border must be a non-negative integer. this.drawCanvas = function(scale, border, canvas) { if (scale <= 0 || border < 0) - throw "Value out of range"; + throw 'Value out of range'; var width = (size + border * 2) * scale; canvas.width = width; canvas.height = width; - var ctx = canvas.getContext("2d"); + var ctx = canvas.getContext('2d'); for (var y = -border; y < size + border; y++) { for (var x = -border; x < size + border; x++) { - ctx.fillStyle = this.getModule(x, y) ? "#000000" : "#FFFFFF"; + ctx.fillStyle = this.getModule(x, y) ? '#000000' : '#FFFFFF'; ctx.fillRect((x + border) * scale, (y + border) * scale, scale, scale); } } @@ -136,12 +136,12 @@ var qrcodegen = new function() { // of border modules. The string always uses Unix newlines (\n), regardless of the platform. this.toSvgString = function(border) { if (border < 0) - throw "Border must be non-negative"; + throw 'Border must be non-negative'; var parts = []; for (var y = 0; y < size; y++) { for (var x = 0; x < size; x++) { if (this.getModule(x, y)) - parts.push("M" + (x + border) + "," + (y + border) + "h1v1h-1z"); + parts.push('M' + (x + border) + ',' + (y + border) + 'h1v1h-1z'); } } return '\n' + @@ -160,8 +160,8 @@ var qrcodegen = new function() { function drawFunctionPatterns() { // Draw horizontal and vertical timing patterns for (var i = 0; i < size; i++) { - setFunctionModule(6, i, i % 2 == 0); - setFunctionModule(i, 6, i % 2 == 0); + setFunctionModule(6, i, i % 2 === 0); + setFunctionModule(i, 6, i % 2 === 0); } // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules) @@ -175,7 +175,7 @@ var qrcodegen = new function() { for (var i = 0; i < numAlign; i++) { for (var j = 0; j < numAlign; j++) { // Don't draw on the three finder corners - if (!(i == 0 && j == 0 || i == 0 && j == numAlign - 1 || i == numAlign - 1 && j == 0)) + if (!(i === 0 && j === 0 || i === 0 && j === numAlign - 1 || i === numAlign - 1 && j === 0)) drawAlignmentPattern(alignPatPos[i], alignPatPos[j]); } } @@ -195,8 +195,8 @@ var qrcodegen = new function() { for (var i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); var bits = (data << 10 | rem) ^ 0x5412; // uint15 - if (bits >>> 15 != 0) - throw "Assertion error"; + if (bits >>> 15 !== 0) + throw 'Assertion error'; // Draw first copy for (var i = 0; i <= 5; i++) @@ -227,8 +227,8 @@ var qrcodegen = new function() { for (var i = 0; i < 12; i++) rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25); var bits = version << 12 | rem; // uint18 - if (bits >>> 18 != 0) - throw "Assertion error"; + if (bits >>> 18 !== 0) + throw 'Assertion error'; // Draw two copies for (var i = 0; i < 18; i++) { @@ -249,7 +249,7 @@ var qrcodegen = new function() { var dist = Math.max(Math.abs(dx), Math.abs(dy)); // Chebyshev/infinity norm var xx = x + dx, yy = y + dy; if (0 <= xx && xx < size && 0 <= yy && yy < size) - setFunctionModule(xx, yy, dist != 2 && dist != 4); + setFunctionModule(xx, yy, dist !== 2 && dist !== 4); } } } @@ -260,7 +260,7 @@ var qrcodegen = new function() { function drawAlignmentPattern(x, y) { for (var dy = -2; dy <= 2; dy++) { for (var dx = -2; dx <= 2; dx++) - setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) != 1); + setFunctionModule(x + dx, y + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1); } } @@ -278,8 +278,8 @@ var qrcodegen = new function() { // Returns a new byte string representing the given data with the appropriate error correction // codewords appended to it, based on this object's version and error correction level. function addEccAndInterleave(data) { - if (data.length != QrCode.getNumDataCodewords(version, errCorLvl)) - throw "Invalid argument"; + if (data.length !== QrCode.getNumDataCodewords(version, errCorLvl)) + throw 'Invalid argument'; // Calculate parameter numbers var numBlocks = QrCode.NUM_ERROR_CORRECTION_BLOCKS[errCorLvl.ordinal][version]; @@ -305,12 +305,12 @@ var qrcodegen = new function() { for (var i = 0; i < blocks[0].length; i++) { for (var j = 0; j < blocks.length; j++) { // Skip the padding byte in short blocks - if (i != shortBlockLen - blockEccLen || j >= numShortBlocks) + if (i !== shortBlockLen - blockEccLen || j >= numShortBlocks) result.push(blocks[j][i]); } } - if (result.length != rawCodewords) - throw "Assertion error"; + if (result.length !== rawCodewords) + throw 'Assertion error'; return result; } @@ -318,17 +318,17 @@ var qrcodegen = new function() { // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire // data area of this QR Code. Function modules need to be marked off before this is called. function drawCodewords(data) { - if (data.length != Math.floor(QrCode.getNumRawDataModules(version) / 8)) - throw "Invalid argument"; + if (data.length !== Math.floor(QrCode.getNumRawDataModules(version) / 8)) + throw 'Invalid argument'; var i = 0; // Bit index into the data // Do the funny zigzag scan for (var right = size - 1; right >= 1; right -= 2) { // Index of right column in each column pair - if (right == 6) + if (right === 6) right = 5; for (var vert = 0; vert < size; vert++) { // Vertical counter for (var j = 0; j < 2; j++) { var x = right - j; // Actual x coordinate - var upward = ((right + 1) & 2) == 0; + var upward = ((right + 1) & 2) === 0; var y = upward ? size - 1 - vert : vert; // Actual y coordinate if (!isFunction[y][x] && i < data.length * 8) { modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7)); @@ -339,8 +339,8 @@ var qrcodegen = new function() { } } } - if (i != data.length * 8) - throw "Assertion error"; + if (i !== data.length * 8) + throw 'Assertion error'; } @@ -351,20 +351,20 @@ var qrcodegen = new function() { // QR Code needs exactly one (not zero, two, etc.) mask applied. function applyMask(mask) { if (mask < 0 || mask > 7) - throw "Mask value out of range"; + throw 'Mask value out of range'; for (var y = 0; y < size; y++) { for (var x = 0; x < size; x++) { var invert; switch (mask) { - case 0: invert = (x + y) % 2 == 0; break; - case 1: invert = y % 2 == 0; break; - case 2: invert = x % 3 == 0; break; - case 3: invert = (x + y) % 3 == 0; break; - case 4: invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 == 0; break; - case 5: invert = x * y % 2 + x * y % 3 == 0; break; - case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break; - case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break; - default: throw "Assertion error"; + case 0: invert = (x + y) % 2 === 0; break; + case 1: invert = y % 2 === 0; break; + case 2: invert = x % 3 === 0; break; + case 3: invert = (x + y) % 3 === 0; break; + case 4: invert = (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0; break; + case 5: invert = x * y % 2 + x * y % 3 === 0; break; + case 6: invert = (x * y % 2 + x * y % 3) % 2 === 0; break; + case 7: invert = ((x + y) % 2 + x * y % 3) % 2 === 0; break; + default: throw 'Assertion error'; } if (!isFunction[y][x] && invert) modules[y][x] = !modules[y][x]; @@ -384,9 +384,9 @@ var qrcodegen = new function() { var color = false; var runX = 0; for (var x = 0; x < size; x++) { - if (modules[y][x] == color) { + if (modules[y][x] === color) { runX++; - if (runX == 5) + if (runX === 5) result += QrCode.PENALTY_N1; else if (runX > 5) result++; @@ -410,9 +410,9 @@ var qrcodegen = new function() { var color = false; var runY = 0; for (var y = 0; y < size; y++) { - if (modules[y][x] == color) { + if (modules[y][x] === color) { runY++; - if (runY == 5) + if (runY === 5) result += QrCode.PENALTY_N1; else if (runY > 5) result++; @@ -435,7 +435,7 @@ var qrcodegen = new function() { for (var y = 0; y < size - 1; y++) { for (var x = 0; x < size - 1; x++) { var color = modules[y][x]; - if (color == modules[y][x + 1] && color == modules[y + 1][x] && color == modules[y + 1][x + 1]) + if (color === modules[y][x + 1] && color === modules[y + 1][x] && color === modules[y + 1][x + 1]) result += QrCode.PENALTY_N2; } } @@ -448,7 +448,7 @@ var qrcodegen = new function() { black++; }); }); - var total = size * size; // Note that size is odd, so black/total != 1/2 + var total = size * size; // Note that size is odd, so black/total !== 1/2 // Compute the smallest integer k >= 0 such that (45-5k)% <= black/total <= (55+5k)% var k = Math.ceil(Math.abs(black * 20 - total * 10) / total) - 1; result += k * QrCode.PENALTY_N4; @@ -460,11 +460,11 @@ var qrcodegen = new function() { // Each position is in the range [0,177), and are used on both the x and y axes. // This could be implemented as lookup table of 40 variable-length lists of integers. function getAlignmentPatternPositions() { - if (version == 1) + if (version === 1) return []; else { var numAlign = Math.floor(version / 7) + 2; - var step = (version == 32) ? 26 : + var step = (version === 32) ? 26 : Math.ceil((size - 13) / (numAlign*2 - 2)) * 2; var result = [6]; for (var pos = size - 7; result.length < numAlign; pos -= step) @@ -476,7 +476,7 @@ var qrcodegen = new function() { // Returns true iff the i'th bit of x is set to 1. function getBit(x, i) { - return ((x >>> i) & 1) != 0; + return ((x >>> i) & 1) !== 0; } }; @@ -522,12 +522,12 @@ var qrcodegen = new function() { * This is a mid-level API; the high-level API is encodeText() and encodeBinary(). */ this.QrCode.encodeSegments = function(segs, ecl, minVersion, maxVersion, mask, boostEcl) { - if (minVersion == undefined) minVersion = MIN_VERSION; - if (maxVersion == undefined) maxVersion = MAX_VERSION; - if (mask == undefined) mask = -1; - if (boostEcl == undefined) boostEcl = true; + if (minVersion === undefined) minVersion = MIN_VERSION; + if (maxVersion === undefined) maxVersion = MAX_VERSION; + if (mask === undefined) mask = -1; + if (boostEcl === undefined) boostEcl = true; if (!(MIN_VERSION <= minVersion && minVersion <= maxVersion && maxVersion <= MAX_VERSION) || mask < -1 || mask > 7) - throw "Invalid value"; + throw 'Invalid value'; // Find the minimal version number to use var version, dataUsedBits; @@ -537,7 +537,7 @@ var qrcodegen = new function() { if (dataUsedBits <= dataCapacityBits) break; // This version number is found to be suitable if (version >= maxVersion) // All versions in the range could not fit the given data - throw "Data too long"; + throw 'Data too long'; } // Increase the error correction level while the data still fits in the current version number @@ -555,17 +555,17 @@ var qrcodegen = new function() { bb.push(bit); }); }); - if (bb.length != dataUsedBits) - throw "Assertion error"; + if (bb.length !== dataUsedBits) + throw 'Assertion error'; // Add terminator and pad up to a byte if applicable var dataCapacityBits = QrCode.getNumDataCodewords(version, ecl) * 8; if (bb.length > dataCapacityBits) - throw "Assertion error"; + throw 'Assertion error'; bb.appendBits(0, Math.min(4, dataCapacityBits - bb.length)); bb.appendBits(0, (8 - bb.length % 8) % 8); - if (bb.length % 8 != 0) - throw "Assertion error"; + if (bb.length % 8 !== 0) + throw 'Assertion error'; // Pad with alternating bytes until data capacity is reached for (var padByte = 0xEC; bb.length < dataCapacityBits; padByte ^= 0xEC ^ 0x11) @@ -594,7 +594,7 @@ var qrcodegen = new function() { // The result is in the range [208, 29648]. This could be implemented as a 40-entry lookup table. QrCode.getNumRawDataModules = function(ver) { if (ver < MIN_VERSION || ver > MAX_VERSION) - throw "Version number out of range"; + throw 'Version number out of range'; var result = (16 * ver + 128) * ver + 64; if (ver >= 2) { var numAlign = Math.floor(ver / 7) + 2; @@ -629,8 +629,8 @@ var qrcodegen = new function() { // Must only be called immediately after a run of white modules has ended. QrCode.hasFinderLikePattern = function(runHistory) { var n = runHistory[1]; - return n > 0 && runHistory[2] == n && runHistory[4] == n && runHistory[5] == n - && runHistory[3] == n * 3 && Math.max(runHistory[0], runHistory[6]) >= n * 4; + return n > 0 && runHistory[2] === n && runHistory[4] === n && runHistory[5] === n + && runHistory[3] === n * 3 && Math.max(runHistory[0], runHistory[6]) >= n * 4; }; @@ -638,8 +638,8 @@ var qrcodegen = new function() { var MIN_VERSION = 1; // The minimum version number supported in the QR Code Model 2 standard var MAX_VERSION = 40; // The maximum version number supported in the QR Code Model 2 standard - Object.defineProperty(this.QrCode, "MIN_VERSION", {value:MIN_VERSION}); - Object.defineProperty(this.QrCode, "MAX_VERSION", {value:MAX_VERSION}); + Object.defineProperty(this.QrCode, 'MIN_VERSION', {value:MIN_VERSION}); + Object.defineProperty(this.QrCode, 'MAX_VERSION', {value:MAX_VERSION}); // For use in getPenaltyScore(), when evaluating which mask is best. QrCode.PENALTY_N1 = 3; @@ -682,10 +682,10 @@ var qrcodegen = new function() { // Private constructor. function Ecc(ord, fb) { // (Public) In the range 0 to 3 (unsigned 2-bit integer) - Object.defineProperty(this, "ordinal", {value:ord}); + Object.defineProperty(this, 'ordinal', {value:ord}); // (Package-private) In the range 0 to 3 (unsigned 2-bit integer) - Object.defineProperty(this, "formatBits", {value:fb}); + Object.defineProperty(this, 'formatBits', {value:fb}); } @@ -709,18 +709,18 @@ var qrcodegen = new function() { this.QrSegment = function(mode, numChars, bitData) { /*---- Constructor (low level) ----*/ if (numChars < 0 || !(mode instanceof Mode)) - throw "Invalid argument"; + throw 'Invalid argument'; // The data bits of this segment. Accessed through getData(). bitData = bitData.slice(); // Make defensive copy // The mode indicator of this segment. - Object.defineProperty(this, "mode", {value:mode}); + Object.defineProperty(this, 'mode', {value:mode}); // The length of this segment's unencoded data. Measured in characters for // numeric/alphanumeric/kanji mode, bytes for byte mode, and 0 for ECI mode. // Always zero or positive. Not the same as the data's bit length. - Object.defineProperty(this, "numChars", {value:numChars}); + Object.defineProperty(this, 'numChars', {value:numChars}); // Returns a new copy of the data bits of this segment. this.getData = function() { @@ -750,7 +750,7 @@ var qrcodegen = new function() { */ this.QrSegment.makeNumeric = function(digits) { if (!this.NUMERIC_REGEX.test(digits)) - throw "String contains non-numeric characters"; + throw 'String contains non-numeric characters'; var bb = new BitBuffer(); for (var i = 0; i < digits.length; ) { // Consume up to 3 digits per iteration var n = Math.min(digits.length - i, 3); @@ -768,7 +768,7 @@ var qrcodegen = new function() { */ this.QrSegment.makeAlphanumeric = function(text) { if (!this.ALPHANUMERIC_REGEX.test(text)) - throw "String contains unencodable characters in alphanumeric mode"; + throw 'String contains unencodable characters in alphanumeric mode'; var bb = new BitBuffer(); var i; for (i = 0; i + 2 <= text.length; i += 2) { // Process groups of 2 @@ -788,7 +788,7 @@ var qrcodegen = new function() { */ this.QrSegment.makeSegments = function(text) { // Select the most efficient segment encoding automatically - if (text == "") + if (text === '') return []; else if (this.NUMERIC_REGEX.test(text)) return [this.makeNumeric(text)]; @@ -806,7 +806,7 @@ var qrcodegen = new function() { this.QrSegment.makeEci = function(assignVal) { var bb = new BitBuffer(); if (assignVal < 0) - throw "ECI assignment value out of range"; + throw 'ECI assignment value out of range'; else if (assignVal < (1 << 7)) bb.appendBits(assignVal, 8); else if (assignVal < (1 << 14)) { @@ -816,7 +816,7 @@ var qrcodegen = new function() { bb.appendBits(6, 3); bb.appendBits(assignVal, 21); } else - throw "ECI assignment value out of range"; + throw 'ECI assignment value out of range'; return new this(this.Mode.ECI, 0, bb); }; @@ -853,7 +853,7 @@ var qrcodegen = new function() { // (Private) The set of all legal characters in alphanumeric mode, // where each character value maps to the index in the string. - QrSegment.ALPHANUMERIC_CHARSET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"; + QrSegment.ALPHANUMERIC_CHARSET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:'; /*---- Public helper enumeration ----*/ @@ -873,7 +873,7 @@ var qrcodegen = new function() { // Private constructor. function Mode(mode, ccbits) { // (Package-private) The mode indicator bits, which is a uint4 value (range 0 to 15). - Object.defineProperty(this, "modeBits", {value:mode}); + Object.defineProperty(this, 'modeBits', {value:mode}); // (Package-private) Returns the bit width of the character count field for a segment in // this mode in a QR Code at the given version number. The result is in the range [0, 16]. @@ -891,7 +891,7 @@ var qrcodegen = new function() { str = encodeURI(str); var result = []; for (var i = 0; i < str.length; i++) { - if (str.charAt(i) != "%") + if (str.charAt(i) !== '%') result.push(str.charCodeAt(i)); else { result.push(parseInt(str.substring(i + 1, i + 3), 16)); @@ -912,7 +912,7 @@ var qrcodegen = new function() { */ function ReedSolomonGenerator(degree) { if (degree < 1 || degree > 255) - throw "Degree out of range"; + throw 'Degree out of range'; // Coefficients of the divisor polynomial, stored from highest to lowest power, excluding the leading term which // is always 1. For example the polynomial x^3 + 255x^2 + 8x + 93 is stored as the uint8 array {255, 8, 93}. @@ -957,16 +957,16 @@ var qrcodegen = new function() { // This static function returns the product of the two given field elements modulo GF(2^8/0x11D). The arguments and // result are unsigned 8-bit integers. This could be implemented as a lookup table of 256*256 entries of uint8. ReedSolomonGenerator.multiply = function(x, y) { - if (x >>> 8 != 0 || y >>> 8 != 0) - throw "Byte out of range"; + if (x >>> 8 !== 0 || y >>> 8 !== 0) + throw 'Byte out of range'; // Russian peasant multiplication var z = 0; for (var i = 7; i >= 0; i--) { z = (z << 1) ^ ((z >>> 7) * 0x11D); z ^= ((y >>> i) & 1) * x; } - if (z >>> 8 != 0) - throw "Assertion error"; + if (z >>> 8 !== 0) + throw 'Assertion error'; return z; }; @@ -982,8 +982,8 @@ var qrcodegen = new function() { // Appends the given number of low-order bits of the given value // to this buffer. Requires 0 <= len <= 31 and 0 <= val < 2^len. this.appendBits = function(val, len) { - if (len < 0 || len > 31 || val >>> len != 0) - throw "Value out of range"; + if (len < 0 || len > 31 || val >>> len !== 0) + throw 'Value out of range'; for (var i = len - 1; i >= 0; i--) // Append bit by bit this.push((val >>> i) & 1); }; diff --git a/load/register.js b/load/register.js index 3f2fc07..92a7a89 100644 --- a/load/register.js +++ b/load/register.js @@ -38,14 +38,14 @@ function register() { // Dont allow existing users to re-register if (user.number) { fo.sendBaseline('ALREADY_MEMBER',false); - return read == '*' ? read : ''; + return read === '*' ? read : ''; } log(LOG_DEBUG,'Control REGISTER handle() start. ('+read+')'); log(LOG_DEBUG,'- Field '+cf.fname+'('+JSON.stringify(cf)+')'); - if ((cf.fname == 'TOKEN') && (read == '#' || read == '\r')) { - if (cf.fvalue == code) { + if ((cf.fname === 'TOKEN') && (read === '#' || read === "\r")) { + if (cf.fvalue === code) { complete = true; } else { @@ -65,7 +65,7 @@ function register() { this.prefield=function() { log(LOG_DEBUG,'- prefield: Field '+cf.fname+'('+JSON.stringify(cf)+')'); - if (cf.fname == 'TOKEN') { + if (cf.fname === 'TOKEN') { if (! code.length) { log(LOG_DEBUG,' - BASELINE '+cf.fname+'('+JSON.stringify(cf)+')'); fo.sendBaseline('TOKEN_EMAIL',false); @@ -97,7 +97,7 @@ function register() { var hdrs = new Object(); hdrs.to=name; hdrs.to_net_type=netaddr_type(email); - if (hdrs.to_net_type != NET_NONE) { + if (hdrs.to_net_type !== NET_NONE) { hdrs.to_net_addr = email; } else { fo.sendBaseline('CANNOT_SEND_TOKEN',false); @@ -108,7 +108,7 @@ function register() { hdrs.from_net_type=NET_INTERNET; hdrs.subject='Registration TOKEN for '+system.name; - if (msgbase.open != undefined && msgbase.open() == false) { + if (msgbase.open !== undefined && msgbase.open() === false) { console.print("\r\n\1n\1h\1rERROR: \1y" + msgbase.last_error + "\1n \r\n"); console.pause(); msgbase.close(); @@ -187,4 +187,4 @@ function register() { } } -this; \ No newline at end of file +this; diff --git a/load/sqrllogin.js b/load/sqrllogin.js index e330398..78bb4be 100644 --- a/load/sqrllogin.js +++ b/load/sqrllogin.js @@ -19,6 +19,7 @@ load('frame.js'); log(LOG_DEBUG,'+ Control SQRL-LOGIN loaded'); +// @todo This should move to handle - since we have to press 2 twice to get out. function sqrllogin() { var complete = false; var cancel = false; @@ -39,7 +40,7 @@ function sqrllogin() { .map(function(x) {return x.charCodeAt(0)}); var qr = qrcodegen.QrCode.encodeBinary(data,qrcodegen.QrCode.Ecc.LOW); - var subframe = new Frame((viewdata ? VIEWDATA_FRAME_WIDTH : ANSI_FRAME_WIDTH-qr.size-2),2,(viewdata ? qr.size/2 : qr.size+2),22,BG_BLACK|LIGHTGRAY); + var subframe = new Frame((viewdata ? fo.settings.FRAME_WIDTH : fo.settings.FRAME_WIDTH-qr.size-2),2,(viewdata ? qr.size/2 : qr.size+2),22,BG_BLACK|LIGHTGRAY); fo.qrcode(qr,subframe); fo.sendBaseline('CANCEL_MSG',false); @@ -51,7 +52,7 @@ function sqrllogin() { while (read !== '2') { read = console.inkey(K_NONE,1000); - if (read == 2) + if (read === 2) cancel = true; http = new HTTPRequest(); @@ -73,7 +74,7 @@ function sqrllogin() { if (result.isReady) { log(LOG_INFO,'NUT: '+result.msg); log(LOG_INFO,'NEXT: '+result.nextPage); - if (result.msg == 'SQRL authenticated') { + if (result.msg === 'SQRL authenticated') { log(LOG_DEBUG,'Getting Authenticated User ['+result.nextPage+']'); http = new HTTPRequest(); http.SetupGet(result.nextPage,undefined,''); @@ -83,7 +84,7 @@ function sqrllogin() { http.ReadResponse(); log(LOG_DEBUG,'Getting Authenticated User Response ['+http.response_code+']'); - if (http.response_code == 200) { + if (http.response_code === 200) { var sqrluser = http.body.substr(0,40); var username = 'S'+sqrluser.substr(0,24) log(LOG_DEBUG,'Getting Authenticated sqrluser ['+JSON.stringify(sqrluser)+']'); @@ -173,7 +174,7 @@ function sqrllogin() { if (typeof subframe === 'object') subframe.close(); action = ACTION_GOTO; - next_page = { frame: 98,index: 'a' }; + next_page = LOGIN_FRAME; } // Called before processing for a field diff --git a/main.js b/main.js index 280900a..d9b281b 100644 --- a/main.js +++ b/main.js @@ -147,14 +147,14 @@ while(bbs.online) { read = KEY_ESC; // Recognise when the ESC sequence has ended (with a ~ or ;) - } else if (esc && extendedkey && (read === '~' || read === ';')) { + } else if (esc && extendedkey && (read === '~' || read === ';' || ! read)) { switch (extendedkey) { case '[15': read = false; break; // F5 case '[17': read = false; break; // F6 case '[18': read = false; break; // F7 case '[19': read = false; break; // F8 case '[20': read = false; break; // F9 - case '[21': read = false; break; // F10 + case '[21': read = ascii(26); break; // F10 case '[23': read = false; break; // F11 case '[24': read = false; break; // F12 default: @@ -592,7 +592,7 @@ while(bbs.online) { if (read.charCodeAt(0) > 31 && cf.fvalue.length < cf.flength) { cf.fvalue += read; - console.write((cf.ftype == 't') ? read : 'x'); + console.write((cf.ftype === 't') ? read : 'x'); } } @@ -726,7 +726,7 @@ while(bbs.online) { } /* - if ($read == HASH) { + if ($read === HASH) { if ($x = $this->fo->route(2) AND $x !== '*' AND is_numeric($x)) { $next_page = ['frame'=>$x]; @@ -838,7 +838,7 @@ while(bbs.online) { fo.load(pageStr(next_page)); // If the frame doesnt exist, check that the parent frame exists in case we are creating a new one - if (fo.page == null) { + if (fo.page === null) { log(LOG_DEBUG,'- ACTION_EDIT: check index: '+next_page.index+' ('+String.fromCharCode(next_page.index.charCodeAt(0)-1)+')'); // We can always create an 'a' frame @@ -847,7 +847,7 @@ while(bbs.online) { fo.load(pageStr({frame: next_page.frame, index: String.fromCharCode(next_page.index.charCodeAt(0)-1)})); log(LOG_DEBUG,'- ACTION_EDIT: check index: '+JSON.stringify(fo)+' ('+String.fromCharCode(next_page.index.charCodeAt(0)-1)+')'); - if (fo.page == null) { + if (fo.page === null) { fo = current; // sendbaseline ERR_PAGE fo.sendBaseline('ERR_NO_PARENT',false); @@ -885,7 +885,7 @@ while(bbs.online) { log(LOG_DEBUG,'- ACTION_BACKUP: Backing up to ['+(next_page ? pageStr(next_page) : '')+'] current ['+fo.page+']'); // If there is no next page, we'll ignore the request. - if (! next_page || (pageStr(next_page) == fo.page)) { + if (! next_page || (pageStr(next_page) === fo.page)) { action = false; break; } @@ -908,11 +908,11 @@ while(bbs.online) { fo = viewdata ? new FrameViewdata() : new FrameAnsi(); fo.load(pageStr(next_page)); - if (fo.page == null) { + if (fo.page === null) { fo = current; // In case the frame doesnt exist - if (fo == null) + if (fo === null) fo = viewdata ? new FrameViewdata() : new FrameAnsi(); // sendbaseline ERR_PAGE diff --git a/save.js b/save.js index f11cd8d..dc85864 100644 --- a/save.js +++ b/save.js @@ -22,7 +22,7 @@ frame = new TexFrame(); frame.load(pageStr({frame: p,index: i})); if (! send || ! frame || file) { - if (frame.page == null) { + if (frame.page === null) { frame = new TexFrame(); frame.frame = p; frame.index = i; @@ -55,7 +55,7 @@ if (! send || ! frame || file) { if (key) { frame.key = key.split(',').map(function(t){return parseInt(t)}); - if (frame.key.length != 10) { + if (frame.key.length !== 10) { log(LOG_ERROR,'! ERROR: Must specify 10 keys with -k'); exit(1); }