Word Count Bookmarklet
Inspired by See Your Word Count While You Write from dreeves, I whipped up my own word count bookmarklet.
My version:
- displays the word count on the
textareawhen you focus it - updates the count as you type
Tip
Drag this bookmarklet to your bookmarks bar:
Word Counter
How to use:
- Drag the link above to your bookmarks bar
- Click it on any webpage
- Focus on any textarea to see a live word count
Full code:
document.addEventListener('focusin', (e) => {
if (e.target.tagName === 'TEXTAREA') {
const textarea = e.target;
if (textarea.dataset.hasCounter) return;
textarea.dataset.hasCounter = 'true';
const originalPosition = textarea.style.position;
if (!originalPosition || originalPosition === 'static') {
textarea.style.position = 'relative';
}
const counter = document.createElement('div');
counter.style.cssText = `
position: absolute;
bottom: 4px;
right: 8px;
font-size: 11px;
color: #666;
pointer-events: none;
background: rgba(255, 255, 255, 0.9);
padding: 2px 6px;
border-radius: 3px;
font-family: monospace;
z-index: 1;
`;
textarea.parentElement.insertBefore(counter, textarea.nextSibling);
let rafId = null;
const updateCount = () => {
const text = textarea.value.trim();
const words = text ? text.split(/\s+/).length : 0;
counter.textContent = `${words} word${words !== 1 ? 's' : ''}`;
};
textarea.addEventListener('input', () => {
if (rafId) cancelAnimationFrame(rafId);
rafId = requestAnimationFrame(updateCount);
});
updateCount();
textarea.addEventListener('blur', () => {
setTimeout(() => {
if (document.activeElement !== textarea) {
counter.remove();
if (!originalPosition || originalPosition === 'static') {
textarea.style.position = '';
}
delete textarea.dataset.hasCounter;
}
}, 100);
});
}
});
Reference
- Blog / Practicing
- language-javascript, code-snippets, writing
-
Permalink to
2025.BLG.179 - Insight
- Edit
| ← Previous | Next → |
| Making MCP Tool Calls Scriptable with mcp_cli | Contributing to Open-Source Should be Required, Like Jury Duty |