Bookmarklet: Link Generator for Markdown
Author: nrryuya.icon
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;
var tail = "";
var authors = "";
if (url.indexOf("arxiv.org/abs") !== -1) {
let matches = title.match(/^(^ +) (.+)/); let paper_title = matches2; authors = document.querySelector(".authors").innerText;
title = paper_title;
}
if (url.indexOf("eprint.iacr.org") !== -1) {
title = document.querySelector("b:nth-child(2)").innerText;
authors = document.querySelector("i").innerText;
}
if (url.indexOf("ethresear.ch/t/") !== -1) {
let a = document.querySelector('.relative-date');
let t = new Date(parseInt(a.getAttribute('data-time')));
title = document.querySelector('.fancy-title').innerText;
authors = document.querySelector('#post_1 .username a').innerText;
tail = ", @ethresear.ch, " + t.getFullYear() + "." + ('0' + (t.getMonth() + 1)).slice(-2) + ", " + authors;
}
if (url.indexOf("ethereum-magicians.org/t/") !== -1) {
let a = document.querySelector('.relative-date');
let t = new Date(parseInt(a.getAttribute('data-time')));
title = document.querySelector('.fancy-title').innerText;
authors = document.querySelector('#post_1 .username a').innerText;
tail = ", @ethereum-magicians.org, " + t.getFullYear() + "." + ('0' + (t.getMonth() + 1)).slice(-2) + ", " + authors;
}
if (url.indexOf("medium.com") !== -1) {
title = document.querySelector('.de').innerText;
authors = document.querySelector('.dy.df .bm').innerText;
let date = document.querySelector('.bs .bm').innerText;
tail = ", @Medium, " + date + ", " + authors;
}
if (url.indexOf("hackmd.io") !== -1) {
title = title.substr(0, title.indexOf("- HackMD") - 1);
tail = ", @HackMD";
}
if (title === "") title = url.match(/(^\/+$)/)1; var s = "- + title + "(" + url + ") \n - " + tail + authors;
copy(s);