Q:

How to reset an automatically function of a slideshow when next/back button is pressed?

I have a slideshow of images,that it changes automatically( autoslide() ) every 4 sec, so when i press one of the next/back buttons, the countdown continues.
How I want to behaves : When one of the next/back buttons is pressed,  the autoslide function countdown starts over from 0 seconds, without continuing the previous countdown.

var index = 1;

function plusindex(n) {
  showimage(index += n);
}

showimage(index);

function showimage(n) {
  var slide = document.getElementsByClassName('sliders');

  if (n > slide.length) {
    index = 1
  };
  if (n < 1) {
    index = slide.length
  };
  for (i = 0; i < slide.length; i++) {
    slide[i].style.display = "none";
  }
  slide[index - 1].style.display = "block";

}

var time = 4000;
autoslide()

function autoslide() {
  var slide = document.getElementsByClassName('sliders');
  for (i = 0; i < slide.length; i++) {
    slide[i].style.display = "none";
  }
  if (index > slide.length) {
    index = 1
  };
  slide[index - 1].style.display = "block";
  index++;
  setTimeout(autoslide, time);
}
<button class="btn" id="btn1" onclick="plusindex(-1)">&#10094</button>
<button class="btn" id="btn2" onclick="plusindex(1)">&#10095</button>

A:

You could do this using clearTimeout. You function autoslide is to be modified as follows:
var timer;
function autoslide() {
  var slide = document.getElementsByClassName('sliders');
  for (i = 0; i < slide.length; i++) {
    slide[i].style.display = "none";
  }
  if (index > slide.length) {
    index = 1
  };
  slide[index - 1].style.display = "block";
  index++;
  timer = setTimeout(autoslide, time);
}

Here the timer keeps track of your next scheduled sliding. So, here's how you could use that to reset the timer:
function plusindex(n){
  showimage(index +=n);
  clearTimeout(timer);
  timer = setTimeout(autoslide,time);
}

