This script doesn't work with the middle mouse button, only count the clicks from the left button. I want to add functionality to work with the middle one too, but how? and suggestions?
<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>