From 99b4dcef9c0c19453f73904c560dfb580ce4be38 Mon Sep 17 00:00:00 2001 From: Nick Marcopoli Date: Sat, 30 May 2020 17:56:14 -0400 Subject: [PATCH] bug fixes - fix error when deleting remote card with empty availableTeams - fix search bar not working with empty restoreList --- extension/manifest.json | 2 +- extension/popup.js | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extension/manifest.json b/extension/manifest.json index b9117d5..b9a76da 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,6 +1,6 @@ { "name": "Showdown Team Backup", - "version": "0.1.5", + "version": "0.1.6", "description": "Backup teams from Pokemon Showdown across browsers!", "permissions": ["activeTab", "declarativeContent", "storage", "identity", "identity.email"], "background": { diff --git a/extension/popup.js b/extension/popup.js index 22d5949..9e23bc4 100644 --- a/extension/popup.js +++ b/extension/popup.js @@ -162,7 +162,13 @@ function deleteRemoteCard(teamKey, card) { // Go through each combination and see if there's a match for (let availableTeam of availableTeams.children) { - let availableTeamKey = hashTeam(availableTeam.querySelector("#teamJSON").innerText).toString(); + let availableTeamKey = null; + try { + availableTeamKey = hashTeam(availableTeam.querySelector("#teamJSON").innerText).toString(); + } catch { + // we only have the "no teams available" card pushed + break; + } if (availableTeamKey === teamKey) { // Enable button and change its color enableButton(availableTeam.querySelector("#actionButton"), "btn-secondary", "btn-primary", "Backup", backupOnClick); @@ -517,7 +523,7 @@ function disableDuplicates(init = false) { restoreTeams.parentNode.replaceChild(moveDisabledToBottom(restoreTeams, query), restoreTeams) startButtonListeners(); - search(); + showTeams(document.getElementById("searchLocalTeams").value); } // Runs when extension is loaded @@ -526,10 +532,11 @@ function loadTeamsInShowdown() { chrome.tabs.executeScript(null, { file: "getAvailableTeams.js" }, function (ret) { - document.getElementById("searchLocalTeams").value = localStorage.getItem("localSearchTerm"); displayTeams(ret[0], "localTeams"); restoreList("init"); startButtonListeners(); + document.getElementById("searchLocalTeams").value = localStorage.getItem("localSearchTerm"); + search(); }); } @@ -572,5 +579,5 @@ document.getElementById("clearSearchButton").addEventListener("click", function console.log("clearing"); let searchbox = document.getElementById("searchLocalTeams"); searchbox.value = ""; - search(searchbox.value); + showTeams(searchbox.value); }, false); \ No newline at end of file