embed tweetの展開

embed tweetの展開

/kn1cht/embed-tweetの改変。

expand.js
Copied!
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>.*<script.*?><\/script>/;
const match = text.match(tweetRegex);
if(!match){
console.log('unmatch!');
return;
}
const {content, author, link} = match.groups;
return text.replace(tweetRegex, `>${convertContent(content)}\n>\t—${author} ${convertContent(link)}`);
}
})

import '/api/code/rebuild-kitashirakawa/embed_tweetの展開/expand.js'

Powered by Helpfeel