UserScript:Popup-Tweet
選択されたテキストをTwitterでつぶやく
scriptxx.jsscrapbox.PopupMenu.addButton({
title: function (text) {
const chars = 117 - text.replace(/[\r\n]|\[|\]/g, '').length
return `Tw ${chars}C`
},
onClick: text =>
(text.replace(/[\r\n]|\[|\]/g, '').length < 117) ?
window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(location.href)}&text=${encodeURIComponent(text.replace(/\[|\]/g,""))}`) :
window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(location.href)}&text=${encodeURIComponent(text.replace(/\[|\]/g,"").substr(0,116)+"…")}`)
})
script.jsscrapbox.PopupMenu.addButton({
title: function (text) {
const ttext = scrapbox.Page.title + "\n" + text
const chars = 117 - text.replace(/[\r\n]|\[|\]/g, '').length
return `TT ${chars}C`
},
onClick: text => {
const twtext = scrapbox.Page.title + "\n" + text
return (twtext.replace(/[\r\n]|\[|\]/g, '').length < 117) ?
window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(location.href)}&text=${encodeURIComponent(twtext.replace(/\[|\]/g,""))}`) :
window.open(`https://twitter.com/intent/tweet?url=${encodeURIComponent(location.href)}&text=${encodeURIComponent(twtext.replace(/\[|\]/g,"").substr(0,116)+"…")}`)
}
})
元ネタ
うん、そのまんまだ。