Action
Modify
The same thing as Tim Nahumck’s Text Modifier… action but with the addition of modifying text into the NATO phonetic alphabet. I made this because saying serial numbers over the phone makes me sound dumb.
Steps
-
script
// Text Modifiers (plus NATO alphabet) /* Scripts taken from Drafts 4 and ported to Drafts 5 */ /* Action created by Tim Nahumck then Toffer Surovec added one thing to it by just copying the smallcaps function and changing it slightly because he's not bright enough to do it another way*/ /* --------------------- */ /* ------Functions------ */ /* --------------------- */ // Title Case Function /* --------------------- */ /* To Title Case 2.1 – http://individed.com/code/to-title-case/ */ /* Copyright © 2008–2013 David Gouch. Licensed under the MIT License. */ String.prototype.toTitleCase = function(){ var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\.?|via)$/i; return this.replace(/[A-Za-z0-9\u00C0-\u00FF]+[^\s-]*/g, function(match, index, title){ if (index > 0 && index + match.length !== title.length && match.search(smallWords) > -1 && title.charAt(index - 2) !== ":" && (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') && title.charAt(index - 1).search(/[^\s-]/) < 0) { return match.toLowerCase(); } if (match.substr(1).search(/[A-Z]|\../) > -1) { return match; } return match.charAt(0).toUpperCase() + match.substr(1); }); }; //Small Caps Function /* --------------------- */ // uses Unicode characters function smallCapitalize(input) { var out = ''; for( var i = 0; i <= input.length - 1; i++ ) { var ch = input.charAt( i ); if( ch == 'a' || ch == 'A' ) { out += '\u1D00' } else if( ch == 'b' || ch == 'B' ) { out += '\u0299' } else if( ch == 'c' || ch == 'C' ) { out += '\u1D04' } else if( ch == 'd' || ch == 'D' ) { out += '\u1D05' } else if( ch == 'e' || ch == 'E' ) { out += '\u1D07' } else if( ch == 'f' || ch == 'F' ) { out += '\u0493' } else if( ch == 'g' || ch == 'G' ) { out += '\u0262' } else if( ch == 'h' || ch == 'H' ) { out += '\u029C' } else if( ch == 'i' || ch == 'I' ) { out += '\u026A' } else if( ch == 'j' || ch == 'J' ) { out += '\u1D0A' } else if( ch == 'k' || ch == 'K' ) { out += '\u1D0B' } else if( ch == 'l' || ch == 'L' ) { out += '\u029F' } else if( ch == 'm' || ch == 'M' ) { out += '\u1D0D' } else if( ch == 'n' || ch == 'N' ) { out += '\u0274' } else if( ch == 'o' || ch == 'O' ) { out += '\u1D0F' } else if( ch == 'p' || ch == 'P' ) { out += '\u1D18' } else if( ch == 'q' || ch == 'Q' ) { out += '\u01EB' } else if( ch == 'r' || ch == 'R' ) { out += '\u0280' } else if( ch == 's' || ch == 'S' ) { out += 's' } else if( ch == 't' || ch == 'T' ) { out += '\u1D1B' } else if( ch == 'u' || ch == 'U' ) { out += '\u1D1C' } else if( ch == 'v' || ch == 'V' ) { out += '\u1D20' } else if( ch == 'w' || ch == 'W' ) { out += '\u1D21' } else if( ch == 'x' || ch == 'X' ) { out += 'x' } else if( ch == 'y' || ch == 'Y' ) { out += '\u028F' } else if( ch == 'z' || ch == 'Z' ) { out += '\u1D22' } else { out += ch } } return out; } //Superscript Function /* --------------------- */ // uses Unicode characters function superscript(s) { var pchars = "0123456789n" , cchars = "⁰¹²³⁴⁵⁶⁷⁸⁹ⁿ" , count = pchars.length , regex = new RegExp('[' + pchars + ']', 'g') , trans = {} , lookup = function(c) { return trans[c] || c; }; for (var i=0; i<count; i++) { trans[pchars[i]] = cchars[i]; } return s.replace(regex, lookup); } //Subscript Function /* --------------------- */ // uses Unicode characters function subscript(s) { var pchars = "0123456789" , cchars = "₀₁₂₃₄₅₆₇₈₉" , count = pchars.length , regex = new RegExp('[' + pchars + ']', 'g') , trans = {} , lookup = function(c) { return trans[c] || c; }; for (var i=0; i<count; i++) { trans[pchars[i]] = cchars[i]; } return s.replace(regex, lookup); } //Hyphenate Function /* --------------------- */ function hyphenate(s) { var f = ' ' , r = '-' , re = new RegExp(f, 'g') , matches = s.match(re); if (matches) { return s.replace(re,r); } } //Encircle Function /* --------------------- */ function encircle(s) { var pchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" , cchars = "ⓐⓑⓒⓓⓔⓕⓖⓗⓘⓙⓚⓛⓜⓝⓞⓟⓠⓡⓢⓣⓤⓥⓦⓧⓨⓩⒶⒷⒸⒹⒺⒻⒼⒽⒾⒿⓀⓁⓂⓃⓄⓅⓆⓇⓈⓉⓊⓋⓌⓍⓎⓏ⓪①②③④⑤⑥⑦⑧⑨" , count = pchars.length , regex = new RegExp('.', 'g') , trans = {} , lookup = function(c) { return trans[c] || c; }; for (var i=0; i<count; i++) { trans[pchars[i]] = cchars[i]; } return s.replace(regex, lookup); } //Strikeout Function /* --------------------- */ function strikeout(unstruck) { var s = String.fromCharCode(824) , a = unstruck.split(''); if (a.length > 0) { return a.join(s) + s; } else { return ''; } } //Flip Text Function /* --------------------- */ function flip(s) { var pchars = "abcdefghijklmnopqrstuvwxyz,.?!'(){}[]" , fchars = "ɐqɔpǝɟƃɥıɾʞlɯuodbɹsʇnʌʍxʎz'˙¿¡,)(}{][" , count = pchars.length , regex = new RegExp('.', 'g') , trans = {} , t = s.toLowerCase() , lookup = function(c) { return trans[c] || c; }; for (var i=0; i<count; i++) { trans[pchars[i]] = fchars[i]; } var a = t.split(""); a.reverse(); return a.join("").replace(regex, lookup); } //NATO Function /* --------------------- */ // uses Unicode characters function NATO(input) { var out = ''; for( var i = 0; i <= input.length - 1; i++ ) { var ch = input.charAt( i ); if( ch == 'a' || ch == 'A' ) { out += 'Alfa ' } else if( ch == 'b' || ch == 'B' ) { out += 'Bravo ' } else if( ch == 'c' || ch == 'C' ) { out += 'Charlie ' } else if( ch == 'd' || ch == 'D' ) { out += 'Delta ' } else if( ch == 'e' || ch == 'E' ) { out += 'Echo ' } else if( ch == 'f' || ch == 'F' ) { out += 'Foxtrot ' } else if( ch == 'g' || ch == 'G' ) { out += 'Golf ' } else if( ch == 'h' || ch == 'H' ) { out += 'Hotel ' } else if( ch == 'i' || ch == 'I' ) { out += 'India ' } else if( ch == 'j' || ch == 'J' ) { out += 'Juliett ' } else if( ch == 'k' || ch == 'K' ) { out += 'Kilo ' } else if( ch == 'l' || ch == 'L' ) { out += 'Lima ' } else if( ch == 'm' || ch == 'M' ) { out += 'Mike ' } else if( ch == 'n' || ch == 'N' ) { out += 'November ' } else if( ch == 'o' || ch == 'O' ) { out += 'Oscar ' } else if( ch == 'p' || ch == 'P' ) { out += 'Papa ' } else if( ch == 'q' || ch == 'Q' ) { out += 'Quebec ' } else if( ch == 'r' || ch == 'R' ) { out += 'Romeo ' } else if( ch == 's' || ch == 'S' ) { out += 'Sierra ' } else if( ch == 't' || ch == 'T' ) { out += 'Tango ' } else if( ch == 'u' || ch == 'U' ) { out += 'Uniform ' } else if( ch == 'v' || ch == 'V' ) { out += 'Victor ' } else if( ch == 'w' || ch == 'W' ) { out += 'Whiskey ' } else if( ch == 'x' || ch == 'X' ) { out += 'X-ray ' } else if( ch == 'y' || ch == 'Y' ) { out += 'Yankee ' } else if( ch == 'z' || ch == 'Z' ) { out += 'Zulu ' } else if( ch == '0' || ch == 'Z' ) { out += 'Zero ' } else if( ch == '1' || ch == 'Z' ) { out += 'One ' } else if( ch == '2' || ch == 'Z' ) { out += 'Two ' } else if( ch == '3' || ch == 'Z' ) { out += 'Three ' } else if( ch == '4' || ch == 'Z' ) { out += 'Four ' } else if( ch == '5' || ch == 'Z' ) { out += 'Five ' } else if( ch == '6' || ch == 'Z' ) { out += 'Six ' } else if( ch == '7' || ch == 'Z' ) { out += 'Seven ' } else if( ch == '8' || ch == 'Z' ) { out += 'Eight ' } else if( ch == '9' || ch == 'Z' ) { out += 'Niner ' } else { out += ch } } return out; } // Prompt /* --------------------- */ var lists = ["Encode", "Decode", "Hyphenate", "Small Caps", "Superscript", "Subscript", "lower case", "UPPER CASE", "Title Case", "Encircle", "Flip", "Strikeout", "NATO"]; var p = Prompt.create(); p.title = "Text Modifier"; for (i = 0; i < lists.length; i++) { p.addButton(lists[i]); } var con = p.show(); if (con) { var s = editor.getSelectedText(); var selRange = editor.getSelectedRange(); if (p.buttonPressed == "lower case") { var text = s.toLowerCase(); } if (p.buttonPressed == "UPPER CASE") { var text = s.toUpperCase(); } if (p.buttonPressed == "Title Case") { var text = s.toTitleCase(); } if (p.buttonPressed == "Small Caps") { var text = smallCapitalize(s); } if (p.buttonPressed == "Superscript") { var text = superscript(s); } if (p.buttonPressed == "Subscript") { var text = subscript(s); } if (p.buttonPressed == "Encode") { var text = encodeURIComponent(s); } if (p.buttonPressed == "Decode") { var text = decodeURIComponent(s); } if (p.buttonPressed == "Hyphenate") { var text = hyphenate(s); } if (p.buttonPressed == "Encircle") { var text = encircle(s); } if (p.buttonPressed == "Strikeout") { var text = strikeout(s); } if (p.buttonPressed == "Flip") { var text = flip(s); } if (p.buttonPressed == "NATO") { var text = NATO(s); } editor.setSelectedText(text); editor.setSelectedRange(selRange[0]+text.length,0); editor.activate(); } else { context.cancel(); }
Options
-
After Success Nothing Notification Error Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.