Action

Bump Pages

Posted by sylumer, Last update 2 months ago - Unlisted

Steps

  • script

    function bumpPages()
    {
    	const buttonOK = "OK";
    	let prBump = Prompt.create();
    	prBump.title = "Bump Pages";
    	prBump.addTextField("textFieldName", "Bump all pages by:", 0,
    	{
    		"wantsFocus": true,
    		"keyboard" : "decimalPad"
    	});
    	prBump.addButton(buttonOK);
    	if (prBump.show())
    	{
    		if (prBump.buttonPressed == buttonOK)
    		{
    			draft.content = bumpPagesOutput(parseInt(prBump.fieldValues["textFieldName"]));
    			draft.update();
    		}
    	}
    	return;
    }
    
    function bumpPagesOutput(p_intBump)
    {
    	let astrOutput = []
    	draft.lines.forEach(function(strLine)
    	{
    		const rePage = new RegExp(/^\#\@\d+/);
    		if(rePage.test(strLine))
    		{
    			let intPage = parseInt(strLine.replace(/^\#\@(\d+).*/, "$1"));
    			astrOutput.push(strLine.replace(/^\#\@(\d+)(.*)/, `#@${intPage + p_intBump}$2`))
    		}
    		else astrOutput.push(strLine);
    	});
    	return astrOutput.join("\n");
    }
    
    bumpPages();

Options

  • After Success Default
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.