From 3f4fed06f3506b3939296565825274cf65b559a1 Mon Sep 17 00:00:00 2001 From: e7d Date: Tue, 18 Aug 2020 09:33:03 +0200 Subject: [PATCH] optimized gamepad scanning --- js/gamepad.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/js/gamepad.js b/js/gamepad.js index 17a8dea..ab59dd3 100644 --- a/js/gamepad.js +++ b/js/gamepad.js @@ -268,9 +268,11 @@ class Gamepad { */ refresh() { // get fresh information from DOM about gamepads - this.gamepads = this.getNavigatorGamepads(); - - this.buildHelpGamepadList(); + const gamepads = this.getNavigatorGamepads(); + if (gamepads !== this.gamepads) { + this.gamepads = gamepads; + this.buildHelpGamepadList(); + } } /** @@ -453,7 +455,7 @@ class Gamepad { * @param {*} gamepad */ loadTemplate(gamepad) { - $.ajax(`templates/${this.type}/template.html`, {async: true}).done((template) => { + $.ajax(`templates/${this.type}/template.html`).done((template) => { // inject the template HTML this.$gamepad.html(template); window.setTimeout(() => { @@ -593,9 +595,11 @@ class Gamepad { } } else { this.backgroundColorIndex = color; - this.backgroundColorName + this.backgroundColorName; } - this.backgroundColorName = this.backgroundColors[this.backgroundColorIndex]; + this.backgroundColorName = this.backgroundColors[ + this.backgroundColorIndex + ]; this.$body.css({ background: this.backgroundColorName,