まつど
https://gyazo.com/5484c5dfb5a960fd99e19ac2b74b3a97
code:script.js
scrapbox.PopupMenu.addButton({
title : 'Embed Tweet',
onClick : text => {
const convertContent = content => {
const replaced = content
.replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '$1 $2') .replace(/<br>/g, '\n>');
const elem = document.createElement('div');
elem.innerHTML = replaced;
return elem.innerText;
}
const tweetRegex = /<blockquote\w"\-= *><p\w"\-= *>(?<content>.*)<\/p>—(?<author>.*)(?<link><a.*>)<\/blockquote>/; const match = text.match(tweetRegex);
if(!match) return;
const {content, author, link} = match.groups;
return text.replace(tweetRegex, >${convertContent(content)}\n>\t—${author} ${convertContent(link)});
}
})