Drafts Action Directory

字数统计

Posted by Phil, Last updated: 2018-07-04 14:28:44 UTC

统计当前draft的字数。用于弥补Drafts在中午文环境下字数统计不正确的缺陷。

Install

Steps

  • script

    // See online documentation for examples
    // http://getdrafts.com/scripting
    var text = editor.getText()
    var totalCount = text.length
    var cnCount = 0
    var enCount = 0
    var numberCount = 0
    var asciiCount = 0
    var symbolCount = 0
    
    var cnReg = /^[\u4E00-\uFA29]*$/
    var enReg = /^[a-zA-Z()]+$/
    var numberReg = /^\d$/
    var asciiReg = /^[\x00-\xFF]*$/
    var symbolReg = /[ !@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/
    
    for (var i = 0; i < text.length; ++i) {
    
      var character = text.charAt(i)
    
      if (cnReg.test(character)) {
        ++cnCount
      }
      
      if (enReg.test(character)) {
        ++enCount
      }
    
      if (numberReg.test(character)) {
        ++numberCount
      }
    
      if (asciiReg.test(character)) {
        ++asciiCount
      }
    
      if (symbolReg.test(character)) {
        ++symbolCount
      }
    }
    
    var message = ""
    message += "总计: " + totalCount + "\n"
    message += "中文: " + cnCount + "\n"
    message += "英文: " + enCount + "\n"
    message += "数字: " + numberCount + "\n"
    message += "ASCII: " + asciiCount + "\n"
    message += "符号: " + symbolCount
    var p = Prompt.create()
    p.title = "字数统计"
    p.message = message
    p.show()

Options

  • After Success Default
    Notification Info
    Log Level Info

Comments

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