shokai
http://gyazo.com/69c4e93d637830b3a64dd5493c43d4e2
Scrapboxを開発しています
選択範囲の文字列を反転させる
code:script.js
// alert('load userscript')
scrapbox.PopupMenu.addButton({
title: 'reverse',
onClick: text => text.split('').reverse().join('')
})
行頭に引用符を付ける
code:script.js
scrapbox.PopupMenu.addButton({
title: 'quote',
onClick: text => text.split(/\n/).map(line => > ${line}).join('\n')
})
Google検索
code:script.js
scrapbox.PopupMenu.addButton({
title: 'search',
onClick: text => window.open(https://google.com?q=${encodeURIComponent(text)})
})
Google翻訳
code:script.js
scrapbox.PopupMenu.addButton({
title: 'Google翻訳',
onClick: text => window.open(https://translate.google.com/#ja/en/${text})
})
文字カウント
code:script.js
scrapbox.PopupMenu.addButton({
title: function (text) {
const chars = text.replace(/\r\n/g, '').length const words = text.trim().split(/\r\n\s+/).length return ${chars}c ${words}w
},
onClick: () => null
})
ページの1部分を新規ページに切り出す
code:script.js
scrapbox.PopupMenu.addButton({
title: 'NewPage',
onClick: text => {
const lines = text.split(/\r\n/g) .trim()
.replace(/\^\+.icon\]/gm, '')
const projectRoot = (() => {
const tmp = location.href.split('/')
tmp.pop()
return tmp.join('/')
})()
const currentPageTitle = decodeURIComponent(location.href.split(/\//g).pop())
lines.unshift(from [${currentPageTitle}])
const body = encodeURIComponent(lines.join('\n'))
window.open(${projectRoot}/${title}?body=${body})
return [${title}]
}
})