generated at
まつど




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>&mdash;(?<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)}`); } })