From 495c66dbabeb483533ca01e5ee119ea30f2737c8 Mon Sep 17 00:00:00 2001 From: bingingem Date: Sat, 18 Jan 2025 22:28:37 -0600 Subject: [PATCH 1/6] Use default format from localStorage if valid --- play.pokemonshowdown.com/js/client-mainmenu.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index 3106021cd6..b3cb57c85a 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -1026,6 +1026,11 @@ return ''; } if (!noChoice) { + var defaultFormat = Storage.prefs('defaultformat'); + if(BattleFormats[defaultFormat]) { + this.curFormat = defaultFormat; + } + else { this.curFormat = formatid; if (!this.curFormat) { if (BattleFormats['gen9randombattle']) { @@ -1036,6 +1041,7 @@ break; } } + } formatid = this.curFormat; } return ''; From 64d5fe2796b4eb082cac3d0aee55bb85a07dd07f Mon Sep 17 00:00:00 2001 From: bingingem Date: Sat, 18 Jan 2025 22:28:47 -0600 Subject: [PATCH 2/6] Store most recent format as defaultformat --- .../js/client-mainmenu.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index b3cb57c85a..3968274bfd 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -1031,17 +1031,17 @@ this.curFormat = defaultFormat; } else { - this.curFormat = formatid; - if (!this.curFormat) { - if (BattleFormats['gen9randombattle']) { - this.curFormat = 'gen9randombattle'; - } else for (var i in BattleFormats) { - if (!BattleFormats[i].searchShow || !BattleFormats[i].challengeShow) continue; - this.curFormat = i; - break; + this.curFormat = formatid; + if (!this.curFormat) { + if (BattleFormats['gen9randombattle']) { + this.curFormat = 'gen9randombattle'; + } else for (var i in BattleFormats) { + if (!BattleFormats[i].searchShow || !BattleFormats[i].challengeShow) continue; + this.curFormat = i; + break; + } } } - } formatid = this.curFormat; } return ''; @@ -1438,6 +1438,7 @@ }); } this.sourceEl.val(format).html(BattleLog.escapeFormat(format) || '(Select a format)'); + Storage.prefs('defaultformat', format); this.close(); } From b0f197406f2343dceffddef10cb614570b962bba Mon Sep 17 00:00:00 2001 From: bingingem Date: Sat, 18 Jan 2025 22:45:01 -0600 Subject: [PATCH 3/6] Fix linting issues --- play.pokemonshowdown.com/js/client-mainmenu.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index 3968274bfd..bf0245e793 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -1027,10 +1027,9 @@ } if (!noChoice) { var defaultFormat = Storage.prefs('defaultformat'); - if(BattleFormats[defaultFormat]) { + if (BattleFormats[defaultFormat]) { this.curFormat = defaultFormat; - } - else { + } else { this.curFormat = formatid; if (!this.curFormat) { if (BattleFormats['gen9randombattle']) { From 426951ed94e3eb4ed6ae6370dc574ee11e8f01f1 Mon Sep 17 00:00:00 2001 From: bingingem Date: Sun, 19 Jan 2025 01:21:22 -0600 Subject: [PATCH 4/6] Fix wrong team being selected on page reload --- play.pokemonshowdown.com/js/client-mainmenu.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index bf0245e793..42ca33f390 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -701,6 +701,10 @@ if (!this.searching || $.isArray(this.searching) && !this.searching.length) { var format = $formatButton.val(); var teamIndex = $teamButton.val(); + if (teamIndex === '') { + this.curTeamIndex = -1; + teamIndex = undefined; + } $formatButton.replaceWith(this.renderFormats(format)); $teamButton.replaceWith(this.renderTeams(format, teamIndex)); From 8cbc94d3158c4fa92ff3f103a0760ec9a7af67da Mon Sep 17 00:00:00 2001 From: bingingem Date: Sun, 19 Jan 2025 11:56:08 -0600 Subject: [PATCH 5/6] Identify correct team when defaulting format on reload --- play.pokemonshowdown.com/js/client-mainmenu.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index 42ca33f390..960e516b04 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -701,10 +701,7 @@ if (!this.searching || $.isArray(this.searching) && !this.searching.length) { var format = $formatButton.val(); var teamIndex = $teamButton.val(); - if (teamIndex === '') { - this.curTeamIndex = -1; - teamIndex = undefined; - } + $formatButton.replaceWith(this.renderFormats(format)); $teamButton.replaceWith(this.renderTeams(format, teamIndex)); @@ -1075,7 +1072,12 @@ if (!teams.length) { return ''; } - if (teamIndex === undefined) teamIndex = -1; + if (teamIndex === undefined || teamIndex === '' || teamIndex === -1) { + // if format is selected from default on reload, teamIndex gets set to -1 or '' + // handle both cases so we find the first team in that format + teamIndex = -1; + this.curTeamIndex = -1; + } if (teamIndex < 0) { if (this.curTeamIndex >= 0) { teamIndex = this.curTeamIndex; From 83ad1c4ca3c5cb8ae0d3d548155551aed5ac1b40 Mon Sep 17 00:00:00 2001 From: bingingem Date: Sun, 19 Jan 2025 11:57:45 -0600 Subject: [PATCH 6/6] Fix line spacing issue --- play.pokemonshowdown.com/js/client-mainmenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/play.pokemonshowdown.com/js/client-mainmenu.js b/play.pokemonshowdown.com/js/client-mainmenu.js index 960e516b04..5b1b1ba8a7 100644 --- a/play.pokemonshowdown.com/js/client-mainmenu.js +++ b/play.pokemonshowdown.com/js/client-mainmenu.js @@ -701,7 +701,7 @@ if (!this.searching || $.isArray(this.searching) && !this.searching.length) { var format = $formatButton.val(); var teamIndex = $teamButton.val(); - + $formatButton.replaceWith(this.renderFormats(format)); $teamButton.replaceWith(this.renderTeams(format, teamIndex));