Este script no funciona con el botón central del mouse, solo cuenta los clics del botón izquierdo. Quiero agregar funcionalidad para trabajar con el medio también, pero ¿cómo? y sugerencias?
<body> <a href="https://www.google.com" target="_blank" onclick="countClick('google1')">Google</a> <a href="https://www.duckduckgo.com" target="_blank" onclick="countClick('duckduckgo1')">DuckDuckGo</a> <div>Google was clicked <span id="google1_clicks">0</span> times.</div> <div>DuckDuckGo was clicked <span id="duckduckgo1_clicks">0</span> times.</div> <script> const requestHandler = async function(type, key) { return await fetch(`https://api.countapi.xyz/${type}/test/${key}`) .then(res => res.json()) .then(res => res.value || 0) .catch(() => 0) } const loadClicks = (async function() { document.getElementById('google1_clicks').innerHTML = await requestHandler('get', 'google1') document.getElementById('duckduckgo1_clicks').innerHTML = await requestHandler('get', 'duckduckgo1') })() const countClick = async function(key) { document.getElementById(`${key}_clicks`).innerHTML = await requestHandler('hit', key) } </script> </body> </html>