script.js(() => {
const counters = document.createElement('div');
counters.setAttribute('class', 'counters');
const counts = counters.appendChild(document.createElement('span'));
counts.setAttribute('class', 'item');
const statusBar = document.getElementsByClassName('status-bar')[0];
if (scrapbox.Layout == 'page') {
statusBar.appendChild(counters);
}
scrapbox.on('layout:changed', () => {
if (scrapbox.Layout == 'page') {
statusBar.prepend(counters);
} else {
statusBar.removeChild(counters);
}
});
const updateCounts = () => {
if (!window.scrapbox.Page.lines) return;
const words = scrapbox.Page.lines.map(line => line.text.split(/\s+/).filter(Boolean).length).reduce((a, b) => a + b);
const chars = scrapbox.Page.lines.map(line => line.text.length).reduce((a, b) => a + b);
const lines = scrapbox.Page.lines.length;
counts.innerText = `${words} words, ${chars + lines - 1} chars, ${lines} lines`;
}
updateCounts();
scrapbox.on('lines:changed', updateCounts);
})();