// ==UserScript==
// @title youtube_history_ago
// @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 d_url = location.href;
var s_url = para_del(d_url);
if (s_url != "https://www.youtube.com/feed/history") {
localStorage.setItem(s_url, moment().format("YYYYMMDD"));
}
//検索処理と書き出し
var result = document.evaluate('//a[@id="video-title"]', document, null, 7, null);
var result2 = document.evaluate('//div[@id="metadata-line"]', document, null, 7, null);
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 (moment(localStorage.getItem(nr_url), "YYYYMMDD").fromNow() != moment().startOf('day').fromNow()) {
result2.snapshotItem(i).insertAdjacentHTML("afterbegin", moment(localStorage.getItem(nr_url), "YYYYMMDD").fromNow() + " ");
} else {
result2.snapshotItem(i).insertAdjacentHTML("afterbegin", "Today ");
}
}
}