Time

Script key

Posted by emcristi

Install

Details

Label Time
Voice Over
Script
  getTime = function() {
    var d, pad2;
    pad2 = function(s) {
      return (Array(2).join('0') + s).slice(-2);
    };
    d = new Date();
    return "[" + (pad2(d.getHours())) + ":" + (pad2(d.getMinutes())) + "]";
  };

  transformLine = function(line) {
    var reItem;
    reTime = /\-\ \[(\d\d:\d\d)\]\ /;
    reItem = /^\-\s?/;
    if (reTime.test(line)) {
      return '- ' + line.slice(10);
    } else if (reItem.test(line)) {
      return line.replace(reItem, "- " + (getTime()) + " ");
    } else {
      return ("- " + (getTime()) + " ") + line;
    }
  };

  lineRange = getSelectedLineRange();

  line = getTextInRange.apply(null, lineRange);

  newLine = transformLine(line);

  charsAdded = newLine.length - line.length;

  setTextInRange(lineRange[0], lineRange[1], newLine);

var sr = getSelectedRange();
  //setSelectedRange(lineRange[0] + lineRange[1] + charsAdded, 0);

setSelectedRange(sr[0] + charsAdded, sr[1]);

Advanced

Keyboard shortcut None
Hide key Yes

Discussion

comments powered by Disqus