Hi, I’m new to scripting. I’m trying to make an action that replaces text at the end of a Dropbox link in the current draft.
Using this script I can replace text using the location (argument?) but only counting from the start of the link. I thought I could use a minus number to count back from the end, but this doesn’t work. Any help would be appreciated.
var text = editor.getSelectedText(); editor.setTextInRange("10","6","_text_");
You could do it with the editor object too, including everything or just the selection, but I figured it would be most efficient to do the whole draft at once, and this general approach is more broadly applicable in that you can run it on multiple drafts without needing to load each into the editor to process it.
With some modification, yes, you would need to prime a regular expression object with the search string and use that for the find component.
This should prove to be an altogether simpler state of affairs.
let oldExtension = "?dl=0";
let newExtension = "?raw=1";
draft.content = draft.content.replaceAll(oldExtension, newExtension);