Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"short_name": "Showdown!",
"name": "Pokémon Showdown!",
"icons": [
{
"src": "play.pokemonshowdown.com/favicon-16.png",
"type": "image/png",
"sizes": "16x16"
},
{
"src": "play.pokemonshowdown.com/favicon-32.png",
"type": "image/png",
"sizes": "32x32"
},
{
"src": "play.pokemonshowdown.com/favicon-256.png",
"type": "image/png",
"sizes": "256x256"
}
],
"start_url": "/?utm_source=homescreen",
"display": "standalone"
}
101 changes: 100 additions & 1 deletion play.pokemonshowdown.com/js/client-teambuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
'click .teambuilder-clipboard-data .result': 'clipboardResultSelect',
'click .teambuilder-clipboard-data': 'clipboardExpand',
'blur .teambuilder-clipboard-data': 'clipboardShrink'
,'change select[name=teamDuplicateFormat]': 'teamDuplicateFormatChange'

Check failure on line 93 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

A space is required after ','

Check failure on line 93 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

',' should be placed last
},
dispatchClick: function (e) {
e.preventDefault();
Expand Down Expand Up @@ -170,6 +171,66 @@
privacyChange: function (ev) {
Storage.prefs('uploadprivacy', ev.currentTarget.checked);
},
teamDuplicateFormatChange: function (ev) {
var value = typeof ev === 'object' ? ev.currentTarget.value : ev;
// Save using old client Storage.prefs
Storage.prefs('teamDuplicateNameFormat', value);
// Also try new client if available
if (typeof PS !== 'undefined' && PS.prefs) {

Check failure on line 179 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'PS' is not defined
PS.prefs.set('teamDuplicateNameFormat', value);

Check failure on line 180 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'PS' is not defined
}
// also update the team name textbox to preview the chosen format
try {
var baseName = (this.curTeam && this.curTeam.name) ? this.curTeam.name : null;
if (!baseName) return;
// compute preview name similar to createTeam logic
var previewName = '';
// derive a raw base name by stripping an existing leading "Copy of "
// and trailing numeric parenthesis like " (v. 3)" or " (3)"
var raw = baseName.replace(/^\s*Copy of\s+/i, '').replace(/\s*\((?:v\.\s*)?\d+\)$/, '');
if (value === 'copy') {
previewName = 'Copy of ' + raw;
} else {
var base = raw;
// escape for regex
var esc = base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
var max = 0;
for (var i = 0; i < teams.length; i++) {
// Skip the current team to avoid incrementing when just switching formats
if (this.curTeam && teams[i] === this.curTeam) continue;
var tname = teams[i].name || '';
var re = new RegExp('^' + esc + '\\s*\\((?:v\\.\\s*)?(\\d+)\\)$');
var m = tname.match(re);
if (m) {
var num = parseInt(m[1], 10);
if (!isNaN(num) && num > max) max = num;
}
}
var next = max + 1;
if (value === 'paren-v-number') {
previewName = base + ' (v. ' + next + ')';
} else {
previewName = base + ' (' + next + ')';
}
}
// set the textbox value (don't trigger change handlers)
var $input = this.$('.teamnameedit');
if ($input && $input.length) {
$input.val(previewName);
// persist the previewed name to the team model so it is kept when
// switching back to the list view. This ensures the All teams list
// shows the chosen duplicate-name format immediately.
try {
if (this.curTeam) {
this.curTeam.name = previewName;
this.save();
}
} catch (e) {}
}
} catch (err) {
// fail silently
}
},

loadTeam: function () {
if (this.loadingTeam) return false;
Expand Down Expand Up @@ -849,8 +910,37 @@
createTeam: function (orig, isBox) {
var newTeam;
if (orig) {
// naming preference: allow users to choose how duplicated teams are named
var dupFormat = Storage.prefs('teamDuplicateNameFormat') ||

Check failure on line 914 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Trailing spaces not allowed
(typeof PS !== 'undefined' && PS.prefs && PS.prefs.teamDuplicateNameFormat ? PS.prefs.teamDuplicateNameFormat : 'copy');

Check failure on line 915 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'PS' is not defined

Check failure on line 915 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'PS' is not defined

Check failure on line 915 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'PS' is not defined
var newName;
if (dupFormat === 'copy') {
newName = 'Copy of ' + orig.name;
} else {
// strip existing trailing numeric parenthesis like " (v. 3)" or " (3)"
var base = orig.name.replace(/\s*\((?:v\.\s*)?\d+\)$/, '');
// find highest existing index among teams with same base name
var max = 0;
for (var ii = 0; ii < teams.length; ii++) {
var tname = teams[ii].name || '';
var re = new RegExp('^' + base.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '\\s*\\((?:v\\.\\s*)?(\\d+)\\)$');
var m = tname.match(re);
if (m) {
var num = parseInt(m[1], 10);
if (!isNaN(num) && num > max) max = num;
}
}
var next = max + 1;
if (dupFormat === 'paren-v-number') {
newName = base + ' (v. ' + next + ')';
} else {
newName = base + ' (' + next + ')';
}
}
// Debug: show what format was chosen and what name will be used.
if (typeof console !== 'undefined' && console.log) console.log('[teambuilder] duplicate format=', dupFormat, 'newName=', newName);
newTeam = {
name: 'Copy of ' + orig.name,
name: newName,
format: orig.format,
team: orig.team,
capacity: orig.capacity,
Expand Down Expand Up @@ -1208,6 +1298,15 @@
buf += '<div class="teamedit"><textarea class="textbox" rows="17">' + BattleLog.escapeHTML(Storage.exportTeam(this.curSetList, this.curTeam.gen)) + '</textarea></div>';
} else {
buf = '<div class="pad"><button name="back" class="button"><i class="fa fa-chevron-left"></i> List</button> ';
// Duplicate-name preference selector (persisted via Storage.prefs)
var curDupFormat = Storage.prefs('teamDuplicateNameFormat') ||

Check failure on line 1302 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

Trailing spaces not allowed
(typeof PS !== 'undefined' && PS.prefs && PS.prefs.teamDuplicateNameFormat ? PS.prefs.teamDuplicateNameFormat : 'copy');

Check failure on line 1303 in play.pokemonshowdown.com/js/client-teambuilder.js

View workflow job for this annotation

GitHub Actions / build (22.x)

'PS' is not defined
buf += '<label style="margin-left:8px; margin-right:6px; font-weight:600;">Duplicate name:</label>';
buf += '<select name="teamDuplicateFormat">' +
'<option value="copy"' + (curDupFormat === 'copy' ? ' selected' : '') + '>Copy of NAME</option>' +
'<option value="paren-number"' + (curDupFormat === 'paren-number' ? ' selected' : '') + '>NAME (n)</option>' +
'<option value="paren-v-number"' + (curDupFormat === 'paren-v-number' ? ' selected' : '') + '>NAME (v. n)</option>' +
'</select> ';
buf += '<input class="textbox teamnameedit" type="text" class="teamnameedit" size="30" value="' + BattleLog.escapeHTML(this.curTeam.name) + '" /> ';
buf += '<button name="import" class="button"><i class="fa fa-upload"></i> Import/Export</button> ';
buf += '<div class="teamchartbox">';
Expand Down