newspicks_save_link
by
jigendaddy
2018-11-19 [2018/11/19 11:39:10]
try to take over the world!
@@ -1,4 +1,5 @@
// ==UserScript==
+// @title newspicks_save_link
// @name newspicks_save_link
// @namespace http://tampermonkey.net/
// @version 0.1
@@ -8,17 +9,18 @@
// @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);
+result.snapshotItem(0).insertAdjacentHTML('beforeend', '<div><input type="button" value="保存"><input type="button" value="開く"><input type="button" value="削除"></div>');
+var result2 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/input[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);
+var result3 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/input[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);
+var result4 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/input[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);
var result6 = document.evaluate('//link[@rel="canonical"]', document, null, 7, null);
+ var pattern = /body\/\?ref\=index/g;
for (var i = 0; i < 128; i++) {
if (!("url" + (i + 1) in localStorage)) {
if (i == 127) {
@@ -28,6 +30,11 @@
alert("このページは既に登録されています");
break;
}
+ /*else if(pattern.test(result5.snapshotItem(0).href))
+ {
+ alert("このページは外部サイトへのリンクではありません");
+ break;
+ }*/
localStorage.setItem("url" + (i + 1), result6.snapshotItem(0).href);
localStorage.setItem(result6.snapshotItem(0).href, result5.snapshotItem(0).href);
alert("「続きを読む」リンクのURLを保存しました");
@@ -41,7 +48,7 @@
var result6 = document.evaluate('//link[@rel="canonical"]', document, null, 7, null);
for (var i = 0; i < 128; i++) {
if ("url" + (i + 1) in localStorage) {
- var tmp = localStorage.getItem(result6.snapshotItem(0).href);
+ var tmp = localStorage.getItem(localStorage.getItem("url" + (i + 1)));
buf = buf + " " + tmp;
} else {
break;
@@ -53,9 +60,15 @@
function sample3() {
var result6 = document.evaluate('//link[@rel="canonical"]', document, null, 7, null);
if (result6.snapshotItem(0).href in localStorage) {
- localStorage.removeItem(result6.snapshotItem(0).href);
- alert("このページをキーから削除しました");
+ for (var i = 0; i < 128; i++) {
+ if (localStorage.getItem("url" + (i + 1)) == result6.snapshotItem(0).href) {
+ localStorage.removeItem("url" + (i + 1));
+ localStorage.removeItem(result6.snapshotItem(0).href);
+ alert("このページをキーから削除しました");
+ break;
+ }
+ }
} else {
- alert("キーが登録されていません");
+ alert("このページのキーが登録されていません");
}
}
// ==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><input type="button" value="保存"><input type="button" value="開く"><input type="button" value="削除"></div>');
var result2 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/input[1]', document, null, 7, null);
result2.snapshotItem(0).addEventListener('click', sample, false);
var result3 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/input[2]', document, null, 7, null);
result3.snapshotItem(0).addEventListener('click', sample2, false);
var result4 = document.evaluate('//div[@class="meta-block clear"]/div[last()]/input[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);
var result6 = document.evaluate('//link[@rel="canonical"]', document, null, 7, null);
var pattern = /body\/\?ref\=index/g;
for (var i = 0; i < 128; i++) {
if (!("url" + (i + 1) in localStorage)) {
if (i == 127) {
alert("保存できるURLの数は128までに制限しています。\nローカルストレージから登録したキーを削除してください");
break;
} else if (localStorage.getItem("url" + i) == result6.snapshotItem(0).href) {
alert("このページは既に登録されています");
break;
}
/*else if(pattern.test(result5.snapshotItem(0).href))
{
alert("このページは外部サイトへのリンクではありません");
break;
}*/
localStorage.setItem("url" + (i + 1), result6.snapshotItem(0).href);
localStorage.setItem(result6.snapshotItem(0).href, result5.snapshotItem(0).href);
alert("「続きを読む」リンクのURLを保存しました");
break;
}
}
}
function sample2() {
var buf = "";
var result6 = document.evaluate('//link[@rel="canonical"]', document, null, 7, null);
for (var i = 0; i < 128; i++) {
if ("url" + (i + 1) in localStorage) {
var tmp = localStorage.getItem(localStorage.getItem("url" + (i + 1)));
buf = buf + " " + tmp;
} else {
break;
}
}
var sign = prompt("url_list", buf);
}
function sample3() {
var result6 = document.evaluate('//link[@rel="canonical"]', document, null, 7, null);
if (result6.snapshotItem(0).href in localStorage) {
for (var i = 0; i < 128; i++) {
if (localStorage.getItem("url" + (i + 1)) == result6.snapshotItem(0).href) {
localStorage.removeItem("url" + (i + 1));
localStorage.removeItem(result6.snapshotItem(0).href);
alert("このページをキーから削除しました");
break;
}
}
} else {
alert("このページのキーが登録されていません");
}
}
- Permalink
- このページへの個別リンクです。
- RAW
- 書かれたコードへの直接のリンクです。
- Packed
- 文字列が圧縮された書かれたコードへのリンクです。
- Userscript
- Greasemonkey 等で利用する場合の .user.js へのリンクです。
- Loader
- @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
- Metadata
- コード中にコメントで @xxx と書かれたメタデータの JSON です。