From 7abea66ae3e0d22896736a1464a31681a441f665 Mon Sep 17 00:00:00 2001 From: Shane Eskritt Date: Wed, 29 Nov 2023 21:40:51 +1100 Subject: [PATCH] Update ParseShip logic to try exact match first Try to match exact name in shipMatrix first to prevent false positives (ex. "Sabre Raven" matching as "Sabre") --- src/web_resources/HangarXPLOR.ParseShip.js | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/web_resources/HangarXPLOR.ParseShip.js b/src/web_resources/HangarXPLOR.ParseShip.js index 8aecbd5..2a90479 100644 --- a/src/web_resources/HangarXPLOR.ParseShip.js +++ b/src/web_resources/HangarXPLOR.ParseShip.js @@ -28,18 +28,28 @@ HangarXPLOR.ParseShip = function() .replace(/ promo wb/i, ''); var found = false; - var i, j; - for (i = 0, j = HangarXPLOR._shipMatrix.length; i < j; i++) { - if (this.ship_name.toLowerCase().indexOf(HangarXPLOR._shipMatrix[i].name.toLowerCase()) > -1) { + var shipIndex = HangarXPLOR._shipMatrix.findIndex(ship => this.ship_name.toLowerCase() === ship.name.toLowerCase()); - HangarXPLOR.Log('Matched', HangarXPLOR._shipMatrix[i].name, 'in', this.ship_name); - - this.ship_name = (HangarXPLOR._shipMatrix[i].displayName || HangarXPLOR._shipMatrix[i].name); - found = true; - if (HangarXPLOR._shipMatrix[i].thumbnail != undefined) { - $('.basic-infos .image', this).css({ 'background-image': 'url("' + HangarXPLOR._shipMatrix[i].thumbnail + '")'}); + if (shipIndex === -1) { + var i, j; + for (i = 0, j = HangarXPLOR._shipMatrix.length; i < j; i++) { + if (this.ship_name.toLowerCase().indexOf(HangarXPLOR._shipMatrix[i].name.toLowerCase()) > -1) { + shipIndex = i; + found = true; + break; } - break; + } + }else{ + found = true; + } + + if (found) { + this.ship_name = (HangarXPLOR._shipMatrix[shipIndex].displayName || HangarXPLOR._shipMatrix[shipIndex].name); + + HangarXPLOR.Log('Matched', HangarXPLOR._shipMatrix[shipIndex].name, 'in', this.ship_name); + + if (HangarXPLOR._shipMatrix[shipIndex].thumbnail !== undefined) { + $('.basic-infos .image', this).css({ 'background-image': 'url("' + HangarXPLOR._shipMatrix[shipIndex].thumbnail + '")'}); } }