Action
Insert Day of Week
Posted by kjz,
Last update
about 4 years ago
- Unlisted
Inserts day of the week after a chosen string, “Day:”, in the draft.
Steps
-
script
//Function returns current day of week function findDayofWeek() { let d = new Date(); let day = d.getDay(); var dayOfWeek = [" Sunday", " Monday", " Tuesday", " Wednesday", " Thursday", " Friday", " Saturday"]; let currentDay = dayOfWeek[day]; return currentDay; } // Function to escape special characters function escapeRegExp(stringToGoIntoTheRegex) { return stringToGoIntoTheRegex.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); } // Function to insert cursor after defined string in draft // uses function to escape any special characters possibly in the string function cursorInsert(stringToInsertAfter) { var textToFind = stringToInsertAfter; var stringToGoIntoTheRegex = escapeRegExp(textToFind); //escape the string var textName = new RegExp(stringToGoIntoTheRegex); //regex for the string var textLength = textToFind.length; var d = draft.content; var textStart = d.search(textName); //find start of the string editor.setSelectedRange(textStart+textLength,""); //insert cursor at string end editor.activate(); } var stringToInsertAfter = "Day:" //string to find in the draft, hardcoded cursorInsert(stringToInsertAfter); // fnc puts cursor after chosen string var dayOfWeek = findDayofWeek(); editor.setSelectedText(dayOfWeek); editor.activate();
Options
-
After Success Default Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.