(function () {
const uid = 'ojs-counter-1';
const host = document.getElementById(uid) || document.body;
const container = document.createElement('div');
container.id = uid + '-root';
container.style.maxWidth = '720px';
container.style.margin = '24px auto';
container.innerHTML = `
<div style="text-align:center; padding:28px; font-family:system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;">
<button id="${uid}-btn" aria-live="polite" style="font-size:18px; padding:10px 20px; cursor:pointer; border-radius:6px; border:1px solid #ccc; background:#fff;">
Click to +1!
</button>
<div id="${uid}-display" style="margin-top:22px;">
<h2 style="margin:0; font-weight:600;">Count: <strong id="${uid}-value" style="color:#e15759;">0</strong></h2>
<p id="${uid}-sub" style="color:#666; margin-top:10px;">You've clicked <strong id="${uid}-plural">0</strong> times!</p>
</div>
</div>
`;
host.appendChild(container);
let count = 0;
const btn = document.getElementById(`${uid}-btn`);
const valueEl = document.getElementById(`${uid}-value`);
const pluralEl = document.getElementById(`${uid}-plural`);
function updateUI() {
valueEl.textContent = String(count);
pluralEl.textContent = String(count);
btn.setAttribute('aria-label', `Click to increment. Current count ${count}`);
}
btn.addEventListener('click', () => {
count += 1;
updateUI();
});
btn.addEventListener('keydown', (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
count += 1;
updateUI();
}
});
updateUI();
})();







