The approach of the script you posted is all wrong. Where did you get it? Is this ChatGPT's work?
Adding paragraphs in the story is messy and makes it hard to delete the continuation prompts. It's much better to place the prompts in text frames on a dedicated layer. To remove the prompts, all you need to do is remove that layer.
The script below assumes the presence of object styles for the text frames. The paragraph styles for the prompts are applied in the object style, and so are size and position. So all the script needs to do is place a frame and add the style and the prompt. The attached InDesign document shows the set-up (you need to refine the styles).
To see how it works, open the document, select a story (a text frame or an insertion point) and run the script.
(function () {
if (app.selection.length === 0 || !app.selection[0].hasOwnProperty ('parentStory')) {
alert ('Select a story');
exit();
}
var d = app.activeDocument;
var layer = d.layers.item ('Continua');
var ostyleContinua = d.objectStyles.item ('Etiquetacontinua');
var ostyleContinuacion = d.objectStyles.item ('Etiquetacontinuacion');
var continuaText = 'El código continúa en la página siguiente →';
var continuacionText = '← Continuación del código anterior';
if (layer.isValid) {
layer.remove();
}
var layer = d.layers.add ({name: 'Continua'});
var frames = app.selection[0].parentStory.textContainers;
for (var i = 1; i < frames.length; i++) {
if (frames[i].parentPage.side === PageSideOptions.RIGHT_HAND) {
if (frames[i].lines[0].appliedParagraphStyle.name === 'CodigoHTML') {
frames[i-1].parentPage.textFrames.add ({
appliedObjectStyle: ostyleContinua,
contents: continuaText
});
frames[i].parentPage.textFrames.add ({
appliedObjectStyle: ostyleContinuacion,
contents: continuacionText
});
}
}
}
}());
... View more