Show HN: All visitors pointers on a webpage (How-to) (hexagon.56k.guru) 8 points by Hexagon56k 2y ago ↗ HN
[–] yetihehe 2y ago ↗ I'm curious how well will it work with 5 thousand pointers... [–] Hexagon56k 2y ago ↗ Would work quite well i think, at last if deployed to deno deploy [–] yetihehe 2y ago ↗ And kill browsers... ws.onmessage = function(event) { Object.keys(cursors).forEach((id) => { if (!positions.find((pos) => pos.id === id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); If I'm not mistaken, this has O(n^2) complexity and is executed on EACH position update. Unless it's autooptimized to not be a linear search on positions? [–] Hexagon56k 2y ago ↗ It was just a quickie for fun, but maybe I should look into that [–] spdustin 2y ago ↗ Yeah, I’d maybe make a set of just the position IDs, and do a negated .has() of that set to check if the cursor was removed. ws.onmessage = function(event) { const positionIds = new Set(positions.map(pos => pos.id)); Object.keys(cursors).forEach((id) => { if (!positionIds.has(id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); }; Untested but that’s probably pretty close for phone typing [–] Hexagon56k 2y ago ↗ Any code written on a phone is impressive ^^ Will try it out [–] Hexagon56k 2y ago ↗ Implemented and working, should probably move this whole thing outside ws.onmessage too, could be run every fifth second or so.
[–] Hexagon56k 2y ago ↗ Would work quite well i think, at last if deployed to deno deploy [–] yetihehe 2y ago ↗ And kill browsers... ws.onmessage = function(event) { Object.keys(cursors).forEach((id) => { if (!positions.find((pos) => pos.id === id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); If I'm not mistaken, this has O(n^2) complexity and is executed on EACH position update. Unless it's autooptimized to not be a linear search on positions? [–] Hexagon56k 2y ago ↗ It was just a quickie for fun, but maybe I should look into that [–] spdustin 2y ago ↗ Yeah, I’d maybe make a set of just the position IDs, and do a negated .has() of that set to check if the cursor was removed. ws.onmessage = function(event) { const positionIds = new Set(positions.map(pos => pos.id)); Object.keys(cursors).forEach((id) => { if (!positionIds.has(id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); }; Untested but that’s probably pretty close for phone typing [–] Hexagon56k 2y ago ↗ Any code written on a phone is impressive ^^ Will try it out [–] Hexagon56k 2y ago ↗ Implemented and working, should probably move this whole thing outside ws.onmessage too, could be run every fifth second or so.
[–] yetihehe 2y ago ↗ And kill browsers... ws.onmessage = function(event) { Object.keys(cursors).forEach((id) => { if (!positions.find((pos) => pos.id === id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); If I'm not mistaken, this has O(n^2) complexity and is executed on EACH position update. Unless it's autooptimized to not be a linear search on positions? [–] Hexagon56k 2y ago ↗ It was just a quickie for fun, but maybe I should look into that [–] spdustin 2y ago ↗ Yeah, I’d maybe make a set of just the position IDs, and do a negated .has() of that set to check if the cursor was removed. ws.onmessage = function(event) { const positionIds = new Set(positions.map(pos => pos.id)); Object.keys(cursors).forEach((id) => { if (!positionIds.has(id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); }; Untested but that’s probably pretty close for phone typing [–] Hexagon56k 2y ago ↗ Any code written on a phone is impressive ^^ Will try it out [–] Hexagon56k 2y ago ↗ Implemented and working, should probably move this whole thing outside ws.onmessage too, could be run every fifth second or so.
[–] Hexagon56k 2y ago ↗ It was just a quickie for fun, but maybe I should look into that [–] spdustin 2y ago ↗ Yeah, I’d maybe make a set of just the position IDs, and do a negated .has() of that set to check if the cursor was removed. ws.onmessage = function(event) { const positionIds = new Set(positions.map(pos => pos.id)); Object.keys(cursors).forEach((id) => { if (!positionIds.has(id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); }; Untested but that’s probably pretty close for phone typing [–] Hexagon56k 2y ago ↗ Any code written on a phone is impressive ^^ Will try it out [–] Hexagon56k 2y ago ↗ Implemented and working, should probably move this whole thing outside ws.onmessage too, could be run every fifth second or so.
[–] spdustin 2y ago ↗ Yeah, I’d maybe make a set of just the position IDs, and do a negated .has() of that set to check if the cursor was removed. ws.onmessage = function(event) { const positionIds = new Set(positions.map(pos => pos.id)); Object.keys(cursors).forEach((id) => { if (!positionIds.has(id)) { document.body.removeChild(cursors[id]); delete cursors[id]; } }); }; Untested but that’s probably pretty close for phone typing [–] Hexagon56k 2y ago ↗ Any code written on a phone is impressive ^^ Will try it out [–] Hexagon56k 2y ago ↗ Implemented and working, should probably move this whole thing outside ws.onmessage too, could be run every fifth second or so.
[–] Hexagon56k 2y ago ↗ Implemented and working, should probably move this whole thing outside ws.onmessage too, could be run every fifth second or so.
[–] SushiHippie 2y ago ↗ https://dimden.dev/Dimden shows all mouse pointers on the web page, the page in general is absolute mint. [–] Hexagon56k 2y ago ↗ Wonderful, reminds me of the good old days!
9 comments
[ 3.3 ms ] story [ 25.3 ms ] threadDimden shows all mouse pointers on the web page, the page in general is absolute mint.