The new submission feature broke my custom chunker

I have a custom bookmarklet I use that is similar to the one that was recently added to chatgpt. I don’t know what is going on under the hood, but I barely could get this working and now the update broke it completely within a couple days of me getting it set up.
The expected and verified behavior of this script is it will chunk a text file and then stop at a specific punctuation so that lines aren’t cut mid sentence, then it allows you to input a prompt for the AI to follow for each submitted chunk. Translate, Summarize, critique, etc.

The basic functionality is just like the newly implanted one, with a part 1, part 2, etc. but for some reason this does not play nice with your own submission format and I do not know anything sophisticated to fix it. I am getting part 1, part 9, and missing everything in-between large gaps like this. It makes me believe the chunker is not being respected and is somehow fighting with the base one over where and when to stop inputting new text. Lowering the specified chunk size included in your webui doesn’t seem to do anything.

javascript:(function() {

// Create button
let button = document.createElement('button');
button.innerText = 'Submit File';
button.style.backgroundColor = 'green';
button.style.color = 'white';
button.style.padding = '5px';
button.style.border = 'none';
button.style.borderRadius = '5px';
button.style.margin = '5px';

// Create progress bar
let progress = document.createElement('progress');
progress.style.width = '99%';
progress.style.height = '5px';
progress.style.backgroundColor = 'grey';

let progressBar = document.createElement('div');
progressBar.style.width = '0%';
progressBar.style.height = '100%';
progressBar.style.backgroundColor = 'blue';

progress.appendChild(progressBar);

// Insert button and progress bar

let target = document.querySelector(‘.flex.flex-col.w-full.py-2.flex-grow.md\:py-3.md\:pl-4’);
target.parentElement.insertBefore(button, target);
target.parentElement.insertBefore(progress, target);

button.onclick = async () => {
    let fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.accept = '.txt,.js,.py,.html,.css,.json,.csv';
    fileInput.click();
    fileInput.onchange = async (e) => {
        let file = e.target.files[0];
        let reader = new FileReader();
        reader.onload = async (e) => {
            let text = e.target.result;
            let prepend_string = "Please translate this into Japanese. It's better to use anime language/アニメ語 than normal language\n";
            let chunks = chunkString(text, 1000- prepend_string.length, prepend_string);
            let numChunks = chunks.length;
            for (let i = 0; i < numChunks; i++) {
                await submitConversation(chunks[i], i + 1, file.name);
                progressBar.style.width = `${((i + 1) / numChunks) * 100}%`;
            }
            progressBar.style.backgroundColor = 'green';
        };
        reader.readAsText(file);
    };
};

function chunkString(str, chunkSize, prepend_string){
let cursorPosition = 0;
let chunks = ;

while (cursorPosition < str.length) {
    let chunkEnd = cursorPosition + chunkSize;
    if (chunkEnd > str.length) {
        chunkEnd = str.length;
    } else {
        while (str[chunkEnd] !== '.' && str[chunkEnd] !== '?' && str[chunkEnd] !== '!' && chunkEnd < str.length) {
            chunkEnd++;
        }
    }
    chunks.push(prepend_string + str.substring(cursorPosition, chunkEnd + 1));
    cursorPosition = chunkEnd + 1;
}

return chunks;

}
async function submitConversation(text, part, filename) {
const textarea = document.querySelector(“textarea[tabindex=‘0’]”);
const enterKeyEvent = new KeyboardEvent(“keydown”, {
bubbles: true,
cancelable: true,
keyCode: 13,
});
textarea.value = Part ${part} of ${filename}: \n\n ${text};
textarea.dispatchEvent(enterKeyEvent);

    // Check if chatgpt is ready
    let chatgptReady = false;
    while (!chatgptReady) {
        await new Promise(resolve => setTimeout(resolve, 1000));
        chatgptReady = !document.querySelector(".text-2xl > span:not(.invisible)");
    }
}

})()

I’ve diagnosed the issue. it appears that whatever change happened caused the script/chatgpt to no longer wait for the next chunk till after it was done processing, causing large quantities of the text to be skipped. I am not fully certain if I have ironed out any additional errors but it seems to work now. I also inverted the colors for ease of use.