選択範囲をtweetするUserScript
Tweet Menuの範囲選択バージョン
scrapboxで考えを書いている時に、twitterに投稿したいと思う事がある
UserScriptで実装した
元ネタは/tanabe1478-96109098/Scrapboxを書いている時に選択しているテキストをツイートしたい
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Tweet',
onClick: text => {
const lines = text
.split(/\r\n/)
.map(line => line.replace(/[\\]/g, '').replace(/^\s+/, ''))
lines.push(location.href)
const url = https://twitter.com/intent/tweet?&text=${encodeURIComponent(lines.join('\n'))}
const width = 550
const height = 420
const option = width=${width},height=${height},left=${(window.innerWidth - width) / 2},top=${(window.innerHeight - height) / 2},scrollbars=yes,resizable=yes,toolbar=no,location=yes
window.open(url, '_blank', option)
}
})
変更した所
ページのURLを末尾に入れる
リンク記法のカッコを外す
ここはplainボタンで使っているplainTextRenderを使えるようにしたい
新scrapbox記法parserも
行頭のスペースも削除した
一応constを使う
複数行選択した時に改行をキープしたままtweetできるよう、encodeURIComponentしてからURL引数に渡す
第三引数もバッククオートによる文字列テンプレートを使う
このtweet方法だとreplyできないのでtreeが作れない