まつど
https://pbs.twimg.com/profile_images/499224812019933186/winTjWyK_400x400.jpeg
まつど.icon
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)});
}
})