Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/toobeeh/skribbltypo into…
Browse files Browse the repository at this point in the history
… develop
  • Loading branch information
toobeeh committed Dec 15, 2023
2 parents 904bb4a + adfb5d1 commit 7a258e1
Showing 1 changed file with 73 additions and 22 deletions.
95 changes: 73 additions & 22 deletions skribbltypo.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @author tobeh#7437
// @description Userscript version of skribbltypo - the most advanced toolbox for skribbl.io
// @icon64 https://rawcdn.githack.com/toobeeh/skribbltypo/master/res/icon/128MaxFit.png
// @version 25.0.4.170205777
// @version 25.0.5.170239597
// @updateURL https://raw.githubusercontent.com/toobeeh/skribbltypo/master/skribbltypo.user.js
// @grant none
// @match https://skribbl.io/*
Expand All @@ -24,7 +24,7 @@ const chrome = {
return "https://rawcdn.githack.com/toobeeh/skribbltypo/master/" + url;
},
getManifest: () => {
return {version: "25.0.4 usrsc"};
return {version: "25.0.5 usrsc"};
},
onMessage: {
addListener: (callback) => {
Expand Down Expand Up @@ -1082,6 +1082,11 @@ const getCurrentOrLastDrawer = () => {
return drawer;
}

// check if the player is currently drawing
const isCurrentlyDrawing = () => {
return QS(".avatar .drawing[style*=block]").closest(".player").querySelector(".player-name")?.textContent.includes("(You)") ?? false;
}

const getCurrentWordOrHint = () => {
if (QS("#game-word .description").textContent.includes("DRAW")) {
// get whole word
Expand Down Expand Up @@ -6067,6 +6072,23 @@ const commands = [
return "Tablet pressure sensitivity is now at " + args + "%.";
}
}
}, {
command: "login",
options: {
type: "action",
description: "Logs in with a given palantir access token. Argument: token (empty to log out)",
actionBefore: null,
actionEnable: null,
actionDisable: null,
actionAfter: (args) => {
if (!args || args.length == 0) localStorage.removeItem("accessToken");
else localStorage.setItem("accessToken", args);
},
response: (args) => {
window.location.reload();
return "Reloading...";
}
}
}, {
command: "usepalette",
options: {
Expand Down Expand Up @@ -6160,6 +6182,22 @@ const commands = [
return "";
}
}
}, {
command: "reconnect",
options: {
type: "action",
description: "Reconnects to the typo server.",
actionBefore: null,
actionEnable: null,
actionDisable: null,
actionAfter: () => {
socket.disconnect();
setTimeout(() => socket.init(), 2000);
},
response: (args) => {
return "Reconnection initiated.";
}
}
}, {
command: "newvision",
options: {
Expand Down Expand Up @@ -6386,17 +6424,20 @@ const uiTweaks = {
canvasGame.setAttribute("data-zoom", 1);
canvasGame.parentElement.style.height = "";
canvasGame.parentElement.style.width = "";
canvasGame.parentElement.style.boxShadow = "";
//canvasGame.parentElement.style.boxShadow = "";
canvasGame.style.width = "100%";
canvasGame.style.top = "";
canvasGame.style.left = "";
document.removeEventListener("keydown", changeZoom);
[...QSA(".zoomNote")].forEach(n => n.remove());
zoomActive = false;
// document.querySelector(".size-picker .slider").dispatchEvent(new MouseEvent("mousedown", { button: 0 }));
}
let toggleZoom = (event, skipctrl = false) => {
if (!isCurrentlyDrawing()) return;
if ((event.ctrlKey || skipctrl) && localStorage.zoomdraw == "true") {
event.preventDefault();
event.stopPropagation();
if (skipctrl || !zoomActive && !QS("#game-toolbar").classList.contains("hidden")) {
zoomActive = true;
const zoom = Number(sessionStorage.zoom) > 1 ? Number(sessionStorage.zoom) : 3;
Expand All @@ -6407,7 +6448,10 @@ const uiTweaks = {
let bRect = canvasGame.getBoundingClientRect();
canvasGame.parentElement.style.height = /* bRect.height + */ "600px";
canvasGame.parentElement.style.width = /* bRect.width + */ "800px";
canvasGame.parentElement.style.boxShadow = "black 0px 0px 25px 5px";
if (!QS(".zoomNote")) {
QS("#game-word .description").insertAdjacentHTML("beforeend", "<span class='zoomNote'> (ZOOM MODE ACTIVE)</span>");
}
//canvasGame.parentElement.style.boxShadow = "black 0px 0px 25px 5px";
// zoom canvas
canvasGame.style.width = (zoom * 100) + "%";
// get position offset
Expand All @@ -6422,14 +6466,21 @@ const uiTweaks = {
}
}
document.addEventListener("keydown", changeZoom);

// undo brush action glitch
//document.addEventListener("pointerup", () => setTimeout(() => QS("[data-tooltip=Undo]").click(), 100), { once: true });
}
else {
uiTweaks.resetZoom();
}
}
}
document.addEventListener("pointerdown", toggleZoom);
document.querySelector("body").addEventListener("logCanvasClear", (e) => { if (zoomActive) toggleZoom(e, true); });
document.addEventListener("logCanvasClear", (e) => { uiTweaks.resetZoom(); });

// disable pointer events when ctrl pressed
document.addEventListener("keydown", (e) => canvasGame.style.pointerEvents = e.ctrlKey ? "none" : "");
document.addEventListener("keyup", (e) => canvasGame.style.pointerEvents = e.ctrlKey ? "none" : "");
},
initColorPalettes: () => {
// add color palettes
Expand Down Expand Up @@ -6816,10 +6867,15 @@ const uiTweaks = {
preview.clear();
preview.gameCanvas.insertAdjacentElement("afterend", preview.canvas);
preview.gameCanvas.style.pointerEvents = "none";

if (!QS(".slNote")) {
QS("#game-word .description").insertAdjacentHTML("beforeend", "<span class='slNote'> (STRAIGHT MODE ACTIVE)</span>");
}
},
stop: () => {
preview.canvas.remove();
preview.gameCanvas.style.pointerEvents = "";
QS(".slNote")?.remove();
},
clear: () => preview.context().clearRect(0, 0, 800, 600),
line: (x, y, x1, y1, color = "black", size = 5) => {
Expand Down Expand Up @@ -6868,17 +6924,10 @@ const uiTweaks = {
let state = straight;
straight = straight && event.which !== 16;
snap = straight && snap;
if (!straight && !pointerdown) preview.stop();
if (!straight/* && !pointerdown */) preview.stop();
if (!straight && state) lastRelease = Date.now();
if (!straight) lastDirectClient = [null, null];
});
document.addEventListener("keyup", (event) => {
let state = straight;
straight = straight && event.which !== 16;
snap = straight && snap;
if (!straight && !pointerdown) preview.stop();
if (!straight && state) lastRelease = Date.now();
});
// get snap end coordinates
const snapDestination = (x, y, x1, y1) => {
let dx = Math.abs(x - x1);
Expand All @@ -6895,11 +6944,12 @@ const uiTweaks = {
lastDown = getRealCoordinates(event.offsetX, event.offsetY);
}
});
preview.canvas.addEventListener("pointerup", (event) => {
event.preventDefault();
event.stopPropagation();
document.addEventListener("pointerup", (event) => {
pointerdown = false;
if (straight) {
// check for event target to filter out generated events that are used for actual drawing
if (straight && event.target !== preview.gameCanvas) {
event.preventDefault();
event.stopPropagation();
preview.clear();
lastDown = [null, null];
let dest = [event.clientX, event.clientY];
Expand All @@ -6909,10 +6959,11 @@ const uiTweaks = {
preview.gameCanvas.dispatchEvent(pointerEvent("pointerup", dest[0], dest[1]));
}
});
preview.canvas.addEventListener("pointermove", (event) => {
event.preventDefault();
event.stopPropagation();
if (straight) {
document.addEventListener("pointermove", (event) => {
// update preview only if cursor moved on preview
if (straight && event.target == preview.canvas) {
event.preventDefault();
event.stopPropagation();
const col = QS("#color-preview-primary").style.fill;
const size = [4, 14, 30, 40][[...QSA(".size")].findIndex(size => size.classList.contains("selected"))]
if (lastDown[0]) {
Expand Down Expand Up @@ -7383,7 +7434,7 @@ let typro = {
let removeConfirm = false;
remove.addEventListener("click", async () => {
if (!removeConfirm) { remove.innerHTML = "Really?"; removeConfirm = true; return; }
await socket.emitEvent("remove drawing", { id: drawing.id });
await socket.emitEvent("remove drawing", { id: drawing.uuid });
new Toast("Deleted drawing from the cloud.");
container.remove();
});
Expand Down

0 comments on commit 7a258e1

Please sign in to comment.