何でもブクマがほしい
Anthologyのスクボはあるけど、qiitaとかもスクボしたい。
いろんなページを自動スクボできるボタンを作れたら良いな
code:スクボ.js
// スクボのURL
var scrapbox_url = "https://scrapbox.io/jyori112/";
// jumpする用の関数
function jump(title, body) {
var url = scrapbox_url + encodeURIComponent(title);
window.open(url + "?body=" + encodeURIComponent(body + "\n"), '_blank');
}
// 対応するサイトのURLパターン
var acl_pattern = /https:\/\/www\.aclweb\.org\/anthology\/^\/+\//;
var arxiv_pattern = /https:\/\/arxiv\.org\/abs\/0-9\.+?/;
var qiita_pattern = /https:\/\/qiita\.com\/a-zA-Z0-9_+\/items\/0-9a-f+\/?/;
var wikipedia_pattern = /https:\/\/a-z+\.wikipedia\.org\/wiki\/.+/;
var youtube_pattern = /https:\/\/www\.youtube\.com\/watch\?v=.+/;
var amazon_pattern = /(https:\/\/www\.amazon\.(co\.jp|com))\/(.+\/)?dp\/(0-9A-Z+)/;
var scrapbox_pattern = /https:\/\/scrapbox\.io\/(.+)/;
var currentURL = window.location.href;
if (currentURL.match(acl_pattern)) {
jump(document.getElementById("title").textContent.trim(),
"#論文読み\n" + window.location.href);
} else if (currentURL.match(arxiv_pattern)) {
var title = document.getElementsByClassName('title')0
.textContent.replace(/^title:/gi, '').trim();
jump(title, "#論文読み\n" + window.location.href);
} else if (currentURL.match(qiita_pattern)) {
var title = document.getElementsByTagName('h1')0.textContent.trim();
var tags = "#qiita";
document.getElementsByClassName("it-Tags_item").forEach(function (elm) {
tags.push("#" + elm.textContent.trim());
});
jump(title, tags.join(" ") + "\n" + window.location.href);
} else if (currentURL.match(wikipedia_pattern)) {
var title = document.getElementById('firstHeading').textContent.trim();
var first_p = document.getElementsByClassName('mw-parser-output')0.getElementsByTagName('p')0;
var text = first_p.textContent.trim().replace(/(\r\n|\n|\r)/gm,"\n>");
jump(title, currentURL + "\n\n>" + text);
} else if (currentURL.match(youtube_pattern)) {
var title = document.getElementsByClassName('title')0.textContent;
jump(title, "+ currentURL + "");
} else if (currentURL.match(amazon_pattern)) {
var match = currentURL.match(amazon_pattern);
jump(document.title, match1 + '/dp/' + match4);
} else if (currentURL.match(scrapbox_pattern)) {
var page_id = decodeURIComponent(window.location.pathname);
jump(document.title, [${page_id.replaceAll("_", ' ')}]);
} else {
jump(document.title, currentURL);
}
更新履歴
2020/6/15
wikipediaに対応
最初の段落をコピペすることにした
2020/6/22
その他のページの本文にURLがなかったので追加
youtubeを追加
開くページを新しいタブに