#652 Add custom stop strings

This commit is contained in:
Cohee
2023-07-11 00:24:09 +03:00
parent 5c6c7fd3ca
commit 9ebb1cfe90
3 changed files with 47 additions and 0 deletions

View File

@@ -186,6 +186,8 @@ let power_user = {
persona_description: '',
persona_description_position: persona_description_positions.BEFORE_CHAR,
custom_stopping_strings: '',
};
let themes = [];
@@ -651,6 +653,7 @@ function loadPowerUserSettings(settings, data) {
$('#auto_swipe_minimum_length').val(power_user.auto_swipe_minimum_length);
$('#auto_swipe_blacklist').val(power_user.auto_swipe_blacklist.join(", "));
$('#auto_swipe_blacklist_threshold').val(power_user.auto_swipe_blacklist_threshold);
$('#custom_stopping_strings').val(power_user.custom_stopping_strings);
$("#console_log_prompts").prop("checked", power_user.console_log_prompts);
$('#auto_fix_generated_markdown').prop("checked", power_user.auto_fix_generated_markdown);
@@ -1381,6 +1384,25 @@ function setAvgBG() {
}
export function getCustomStoppingStrings() {
try {
// Parse the JSON string
const 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
return strings.filter((s) => typeof s === 'string');
} catch (error) {
// If there's an error, return an empty array
console.warn('Error parsing custom stopping strings:', error);
return [];
}
}
$(document).ready(() => {
$(window).on('resize', async () => {
@@ -1832,6 +1854,11 @@ $(document).ready(() => {
$(this).toggleClass('fa-eye fa-eye-slash');
});
$('#custom_stopping_strings').on('input', function () {
power_user.custom_stopping_strings = $(this).val();
saveSettingsDebounced();
});
$(window).on('focus', function () {
browser_has_focus = true;
});