欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

ios 提醒事项和快捷指令,实现进度条功能

程序员文章站 2022-03-11 16:22:02
效果快捷指令链接https://www.icloud.com/shortcuts/348c2ef49da54d7eb47dd8dd856d0c68scriptable代码var parameter = args.shortcutParameter.split("\n")console.log(parameter)const separate = "-------"var reminders = await Reminder.allIncomplete()var title = param...

效果

ios 提醒事项和快捷指令,实现进度条功能

快捷指令链接

https://www.icloud.com/shortcuts/348c2ef49da54d7eb47dd8dd856d0c68

scriptable代码


var parameter = args.shortcutParameter.split("\n")
console.log(parameter)
const separate = "-------"
var reminders = await Reminder.allIncomplete()
var title = parameter[0]
var com_num = parseInt(parameter[1])
var goal_num = parseInt(parameter[2])
var new_note = " "
for(reminder of reminders)
{
  //if(reminder.priority>0)
  { 
    console.log(reminder.title)
    var note = reminder.notes
    if (reminder.title == title)
    {
      //已经设立过目标,需要找到分割线  
      if(!goal_num)
      {
        var list_obj = note.split(separate)
        note = list_obj[0].replace(/^\s+|\s+$/g,'')
        list_obj = list_obj[1].replace(/^\s+|\s+$/g,'').split("\n")
        var reg = /\d+/
        for(let i = 0;i < list_obj.length;i++)
        {
          if(list_obj[i].indexOf("目标")!=-1)
          { 
            goal_num = parseInt(reg.exec(list_obj[i]))  
            break; 
          }
        }
      }
      if(com_num < goal_num)
        reminder.isCompleted = false
       else
        reminder.isCompleted = true
      new_note = generate_str(goal_num,com_num)
      if(note)
         reminder.notes = note + "\n" + new_note
      else
         reminder.notes = new_note
      reminder.save()
      console.log(reminder.title+ " " +reminder.calendar.title+" 备注:\n" +reminder.notes) 
    }  
  }
    
}

Script.setShortcutOutput(new_note)
Script.complete()

function generate_str(goal_num,com_num)
{
    var goal_str = "⭐️目标---" + goal_num + "\n"
    var com_str = "✅完成---" + com_num +  "\n"
    //var per_str = "✅比例---" + Math.trunc(100*com_num/goal_num) + "%\n"  
    var percent = Math.trunc(100*com_num/goal_num)
    var ten = Math.floor(percent/10)
    var one = percent%10
    var progress_bar = ""
    
    var i = 0
    for(;i < ten;i++)
      progress_bar+="

                    
                
相关标签: 笔记