文字カウントするUserScript
文字カウントするUserScript
文字数と単語数(スペースで区切られている個数)を判定して,おおよそ1分で300文字読めるとして音読した場合の時間をざっくり計算するUserScript.
選択した部分を調べる
ページ全体を調べる
の2つができる
ただし単語数は日本語の時はほぼ意味がないかもしれない・・・
https://gyazo.com/b193e389aaf853d18a1e67f7bc014b8c
https://gyazo.com/656ef713f1a1511077b1aa4671211f92
https://gyazo.com/476e77fb0a1f764d3d960d907062015d
参考:/shokai/文字カウント
code:page.js
scrapbox.PageMenu.addItem({
title: () => {
if (!scrapbox.Page.lines) return
const chars = scrapbox.Page.lines.map(line => line.text.length).reduce((a,b) => a + b)
const words = scrapbox.Page.lines.map(line => line.text.split(/\s+/).length).reduce((a,b) => a + b)
const speak_min = (chars / 300).toFixed(1)
return ${chars}文字, ${words}単語, ${scrapbox.Page.lines.length}行, ${speak_min}分で音読
},
onClick: () => null
})
code:popup.js
scrapbox.PopupMenu.addButton({
title: function (text) {
const chars = text.replace(/\r\n/g, '').length
const words = text.trim().split(/\r\n\s+/).length
const speak_min = (chars / 300).toFixed(1)
return ${chars}c ${words}w ${speak_min}min
},
onClick: () => null
})
#UserScript