Bookmarklet
minaminao.icon < Scrapbox でリンクを貼るときに普段使ってるもの
code:[].js
javascript:
var copy = s => {
let tmp = document.createElement('textarea');
tmp.value = s;
tmp.selectionStart = 0;
tmp.selectionEnd = tmp.value.length;
tmp.style.position = 'fixed';
tmp.style.left = '-100%';
document.body.appendChild(tmp);
tmp.focus();
let result = document.execCommand('copy');
tmp.blur();
document.body.removeChild(tmp);
return result;
};
var title = document.title.normalize('NFC').replace(/[\\`]/g, ""); var url = location.href;
if (url.indexOf("twitter.com") !== -1 && url.indexOf("status") !== -1) {
let matches = title.match(/^(.*)さんはTwitterを使っています 「(.+)」 \/ Twitter$/);
let a = document.querySelectorAll('a');
let rt;
for (let i = 0; i < a.length; i++) {
if (ai.href.indexOf(url + "/retweets") !== -1) rt = ai.innerText.match(/\d,万k+/); }
let d = document.querySelectorAll('div');
if (!rt) {
let d = document.querySelectorAll('div');
for (let i = 0; i < d.length; i++) {
if (di.getAttribute('data-testid') == "retweet") { break;
}
}
}
if (rt)
title = "(" + rt + " RT) " + matches2 + " - " + matches1 + " - Twitter"; else
title = matches2 + " - " + matches1 + " - Twitter"; }
if (url.indexOf("youtube.com") !== -1) {
let matches = title.match(/^(\(\d+\) )?(.+)$/);
}
if (url.indexOf("codeforces.com") !== -1) {
let matches = url.match(/\d+/);
title = matches0 + title.substr(10); }
if (url.indexOf("arxiv.org/abs") !== -1) {
let matches = title.match(/^(^ +) (.+)/); let paper_title = matches2; let authors = document.querySelector(".authors").innerText;
title = "arxiv:" + id + " " + authors + ". " + paper_title;
}
if (url.indexOf("en.wikipedia.org") !== -1) {
title = title + "(en)";
}
if (url.indexOf("github.com") !== -1) {
let d = document.querySelector('.starred .social-count');
if (d) {
let cnt = d.innerText.replace(/^\s+|\s+$/g, '');
title = title + " (★" + cnt + ")";
}
}
if (url.indexOf("ethresear.ch/t/") !== -1) {
let a = document.querySelector('.relative-date');
let t = new Date(parseInt(a.getAttribute('data-time')));
title = t.getFullYear() + "-" + ('0' + (t.getMonth() + 1)).slice(-2) + "-" + ('0' + t.getDate()).slice(-2) + " " + title;
}
if (title === "") title = url.match(/(^\/+$)/)1; var s = "+ title + " " + url + "";
copy(s);