опиши логику переходов по истории
<input>
<button class="save">save</button>
<button class="back">back</button>
<button class="forward">forward</button>
<script>
function addElement(element, mas, limit) {
if (mas.length > limit - 1) mas.shift();
mas.push(element);
}
document.querySelector(".save").addEventListener("click", function () {
var backBut = document.querySelector(".back");
delete backBut.n;
if (!this.mas) this.mas = [];
var input = document.querySelector("input");
addElement(input.value, this.mas, 10);
input.select();
console.log(this.mas);
});
document.querySelector(".back").addEventListener("click", function () {
var saveBut = document.querySelector(".save");
if (!saveBut.mas) saveBut.mas = [];
mas = saveBut.mas;
if (this.n == undefined) {
(!mas.length) ? this.n = 0 : this.n = mas.length - 1;
}
(this.n <= 0) ? this.n = 0 : this.n--;
document.querySelector("input").value = mas[this.n];
console.log("n=" + this.n + "; mas[n]=" + mas[this.n]);
});
</script>