Topic: Javascript Snippet to make NovelAI Tags more E6AI Friendly

Posted under e621 Tools and Applications

After the third upload I was getting really frustrated manually reformatting the tags I was copy-pasting from my NovelAI prompts, so I threw together a script I paste-in after pasting tags into the last textarea field that makes it a little more E6AI friendly. Not perfect, but it's something.

function convertNovelAITags(txt)
{
    let processedTags = txt.replaceAll("{", "");
    processedTags = processedTags.replaceAll("}", "");
    processedTags = processedTags.replaceAll("[", "");
    processedTags = processedTags.replaceAll("]", "");
    
    processedTags = processedTags.replaceAll("  ", " ");
    processedTags = processedTags.replaceAll("  ", " ");
    processedTags = processedTags.replaceAll("]", "");

    processedTags = processedTags.replaceAll(" ", "_");
    processedTags = processedTags.replaceAll(",_", " ");
    processedTags = processedTags.replaceAll("_,", " ");
    processedTags = processedTags.trim("_").trim();
    
    return processedTags;
}

let otherTags = document.querySelector("#post_tags");
let currentTagText = otherTags.value;

otherTags.value = convertNovelAITags(currentTagText);

To keep with the theme of the site, here's the same script but remade by AI:

/* Write a function that strips all of these characters from the input string: {}[] */
/* Also replace space with underscore */
/* Also replace ,_ with space */
function NAI_to_E6(input) {
    return input.replace(/[{}[\]]/g, '').replace(/ /g, '_').replace(/,_/g, ' ');
}

/* When the user presses CTRL + Enter on the textbox with the ID "#post_tags", replace the text in that box with the function's output. */
let textbox = document.querySelector("#post_tags");
textbox.addEventListener('keydown', function(e) {
    if (e.keyCode == 13 && e.ctrlKey) {
        textbox.value = NAI_to_E6(textbox.value);
    }
});

textbox.placeholder = 'Paste NAI tags here, then press CTRL + Enter to convert them. WARNING: Only convert once, or it\'ll break your spaces!';

(I renamed and rearranged some things, but the AI wrote 90% of it)

That's awesome! Thank you!

feril said:
To keep with the theme of the site, here's the same script but remade by AI:

/* Write a function that strips all of these characters from the input string: {}[] */
/* Also replace space with underscore */
/* Also replace ,_ with space */
function NAI_to_E6(input) {
    return input.replace(/[{}[\]]/g, '').replace(/ /g, '_').replace(/,_/g, ' ');
}

/* When the user presses CTRL + Enter on the textbox with the ID "#post_tags", replace the text in that box with the function's output. */
let textbox = document.querySelector("#post_tags");
textbox.addEventListener('keydown', function(e) {
    if (e.keyCode == 13 && e.ctrlKey) {
        textbox.value = NAI_to_E6(textbox.value);
    }
});

textbox.placeholder = 'Paste NAI tags here, then press CTRL + Enter to convert them. WARNING: Only convert once, or it\'ll break your spaces!';

(I renamed and rearranged some things, but the AI wrote 90% of it)

  • 1