recommend changes

recommend changes

Hi, 

I am new to jqeury. 

Could you please tell me how to get the most of this script. I wrote it by myself and there is quite few repetitions. 

  1.             $("textarea[name='storyline']").blur(function() {
  2.                 storylineAjaxUpdate();
  3.                 eventViewer('Storyline has been saved');
  4.             });

  5.             var strokeCount = 0;
  6.             $("textarea[name='storyline']").keyup(function() {
  7.                 strokeCount = ++strokeCount;

  8.                 if (strokeCount > 100) {
  9.                     storylineAjaxUpdate();
  10.                     eventViewer('Storyline has been saved');
  11.                     strokeCount = 0;
  12.                 }
  13.             });

  14.             function eventViewer(msg) {
  15.                 var date = new Date();

  16.                 var minutes = date.getMinutes();
  17.                 var hours = date.getHours();
  18.                 var seconds = date.getSeconds();

  19.                 $(".eventManager .menu-title").after("<p>" + msg + "<span class='small'> (" + hours + ":" + minutes + ":" + seconds + ")</span></p>");
  20.                 $(".eventManager p:eq(1)").fadeOut(6000);
  21.             }

  22.             function storylineAjaxUpdate(success = '', error = '') {
  23.                 var storyline = $("textarea[name='storyline']").val();
  24.                 var token = $("input[name='_token']").val();

  25.                 $.ajax({
  26.                     type: 'PATCH',
  27.                     url: "{{ url('/') }}/admin/dealer/add-article/storyline/{{ $articleToEdit->id }}",
  28.                     dataType: 'json',
  29.                     data: {
  30.                         'storyline': storyline,
  31.                         '_token': token
  32.                     },
  33.                     success: success,
  34.                     error: error,
  35.                 });

so that is the code. I want to create autosave for my articles and storyline. This script taking care of just the storyline. 

as I am new to jquery I would like to know what I can actually improve before writing the article part. 

I would also point at the coloured parts. 
RED , I dont like that the variable is out of the block. Can I move it in any way? 
BLUE , I consider this a little bit crazy. Is there any better way how to work with date and time? Couldnt find anything easier. 

How can I add 0 before digits of one place e.g. 1, 2, 3...?

Thank you.