Tweetの埋め込み
twitterを埋め込む、お借り先。
/kn1cht/embed-tweet
/villagepump/UserScriptを他人のprojectから読み込むな読んで、importから2022/2/16時点のもののコピペに変更しました。
code:script.js
// twitterを埋め込む
scrapbox.PopupMenu.addButton({
title : 'Embed Tweet',
onClick : text => {
const convertContent = (content, indent) => {
const replaced = content
.replace(/<a href="(https?:.*?)">(.*?)<\/a>/g, '$1 $2')
.replace(/<br>/g, \n${indent});
const elem = document.createElement('div');
elem.innerHTML = replaced;
return indent + elem.innerText;
}
const tweetRegex = /(?<spaces>\t *)<blockquote\w"\-= *><p\w"\-= *>(?<content>.*)<\/p>&mdash;(?<author>.*)(?<link><a.*>)<\/blockquote>\n\t *<script.*?><\/script>/;
const match = text.match(tweetRegex);
if(!match) return;
const {spaces, content, author, link} = match.groups;
const ind = ${spaces}>;
return text.replace(tweetRegex, convertContent(content, ind) + '\n' + convertContent(\t—${author} ${link}, ind));
}
})
#UserScript