// ==UserScript==
// @title nico_history_copy
// @name nico_history_copy
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.nicovideo.jp/my/history
// @grant none
// ==/UserScript==
var result = document.evaluate('//p[@class="posttime"]/text()', document, null, 7, null);
var g_time;
var d_time = [];
for (var i = 0; i < result.snapshotLength; i++) {
g_time = result.snapshotItem(i).nodeValue.replace("年", "/");
g_time = g_time.replace("月", "/");
g_time = g_time.replace("日", "");
g_time = g_time.replace(" 視聴", "");
var d1 = new Date(g_time).getTime();
//console.log(Math.floor(d1/1000));
d_time[i] = Math.floor(d1 / 1000);
}
var result2 = document.evaluate('//input[@class="miniSearchWord"]', document, null, 7, null);
var result3 = document.evaluate('//p[@class="posttime"]/following-sibling::h5/a', document, null, 7, null);
result2.snapshotItem(0).addEventListener('change', function () {
if (result2.snapshotItem(0).value == "copy") {
var s_time = window.prompt("start", "2010/1/23");
var d2 = new Date(s_time).getTime();
console.log(d2);
var t_time = new Date();
var yy = t_time.getFullYear();
var mm = t_time.getMonth() + 1;
var dd = t_time.getDate();
var td_time = yy + "/" + mm + "/" + dd;
var f_time = window.prompt("finish", td_time);
var d3 = new Date(f_time).getTime();
console.log(d3);
var u_list = "";
var flag = 0;
for (i = 0; i < d_time.length; i++) {
if (d_time[i] > Math.floor(d2 / 1000)) {
if (d_time[i] < Math.floor(d3 / 1000)) {
u_list = u_list + " " + result3.snapshotItem(i).href;
flag = 1;
}
}
}
if (flag == 1) {
var sign = window.prompt("url_list", u_list);
} else {
alert("なにかが変です");
}
}
});