diff --git a/public/script.js b/public/script.js index 5652133ec..d33da5ee3 100644 --- a/public/script.js +++ b/public/script.js @@ -1801,11 +1801,7 @@ function getStoppingStrings(isImpersonate, addSpace) { if (power_user.custom_stopping_strings) { const customStoppingStrings = getCustomStoppingStrings(); - if (power_user.custom_stopping_strings_macro) { - result.push(...customStoppingStrings.map(x => substituteParams(x, name1, name2))); - } else { - result.push(...customStoppingStrings); - } + result.push(...customStoppingStrings); } return addSpace ? result.map(x => `${x} `) : result; diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index 569aba16a..da034c844 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -1616,7 +1616,7 @@ function setAvgBG() { /** * Gets the custom stopping strings from the power user settings. - * @param {number | undefined} limit Number of strings to return. If undefined, returns all strings. + * @param {number | undefined} limit Number of strings to return. If 0 or undefined, returns all strings. * @returns {string[]} An array of custom stopping strings */ export function getCustomStoppingStrings(limit = undefined) { @@ -1627,15 +1627,27 @@ export function getCustomStoppingStrings(limit = undefined) { } // Parse the JSON string - const strings = JSON.parse(power_user.custom_stopping_strings); + let strings = JSON.parse(power_user.custom_stopping_strings); // Make sure it's an array if (!Array.isArray(strings)) { return []; } - // Make sure all the elements are strings. Apply the limit. - return strings.filter((s) => typeof s === 'string').slice(0, limit); + // Make sure all the elements are strings. + strings = strings.filter((s) => typeof s === 'string'); + + // Substitute params if necessary + if (power_user.custom_stopping_strings_macro) { + strings = strings.map(x => substituteParams(x)); + } + + // Apply the limit. If limit is 0, return all strings. + if (limit > 0) { + strings = strings.slice(0, limit); + } + + return strings; } catch (error) { // If there's an error, return an empty array console.warn('Error parsing custom stopping strings:', error);