Drafts Action Directory

Insert Text Element…

Posted by @nahumck, Last update 5 months ago

This action allows prompts for a selection of text to insert. You can modify this to be a single insert or expand it to contain multiple prompts.

Install

Steps

  • script

    //Insert Text Elements
    
    var selRange = editor.getSelectedRange();
    
    var p = Prompt.create();
    p.title = "Text Element";
    p.message = "What do you want to insert?";
    p.addButton("break");
    p.addButton("divider");
    p.addButton("script divider");
    p.addButton("more");
    p.addButton("website");
    p.addButton("current draft link");
    
    var con = p.show();
    
    if (con) {
      if (p.buttonPressed == "break") {
        var text = "<br>";
      }
      if (p.buttonPressed == "divider") {
        var text = "----";
      }
      if (p.buttonPressed == "script divider") {
        var text = "\/* --------------------- *\/";
      }
      if (p.buttonPressed == "more") {
        var text = "<!--more-->";
      }
      if (p.buttonPressed == "website") {
        var text = "https://nahumck.me/";
      }
      if (p.buttonPressed == "current draft link") {
        var text = draft.permalink;
      }
      editor.setSelectedText(text);
      editor.setSelectedRange(selRange[0]+text.length,0);
      editor.focus();
    }
    else {
      context.cancel();
    }

Options

  • After Success Default
    Notification Error
    Log Level Error

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.