Youtubeの履歴ページに何日前に再生した動画か表示

このスクリプトFirefoxで動作を保証しないものとします
http://let.hatelabo.jp/jigendaddy/let/hJmd56Cuy4Ni.js

// ==UserScript==
// @name         youtube_history_ago
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://www.youtube.com/watch?v=*
// @match        https://www.youtube.com/feed/history
// @grant        none
// @require      https://momentjs.com/downloads/moment-with-locales.js
// ==/UserScript==
//パラメータ削除用関数
function para_del(str) {
  var s_url = str + "&";
  var array_url = s_url.split("&");
  s_url = array_url[0];
  return s_url;
}
//登録処理
var result3 = document.evaluate('id("search-form")', document, null, 7, null);
if (document.getElementById("mark") == null) {
  result3.snapshotItem(0).insertAdjacentHTML('afterend', '<input type="button" value="登録" id="mark">');
}
var result4 = document.evaluate('id("mark")', document, null, 7, null);
result4.snapshotItem(0).addEventListener('click', function () {
  var d_url = location.href;
  var s_url = para_del(d_url);
  if (s_url != "https://www.youtube.com/feed/history") {
    if (window.confirm("アドレスバーに" + s_url + "から始まる文字列が表示されていますか?\n異なる場合はキャンセルを押してください。\nリロードを行います")) {
      localStorage.setItem(s_url, moment().format("YYYY-MM-DD"));
      alert("ローカルストレージにこの動画のキーを登録しました");
    } else {
      location.reload();
    }
  }
});
//検索処理と書き出し
if (document.getElementById("write") == null) {
  result3.snapshotItem(0).insertAdjacentHTML('afterend', '<input type="button" value="表示" id="write">');
}
var result5 = document.evaluate('id("write")', document, null, 7, null);
result5.snapshotItem(0).addEventListener('click', function () {
  var result = document.evaluate('//div[@id="title-wrapper"]//a[@id="video-title"]', document, null, 7, null);
  var result2 = document.evaluate('//ytd-video-renderer//div[@id="metadata-line"]', document, null, 7, null);
  var flag = 0;
  for (var i = 0; i < result.snapshotLength; i++) {
    var n_url = result.snapshotItem(i).href;
    var nr_url = para_del(n_url);
    if (nr_url in localStorage) {
      if (flag != 1) {
        var loop = i + 1;
      }
      var to = moment();
      var from = moment(localStorage.getItem(nr_url), "YYYY-MM-DD");
      if (moment(from).fromNow() != moment().startOf('day').fromNow()) {
        if (to.diff(from, 'day') == 1) {
          result2.snapshotItem(i).insertAdjacentHTML("afterbegin", to.diff(from, 'day') + " day ago ");
        } else {
          result2.snapshotItem(i).insertAdjacentHTML("afterbegin", to.diff(from, 'day') + " days ago ");
        }
      } else {
        result2.snapshotItem(i).insertAdjacentHTML("afterbegin", "Today ");
      }
      flag = 1;
    }
  }
  alert("最後に登録したのは" + loop + "本前に見た動画です");
});