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

View file

@ -1,7 +1,7 @@
// ==UserScript==
// @name MultiProbe
// @namespace https://*.angusnicneven.com/*
// @version 20240527.1
// @version 20240916.0
// @description Probe with friends!
// @author tgpholly
// @match https://*.angusnicneven.com/*
@ -48,7 +48,7 @@ console.log("[MP] MultiProbe init");
'use strict';
// 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(".", ""));
if (!continueRunningScript) {
@ -71,7 +71,10 @@ console.log("[MP] MultiProbe init");
};
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...");
const styles = document.createElement("style");
styles.innerHTML = `
@ -295,19 +298,24 @@ kbd {
const gotoButton = document.createElement("button");
gotoButton.innerText = "Go To";
gotoButton.onclick = () => window.location.href = location;
const gotoLoc = location;
gotoButton.onclick = () => {
window.location.href = `https://${gotoLoc}`;
}
buttonBox.appendChild(gotoButton);
groupUsers.appendChild(user);
}
let clientWidth = document.body.getBoundingClientRect().width;
let bodyBoundingRect = document.body.getBoundingClientRect();
setInterval(() => {
bodyBoundingRect = document.body.getBoundingClientRect();
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 {
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);
@ -448,7 +456,7 @@ kbd {
window.onmousemove = (e) => {
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) {
selfCursor.rawSetPosInit(currentMouseX / clientWidth, currentMouseY);
selfCursor.updateCursor();
@ -456,8 +464,9 @@ kbd {
}
window.onscroll = () => {
bodyBoundingRect = document.body.getBoundingClientRect();
currentMouseX = rawMouseX + window.scrollX;
currentMouseY = rawMouseY + window.scrollY;
currentMouseY = rawMouseY + window.scrollY + ((window.scrollY + bodyBoundingRect.top) - bodyMarginTop);
if (selfCursor) {
selfCursor.rawSetPosInit(currentMouseX / clientWidth, currentMouseY);
selfCursor.updateCursor();
@ -475,7 +484,7 @@ kbd {
if (ws && ready) {
if (allowedPings > 0) {
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") {