文字カウント
2つのUserScriptを作ったshokai.icon
ページ内の文字カウント
Page Menuに表示する
https://gyazo.com/b317a5b09ca85cbdc5be95c5a86bdc36
これを自分のページのcode:script.jsの中にコピペして、ブラウザリロード
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)
return ${chars}文字 ${words}単語 ${scrapbox.Page.lines.length}行
},
onClick: () => null
})
範囲選択して文字カウント
Popup Menuに出る
https://gyazo.com/0b55dcdbe7ca4276de306debd9820392
スペース区切りで単語も数える
https://gyazo.com/7634909bea88f6ccf265eb6b5d9b3f8e
日本語だと意味ないけど、英語の時に便利
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
return ${chars}c ${words}w
},
onClick: () => null
})
Chrome v61以降ならESModulesが使えるので
自分のページのcode:script.jsから、こうやってimportする事もできる
code:script.js
import '/api/code/shokai/文字カウント/page.js'
import '/api/code/shokai/文字カウント/popup.js'
最新版のSafariやVivaldiでも動いた