Action

Unicode Fun (Encircle or Flip)

Posted by agiletortoise, Last update about 5 years ago

You may have seen some of the fun Unicode conversions people like to use on Twitter and in messaging apps, which replace normal letters with encircled versions of them, or which show the text so that is appears flipped upside down and backward.

This is a handy action to convert a text selection to either of these Unicode versions. To use, select some text, run the action and you be prompted to choose one of these conversions. Enjoy!

encircle > ⓔⓝⓒⓘⓡⓒⓛⓔ
flip > dıןɟ

Steps

  • script

    // function to flip text to upside unicode equivalents
    function flipText(srcText) {
      var out = '';
      for( var i = srcText.length - 1; i >= 0; --i ) {
        var ch = srcText.charAt( i );
        if( ch == 'a' ) { out += '\u0250' }
        else if( ch == 'b' ) { out += 'q' }
        else if( ch == 'c' ) { out += '\u0254' }
        else if( ch == 'd' ) { out += 'p' }
        else if( ch == 'e' ) { out += '\u01DD' }
        else if( ch == 'f' ) { out += '\u025F' }
        else if( ch == 'g' ) { out += '\u0183' } //1D77' }
        else if( ch == 'h' ) { out += '\u0265' }
        else if( ch == 'i' ) { out += '\u0131' } //1D09' '\u01C3' '\u0131' }
        else if( ch == 'j' ) { out += '\u017F'} //1D98' '\u0638' }
        else if( ch == 'k' ) { out += '\u029E' }
        else if( ch == 'l' ) { out += '\u05DF' }
        else if( ch == 'm' ) { out += '\u026F' }
        else if( ch == 'n' ) { out += 'u' }
        else if( ch == 'o' ) { out += 'o' }
        else if( ch == 'p' ) { out += 'd' }
        else if( ch == 'q' ) { out += 'b' }
        else if( ch == 'r' ) { out += '\u0279' }
        else if( ch == 's' ) { out += 's' }
        else if( ch == 't' ) { out += '\u0287' }
        else if( ch == 'u' ) { out += 'n' }
        else if( ch == 'v' ) { out += '\u028C' }
        else if( ch == 'w' ) { out += '\u028D' }
        else if( ch == 'x' ) { out += 'x' }
        else if( ch == 'y' ) { out += '\u028E' }
        else if( ch == 'z' ) { out += 'z' }
        else if( ch == '(' ) { out += ')' }
        else if( ch == ')' ) { out += '(' }
        else if( ch == '{' ) { out += '}' }
        else if( ch == '}' ) { out += '{' }
        else if( ch == '[' ) { out += ']' }
        else if( ch == ']' ) { out += '[' }
        else if( ch == '<' ) { out += '>' }
        else if( ch == '>' ) { out += '<' }
        else if( ch == '0' ) { out += '0' }
        else if( ch == '1' ) { out += '\u0196' }
        else if( ch == '2' ) { out += '\u01A7' }
        else if( ch == '3' ) { out += '\u0190' }
        else if( ch == '4' ) { out += '\u152D' } // 056B' }
        else if( ch == '5' ) { out += 'S' }
        else if( ch == '6' ) { out += '9' }
        else if( ch == '7' ) { out += 'L' }
        else if( ch == '8' ) { out += '8' }
        else if( ch == '9' ) { out += '6' }
        else if( ch == '?' ) { out += '\u00BF' }
        else if( ch == '\u00BF' ) { out += '?' }
        else if( ch == '!' ) { out += '\u00A1' }
        else if( ch == '\u00A1' ) { out += '!' }
        else if( ch == "\'" ) { out += ',' }
        else if( ch == ',' ) { out += "\'" }
        else if( ch == '.' ) { out += '\u02D9' }
        else if( ch == '_' ) { out += '\u203E' }
        else if( ch == ';' ) { out += '\u061B' }
        else if( ch == '"' ) { out += '\u201E' }
        else if( ch == "'" ) { out += ',' }
        else if( ch == '&' ) { out += '\u214B' }
        else { out += ch }
      }
      return out;
    }
    
    // encircle text
    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);
    }
    
    let f = () => {
    	let s = editor.getSelectedText();
    	let p = Prompt.create();
    	p.title = "Modify Selection";
    	p.message = "Convert selected text to special unicode version.";
    	
    	p.addButton("encircle > ⓔⓝⓒⓘⓡⓒⓛⓔ", "encircle");
    	p.addButton("flip > dıןɟ");
    	
    	if (!p.show()) { return false; }
    	if (p.buttonPressed == "encircle") {
    		editor.setSelectedText(encircle(s));
    	}
    	else {
    		editor.setSelectedText(flipText(s));
    	}
    	return true;
    }
    
    if (!f()) { context.cancel(); }
    

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.