
Here's a simple JavaScript snippet that automatically counts your published posts and drafts on your Bear Blog dashboard.
Installation
- Go to your Bear Blog dashboard
- Navigate to
/dashboard/customise/ - Find the "Dashboard footer content:" section
- Paste the JavaScript snippet below
- Save
What it does
- Counts published posts and drafts
- Displays the count next to "Posts" heading: "Posts (X published, Y drafts)"
Code
<script>
// Count and display total posts and drafts
(function() {
const postList = document.querySelector('ul.post-list');
if (postList) {
const allPosts = postList.querySelectorAll('li');
const totalCount = allPosts.length;
// Count drafts (posts with "not published" text)
let draftCount = 0;
allPosts.forEach(post => {
const smallElement = post.querySelector('small');
if (smallElement && smallElement.textContent.includes('not published')) {
draftCount++;
}
});
const publishedCount = totalCount - draftCount;
const h1Element = document.querySelector('main h1');
if (h1Element) {
const countSpan = document.createElement('span');
countSpan.textContent = ` (${publishedCount} published, ${draftCount} drafts)`;
countSpan.style.fontSize = '0.8em';
countSpan.style.fontWeight = 'normal';
countSpan.style.color = '#777';
h1Element.appendChild(countSpan);
}
}
})();
</script>
Contribute to bear plugins
You can contribute your own scripts at github.com/HermanMartinus/bear-plugins. This plugin is pending review via PR. I'd also like to extend a special thank you to Robert for bringing the Bear plugins GitHub repo to my attention and for checking if I might be interested in contributing.