diff --git a/www/booper.js b/www/booper.js new file mode 100644 index 0000000..3a66620 --- /dev/null +++ b/www/booper.js @@ -0,0 +1,30 @@ +window.addEventListener('load', (e) => { + const targets = document.getElementsByClassName('booperTarget'); + for (let i = 0; i < targets.length; i++) { + const target = targets[i]; + const locators = JSON.parse(target.getAttribute('data-booper')); + console.debug(locators); + target.addEventListener('click', (e) => { + let x = e.offsetX / e.originalTarget.clientWidth; + let y = e.offsetY / e.originalTarget.clientHeight; + for (const [name, box] of Object.entries(locators)) { + const [x1, y1, x2, y2] = box; + if (x >= x1 && x <= x2 && y >= y1 && y <= y2) { + console.log(`[booper.js] Booped ${name}!`); + fetch(`/api/boop/${name}`, {method: 'POST'}).then((r) => { + if (r.ok) { + r.json().then((json) => { + console.debug(json); + }); + } else { + console.error(`[booper.js] Error whilst booping:`); + console.error(r); + } + }); + } + } + }); + } + + console.log(`[booper.js] Initialised ${targets.length} boop target(s)!`); +}); diff --git a/www/index.html b/www/index.html index 4735e96..d5d0ceb 100644 --- a/www/index.html +++ b/www/index.html @@ -8,6 +8,7 @@ + @@ -25,7 +26,7 @@

.

- +

Hi there! I'm Brosef, as you can see by the very fancy changing text about this, I'm interested in a lot of things!