Action
versions
UPDATES
over 2 years ago
new ‘Should have been'1st paragraph of description:
“Listing of Versions to choose the option of resore/copy/do nothing on the active Draft. Quick/easy external keyboard shortcut device, change for your taste. Likely will be antiquated when native drafts 'Versions’ is more immediately accessible, but right now far fewer keystrokes in/out. ”
changes 2022-05-13
Count of chars, words, or lines is now an option,
Script lines 3-5 set defaults of number displayed, count, and if zeores are used as fillers.
Cancel option allowed on initial version list – if canceled final action options not shown.
over 2 years ago
new ‘Should have been'1st paragraph of description:
“Listing of Versions to choose the option of resore/copy/do nothing on the active Draft. Quick/easy external keyboard shortcut device, change for your taste. Likely will be antiquated when native drafts 'Versions’ is more immediately accessible, but right now far fewer keystrokes in/out. ”
changes 2022-05-13
Count of chars, words, or lines is now an option,
Script lines 3-5 set defaults of number displayed, count, and if zeores are used as fillers.
Cancel option allowed on initial version list – if canceled final action options not shown.
over 2 years ago
cleaned up this description, functional changes previoulsy noted.
over 2 years ago
- Count of chars, words, or lines an option, default set in in first 3-4 lines of script.
- Cancel option allowed on initial version list – if canceled final action options not shown.
Versions (listing of->choose -> restore/copy/do notihng action on the active Draft. Quick/easy external keyboard shortcut device, change for your taste. Likely will be antiquated when native drafts “Versions” is more immediately accessible.
This is a quick javascript that shows the usual version list for THE ACTIVE DRAFT and options to restore/copy to clipboard, or both. Lines 3 and 4 of the script define two numbers may be customize (1. maximum number displayed, 2.format choice of listing (aligned by adding more zeroes, or very slightly out of left alignment).
The version list does not immediately update, but requires another draft to be loaded into editor, or exit/reload. (This is the same behavior as the system).
the bottom two functions are useful additions to a general js library. (I think).
Steps
-
script
// draft versions of current draft // next three lines can be set whatever you might want var maxDisp = 10; // maximum number of versions shown, change as desired var dispWhatLen = "char" ; //default 1st listing; options "characters","words","lines" var intStrLength = 4 ; // set = 0 zero to show no zeroes before the length // (use >0 for a minor display glitch on font formatting alignment in prompt) var tver = draft.versions, nv = '', t1=[], t1str="", t1Len=0, ch='', ch1=''; let longestLine=0, endline = "wrds" ;maincycle = true; let numDisp = tver.length if (numDisp>maxDisp) {numDisp=maxDisp} while (maincycle) { for (let n = 0;n<numDisp;n++) { t1Len = tver[n].content.length; if (dispWhatLen.indexOf("ch")>-1) { endLine = "chars"; } if (dispWhatLen.indexOf("w")>-1) { t1Len = countWords(tver[n].content); endLine = "wrds"; } if (dispWhatLen.indexOf("lin")>-1) { t1Len = (tver[n].content.split('\n')).length; endLine = "lines"; } // that count is approximate t1Len = int2Str(t1Len,intStrLength); //that set up all strings to be equal length (or, if intStrLength=0, not). t1str = n+ strftime(tver[n].createdAt,": %y-%m-%d %I:%M%p..") + t1Len+ endLine ; t1.push(t1str); if (t1str.length>longestLine) {longestLine = t1str.length;} } // end of (for (let n =..._ // (longestLine as max line length for equaliztion, NOT CURRENTLY USED (wodl require monospaced font on the prompt?, or a bot fancier html? //for (let n = 0;n<t1.length;n++) { // t1[n] = t1[n]+ " ".repeat(longestLine-t1[n].length ) + ")"; // (to get line lengths to equalize) // } t1.push(""); t1.push("Change count Char-Word-Line.") t1str = t1.toString(); ch = zBigButnMenu(t1str,',' ,"Which Version to use?",'', true); if ( (ch!=undefined)&&(ch.indexOf("Ch")==0) ) { ch1 = zBigButnMenu('characters,words,lines',"," ,"count what?",'', false); if (ch1.includes("ch")) {dispWhatLen = "characters";} if (ch1.includes("w")) {dispWhatLen = "words";} if (ch1.includes("li")) {dispWhatLen = "lines";} t1 = []; } else { maincycle=false;} } // end of while mainCycle nv = parseInt(ch); if ( (ch != undefined) && (nv!=NaN) ) { // a version list number chosen ch = zBigButnMenu('restore/replace drft,copy->clpbrd,restore©,cancel/noAction', "," ,"do what?",'', false);; if (ch==undefined) {ch = "cancel";} if (ch.includes("copy")) { app.setClipboard(tver[nv].content);} if (ch.includes("rest")) { editor.setText(tver[nv].content);} } // NOTE THE VERSION LIST DOES NOT UPDATE UNTIL A SECOND DRAFT IS LOADED INTO EDITOR // i.e., version[0] will list as last saved, not as current on-screen ; // <><><><><><><><> function zBigButnMenu(strOpts,spltr,strTitle,strMsg,canclTF){ // <><><><><><><><> let qickarr=[],qickbtn=''; if (canclTF==undefined) {canclTF = false}; // default correction for string entry or no entry if ((typeof strOpts)=='string') { if (!(spltr)) {spltr = ",";}; // default qickarr=strOpts.split(spltr); } else { qickarr = strOpts;} qickbtn = Prompt.create(); qickbtn.isCancellable = canclTF; if (strTitle) {qickbtn.title = strTitle}; if (strMsg) {qickbtn.message = strMsg}; for (let t of qickarr) {qickbtn.addButton(t)}; qickbtn.show(); return qickbtn.buttonPressed; }; // end minibutton function // // <><><><><><><><> function int2Str(num,len) { //int->Charstring front-padded with "0" // good for searches, where search for "1targ" would also finds "11targ", "21targ", etc --> "01targ" instead // length of returned string (len) is optional, defaults to 2 (01, 02, etc. ) if (len==0) {return num.toString();} if (len==undefined) {len=2;} let temp=""; for (let n=0;n<len;n++) {temp = temp+'0';} // create '00000...'of length len temp = temp + num.toString(); // '00000...'+num temp = temp.slice(-len); // chop off ending str of length len return temp; }; // // <><><><><><><><> function countWords(str) { // counts between spaces ignores long stretches of spaces, and only terminal linefeed? // s = str; str = str.split(/\s+/); // creating array elements between spaces return str.length; } // end countApprxWords //
Options
-
After Success Default Notification None Log Level Info