// ==UserScript==
// @title newspicks_save_link
// @name newspicks_save_link
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://newspicks.com/news/*
// @grant none
// ==/UserScript==
var result = document.evaluate('//div[@class="meta-block clear"]', document, null, 7, null);
result.snapshotItem(0).insertAdjacentHTML("beforeend", "<div><a href='javascript:void(0);'><img src='https://cdn-ak.f.st-hatena.com/images/fotolife/j/jigendaddy/20181107/20181107150929.png'></a> <a href='javascript:void(0);'><img src='https://cdn-ak.f.st-hatena.com/images/fotolife/j/jigendaddy/20181107/20181107150926.png'></a> <a href='javascript:void(0);'><img src='https://cdn-ak.f.st-hatena.com/images/fotolife/j/jigendaddy/20181107/20181107154129.png'></a></div>");
var result2 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/a[1]', document, null, 7, null);
result2.snapshotItem(0).addEventListener('click', sample, false);
var result3 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/a[2]', document, null, 7, null);
result3.snapshotItem(0).addEventListener('click', sample2, false);
var result4 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/a[3]', document, null, 7, null);
result4.snapshotItem(0).addEventListener('click', sample3, false);
function sample() {
var result5 = document.evaluate('//a[@class="read-more center"]', document, null, 7, null);
for (var i = 0; i < 128; i++) {
if (!("url" + (i + 1) in localStorage)) {
if (i == 127) {
alert("保存できるURLの数は128までに制限しています。\nゴミ箱のアイコンをクリックしてローカルストレージから登録したキーを削除してください");
break;
}
localStorage.setItem("url" + (i + 1), result5.snapshotItem(0).href);
alert("「続きを読む」リンクのURLを保存しました");
break;
}
}
}
function sample2() {
var buf = "";
for (var i = 0; i < 128; i++) {
if ("url" + (i + 1) in localStorage) {
var tmp = localStorage.getItem("url" + (i + 1));
buf = buf + " " + tmp;
} else {
break;
}
}
var sign = prompt("url_list", buf);
}
function sample3() {
var flag = 0;
for (var i = 0; i < 128; i++) {
if ("url" + (i + 1) in localStorage) {
localStorage.removeItem("url" + (i + 1));
flag = 1;
} else {
if (flag == 1) {
alert("削除しました");
} else {
alert("キーが登録されていません");
}
break;
}
}
}