fix cursor position on weirdly margined pages (body y offset grrr), prevent undefined cursor url, fix goto button

This commit is contained in:
Holly Stubbs 2024-09-16 19:28:44 +01:00
parent 68e3361814
commit 2dab36d2ec
Signed by: tgpholly
GPG Key ID: B8583C4B7D18119E
1 changed files with 18 additions and 9 deletions

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name MultiProbe // @name MultiProbe
// @namespace https://*.angusnicneven.com/* // @namespace https://*.angusnicneven.com/*
// @version 20240527.1 // @version 20240916.0
// @description Probe with friends! // @description Probe with friends!
// @author tgpholly // @author tgpholly
// @match https://*.angusnicneven.com/* // @match https://*.angusnicneven.com/*
@ -48,7 +48,7 @@ console.log("[MP] MultiProbe init");
'use strict'; 'use strict';
// Make sure to change the userscript version too!!!!!!!!!! // Make sure to change the userscript version too!!!!!!!!!!
const USERSCRIPT_VERSION_RAW = "20240527.1"; const USERSCRIPT_VERSION_RAW = "20240916.0";
const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", "")); const USERSCRIPT_VERSION = parseInt(USERSCRIPT_VERSION_RAW.replace(".", ""));
if (!continueRunningScript) { if (!continueRunningScript) {
@ -71,7 +71,10 @@ console.log("[MP] MultiProbe init");
}; };
let cursorImageI = window.getComputedStyle(document.body).cursor; let cursorImageI = window.getComputedStyle(document.body).cursor;
const cssCursor = `${cursorImageI === "auto" || !cursorImageI.includes("url") ? `url(${SITE_DEFAULT_CURSOR[window.location.href.split("//")[1].split("/")[0].split(":")[0]]}) 11 11, auto` : cursorImageI}`; let cssCursor = `${cursorImageI === "auto" || !cursorImageI.includes("url") ? `url(${SITE_DEFAULT_CURSOR[window.location.href.split("//")[1].split("/")[0].split(":")[0]]}) 11 11, auto` : cursorImageI}`;
if (cssCursor.includes("undefined")) {
cssCursor = "auto";
}
console.log("[MP] Injecting custom styles..."); console.log("[MP] Injecting custom styles...");
const styles = document.createElement("style"); const styles = document.createElement("style");
styles.innerHTML = ` styles.innerHTML = `
@ -295,19 +298,24 @@ kbd {
const gotoButton = document.createElement("button"); const gotoButton = document.createElement("button");
gotoButton.innerText = "Go To"; gotoButton.innerText = "Go To";
gotoButton.onclick = () => window.location.href = location; const gotoLoc = location;
gotoButton.onclick = () => {
window.location.href = `https://${gotoLoc}`;
}
buttonBox.appendChild(gotoButton); buttonBox.appendChild(gotoButton);
groupUsers.appendChild(user); groupUsers.appendChild(user);
} }
let clientWidth = document.body.getBoundingClientRect().width; let clientWidth = document.body.getBoundingClientRect().width;
let bodyBoundingRect = document.body.getBoundingClientRect();
setInterval(() => { setInterval(() => {
bodyBoundingRect = document.body.getBoundingClientRect();
if (document.body.scrollHeight > window.innerHeight) { if (document.body.scrollHeight > window.innerHeight) {
otherCursors.style = `width:${clientWidth = (document.body.getBoundingClientRect().width + bodyMarginRight + bodyMarginLeft)}px;height:${document.body.scrollHeight}px;top:-${((window.scrollY + document.body.getBoundingClientRect().top) - bodyMarginTop)}px;cursor: ${cssCursor};`; otherCursors.style = `width:${clientWidth = (bodyBoundingRect.width + bodyMarginRight + bodyMarginLeft)}px;height:${document.body.scrollHeight}px;top:-${((window.scrollY + bodyBoundingRect.top) - bodyMarginTop)}px;cursor: ${cssCursor};`;
} else { } else {
otherCursors.style = `width:${clientWidth = (document.body.getBoundingClientRect().width + bodyMarginRight + bodyMarginLeft)}px;height:${window.innerHeight}px;top:-${((window.scrollY + document.body.getBoundingClientRect().top) - bodyMarginTop)}px;cursor: ${cssCursor};`; otherCursors.style = `width:${clientWidth = (bodyBoundingRect.width + bodyMarginRight + bodyMarginLeft)}px;height:${window.innerHeight}px;top:-${((window.scrollY + bodyBoundingRect.top) - bodyMarginTop)}px;cursor: ${cssCursor};`;
} }
}, 1000); }, 1000);
@ -448,7 +456,7 @@ kbd {
window.onmousemove = (e) => { window.onmousemove = (e) => {
currentMouseX = (rawMouseX = e.clientX) + window.scrollX; currentMouseX = (rawMouseX = e.clientX) + window.scrollX;
currentMouseY = (rawMouseY = e.clientY) + window.scrollY; currentMouseY = (rawMouseY = e.clientY) + window.scrollY + ((window.scrollY + bodyBoundingRect.top) - bodyMarginTop);
if (selfCursor) { if (selfCursor) {
selfCursor.rawSetPosInit(currentMouseX / clientWidth, currentMouseY); selfCursor.rawSetPosInit(currentMouseX / clientWidth, currentMouseY);
selfCursor.updateCursor(); selfCursor.updateCursor();
@ -456,8 +464,9 @@ kbd {
} }
window.onscroll = () => { window.onscroll = () => {
bodyBoundingRect = document.body.getBoundingClientRect();
currentMouseX = rawMouseX + window.scrollX; currentMouseX = rawMouseX + window.scrollX;
currentMouseY = rawMouseY + window.scrollY; currentMouseY = rawMouseY + window.scrollY + ((window.scrollY + bodyBoundingRect.top) - bodyMarginTop);
if (selfCursor) { if (selfCursor) {
selfCursor.rawSetPosInit(currentMouseX / clientWidth, currentMouseY); selfCursor.rawSetPosInit(currentMouseX / clientWidth, currentMouseY);
selfCursor.updateCursor(); selfCursor.updateCursor();
@ -475,7 +484,7 @@ kbd {
if (ws && ready) { if (ws && ready) {
if (allowedPings > 0) { if (allowedPings > 0) {
allowedPings--; allowedPings--;
ws.send(createWriter(Endian.LE, 9).writeUByte(MessageType.Ping).writeFloat((rawMouseX + window.scrollX - 32) / clientWidth).writeInt(rawMouseY + window.scrollY - 32).toBuffer()); ws.send(createWriter(Endian.LE, 9).writeUByte(MessageType.Ping).writeFloat((rawMouseX + window.scrollX - 32) / clientWidth).writeInt(rawMouseY + window.scrollY - 32 + ((window.scrollY + bodyBoundingRect.top) - bodyMarginTop)).toBuffer());
} }
} }
} else if (e.key === "n") { } else if (e.key === "n") {