mirror of
https://github.com/FlamedDogo99/EaglerMobile.git
synced 2024-11-21 11:36:05 -08:00
Unethically unsafe tampermonkey hack
This is horrible and its only to test a check on Android This will be changed to simply injecting the script, I hope
This commit is contained in:
parent
2a04b33729
commit
dc446b3176
|
@ -6,7 +6,7 @@
|
||||||
// @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js
|
// @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js
|
||||||
// @license Apache License 2.0 - http://www.apache.org/licenses/
|
// @license Apache License 2.0 - http://www.apache.org/licenses/
|
||||||
// @match https://eaglercraft.com/mc/*
|
// @match https://eaglercraft.com/mc/*
|
||||||
// @version 3.0.3-alpha-4
|
// @version 3.0.3-alpha-5
|
||||||
// @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js
|
// @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js
|
||||||
// @run-at document-start
|
// @run-at document-start
|
||||||
// @grant unsafeWindow
|
// @grant unsafeWindow
|
||||||
|
@ -14,11 +14,19 @@
|
||||||
|
|
||||||
// THIS IS LAZY AND CAN EXPOSE INTERNALS
|
// THIS IS LAZY AND CAN EXPOSE INTERNALS
|
||||||
// IN THE FUTURE, JUST INJECT A SCRIPT TAG
|
// IN THE FUTURE, JUST INJECT A SCRIPT TAG
|
||||||
|
//try {
|
||||||
|
//var window = unsafeWindow ?? window
|
||||||
|
//} catch {
|
||||||
|
//
|
||||||
|
//}
|
||||||
try {
|
try {
|
||||||
window = unsafeWindow ?? window
|
if(unsafeWindow) {
|
||||||
|
console.log("UNSAFE WINDOW RAGGHHH")
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
Object.defineProperty(window, "unsafeWindow", {
|
||||||
|
value: window
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMobile() {
|
function isMobile() {
|
||||||
|
@ -32,10 +40,11 @@ function isMobile() {
|
||||||
if(!isMobile()) {
|
if(!isMobile()) {
|
||||||
alert("WARNING: This script was created for mobile, and may break functionality in non-mobile browsers!");
|
alert("WARNING: This script was created for mobile, and may break functionality in non-mobile browsers!");
|
||||||
}
|
}
|
||||||
window.keyboardEnabled = false;
|
|
||||||
window.crouchLock = false;
|
unsafeWindow.keyboardEnabled = false;
|
||||||
window.sprintLock = false;
|
unsafeWindow.crouchLock = false;
|
||||||
window.keyboardFix = false; // temporarily set to true until I can figure out whats going wrong with the event listener in charge of switching it
|
unsafeWindow.sprintLock = false;
|
||||||
|
unsafeWindow.keyboardFix = false; // temporarily set to true until I can figure out whats going wrong with the event listener in charge of switching it
|
||||||
// Used for changing touchmove events to mousemove events
|
// Used for changing touchmove events to mousemove events
|
||||||
var previousTouchX = null;
|
var previousTouchX = null;
|
||||||
var previousTouchY = null;
|
var previousTouchY = null;
|
||||||
|
@ -45,10 +54,10 @@ function logManager() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.init = function () {
|
self.init = function () {
|
||||||
console.log('logmanager initialized');
|
unsafeWindow.console.log('logmanager initialized');
|
||||||
var old = console.log;
|
var old = unsafeWindow.console.log;
|
||||||
self.logger = document.getElementById('log');
|
self.logger = document.getElementById('log');
|
||||||
console.log = function (message, options) {
|
unsafeWindow.console.log = function (message, options) {
|
||||||
if (typeof message == 'object') {
|
if (typeof message == 'object') {
|
||||||
self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />' + self.logger.innerHTML;
|
self.logger.innerHTML = (JSON && JSON.stringify ? JSON.stringify(message) : message) + '<br />' + self.logger.innerHTML;
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,7 +83,7 @@ Object.defineProperty(EventTarget.prototype, "addEventListener", {
|
||||||
value: function (type, fn, ...rest) {
|
value: function (type, fn, ...rest) {
|
||||||
if(type == 'keydown') {
|
if(type == 'keydown') {
|
||||||
_addEventListener.call(this, type, function(...args) {
|
_addEventListener.call(this, type, function(...args) {
|
||||||
if(!args[0].isValid && window.keyboardFix) {
|
if(!args[0].isValid && unsafeWindow.keyboardFix) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return fn.apply(this, args);
|
return fn.apply(this, args);
|
||||||
|
@ -105,7 +114,7 @@ function keyEvent(name, state) {
|
||||||
which: charCode
|
which: charCode
|
||||||
});
|
});
|
||||||
evt.isValid = true; // Disables fix for bad keyboard input
|
evt.isValid = true; // Disables fix for bad keyboard input
|
||||||
window.dispatchEvent(evt);
|
unsafeWindow.dispatchEvent(evt);
|
||||||
}
|
}
|
||||||
function mouseEvent(number, state, canvas) {
|
function mouseEvent(number, state, canvas) {
|
||||||
canvas.dispatchEvent(new PointerEvent(state, {"button": number}))
|
canvas.dispatchEvent(new PointerEvent(state, {"button": number}))
|
||||||
|
@ -123,11 +132,11 @@ function setButtonVisibility(pointerLocked) {
|
||||||
}
|
}
|
||||||
// POINTERLOCK
|
// POINTERLOCK
|
||||||
// When requestpointerlock is called, this dispatches an event, saves the requested element to window.fakelock, and unhides the touch controls
|
// When requestpointerlock is called, this dispatches an event, saves the requested element to window.fakelock, and unhides the touch controls
|
||||||
window.fakelock = null;
|
unsafeWindow.fakelock = null;
|
||||||
|
|
||||||
Object.defineProperty(Element.prototype, "requestPointerLock", {
|
Object.defineProperty(Element.prototype, "requestPointerLock", {
|
||||||
value: function() {
|
value: function() {
|
||||||
window.fakelock = this
|
unsafeWindow.fakelock = this
|
||||||
document.dispatchEvent(new Event('pointerlockchange'));
|
document.dispatchEvent(new Event('pointerlockchange'));
|
||||||
setButtonVisibility(true);
|
setButtonVisibility(true);
|
||||||
return true
|
return true
|
||||||
|
@ -138,13 +147,13 @@ Object.defineProperty(Element.prototype, "requestPointerLock", {
|
||||||
// Makes pointerLockElement return window.fakelock
|
// Makes pointerLockElement return window.fakelock
|
||||||
Object.defineProperty(Document.prototype, "pointerLockElement", {
|
Object.defineProperty(Document.prototype, "pointerLockElement", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return window.fakelock;
|
return unsafeWindow.fakelock;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// When exitPointerLock is called, this dispatches an event, clears the
|
// When exitPointerLock is called, this dispatches an event, clears the
|
||||||
Object.defineProperty(Document.prototype, "exitPointerLock", {
|
Object.defineProperty(Document.prototype, "exitPointerLock", {
|
||||||
value: function() {
|
value: function() {
|
||||||
window.fakelock = null
|
unsafeWindow.fakelock = null
|
||||||
document.dispatchEvent(new Event('pointerlockchange'));
|
document.dispatchEvent(new Event('pointerlockchange'));
|
||||||
setButtonVisibility(false);
|
setButtonVisibility(false);
|
||||||
return true
|
return true
|
||||||
|
@ -152,23 +161,23 @@ Object.defineProperty(Document.prototype, "exitPointerLock", {
|
||||||
});
|
});
|
||||||
|
|
||||||
// FULLSCREEN
|
// FULLSCREEN
|
||||||
window.fakefull = null;
|
unsafeWindow.fakefull = null;
|
||||||
// Stops the client from crashing when fullscreen is requested
|
// Stops the client from crashing when fullscreen is requested
|
||||||
Object.defineProperty(Element.prototype, "requestFullscreen", {
|
Object.defineProperty(Element.prototype, "requestFullscreen", {
|
||||||
value: function() {
|
value: function() {
|
||||||
window.fakefull = this
|
unsafeWindow.fakefull = this
|
||||||
document.dispatchEvent(new Event('fullscreenchange'));
|
document.dispatchEvent(new Event('fullscreenchange'));
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(document, "fullscreenElement", {
|
Object.defineProperty(document, "fullscreenElement", {
|
||||||
get: function() {
|
get: function() {
|
||||||
return window.fakefull;
|
return unsafeWindow.fakefull;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Object.defineProperty(Document.prototype, "exitFullscreen", {
|
Object.defineProperty(Document.prototype, "exitFullscreen", {
|
||||||
value: function() {
|
value: function() {
|
||||||
window.fakefull = null
|
unsafeWindow.fakefull = null
|
||||||
document.dispatchEvent(new Event('fullscreenchange'));
|
document.dispatchEvent(new Event('fullscreenchange'));
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -188,7 +197,7 @@ document.createElement = function(type, ignore) {
|
||||||
element.hidden = true;
|
element.hidden = true;
|
||||||
element.style.display = "none";
|
element.style.display = "none";
|
||||||
}, {passive: false, once: true});
|
}, {passive: false, once: true});
|
||||||
window.addEventListener('focus', function(e) {
|
unsafeWindow.addEventListener('focus', function(e) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
element.hidden = true;
|
element.hidden = true;
|
||||||
element.style.display = "none";
|
element.style.display = "none";
|
||||||
|
@ -246,11 +255,11 @@ function createTouchButton(buttonClass, buttonDisplay, elementName) {
|
||||||
|
|
||||||
function toggleKeyboard() {
|
function toggleKeyboard() {
|
||||||
const keyboardInput = document.getElementById('hiddenInput');
|
const keyboardInput = document.getElementById('hiddenInput');
|
||||||
if (window.keyboardEnabled) {
|
if (unsafeWindow.keyboardEnabled) {
|
||||||
window.keyboardEnabled = false;
|
unsafeWindow.keyboardEnabled = false;
|
||||||
keyboardInput.blur();
|
keyboardInput.blur();
|
||||||
} else {
|
} else {
|
||||||
window.keyboardEnabled = true;
|
unsafeWindow.keyboardEnabled = true;
|
||||||
keyboardInput.select();
|
keyboardInput.select();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -269,7 +278,7 @@ function insertCanvasElements() {
|
||||||
}
|
}
|
||||||
e.movementX = touch.pageX - previousTouchX;
|
e.movementX = touch.pageX - previousTouchX;
|
||||||
e.movementY = touch.pageY - previousTouchY;
|
e.movementY = touch.pageY - previousTouchY;
|
||||||
var evt = window.fakelock ? new MouseEvent("mousemove", {movementX: e.movementX, movementY: e.movementY}) : new WheelEvent("wheel", {"wheelDeltaY": e.movementY});
|
var evt = unsafeWindow.fakelock ? new MouseEvent("mousemove", {movementX: e.movementX, movementY: e.movementY}) : new WheelEvent("wheel", {"wheelDeltaY": e.movementY});
|
||||||
canvas.dispatchEvent(evt);
|
canvas.dispatchEvent(evt);
|
||||||
previousTouchX = touch.pageX;
|
previousTouchX = touch.pageX;
|
||||||
previousTouchY = touch.pageY;
|
previousTouchY = touch.pageY;
|
||||||
|
@ -280,7 +289,7 @@ function insertCanvasElements() {
|
||||||
previousTouchY = null;
|
previousTouchY = null;
|
||||||
}, false)
|
}, false)
|
||||||
//Updates button visibility on load
|
//Updates button visibility on load
|
||||||
setButtonVisibility(window.fakelock != null);
|
setButtonVisibility(unsafeWindow.fakelock != null);
|
||||||
// Adds all of the touch screen controls
|
// Adds all of the touch screen controls
|
||||||
// Theres probably a better way to do this but this works for now
|
// Theres probably a better way to do this but this works for now
|
||||||
let strafeRightButton = createTouchButton("strafeRightButton", "inGame", "div");
|
let strafeRightButton = createTouchButton("strafeRightButton", "inGame", "div");
|
||||||
|
@ -306,13 +315,13 @@ function insertCanvasElements() {
|
||||||
startTouchX = touch.pageX;
|
startTouchX = touch.pageX;
|
||||||
}
|
}
|
||||||
let movementX = touch.pageX - startTouchX;
|
let movementX = touch.pageX - startTouchX;
|
||||||
if((movementX * 10) > window.innerHeight) {
|
if((movementX * 10) > unsafeWindow.innerHeight) {
|
||||||
strafeRightButton.classList.add("active");
|
strafeRightButton.classList.add("active");
|
||||||
strafeLeftButton.classList.remove("active");
|
strafeLeftButton.classList.remove("active");
|
||||||
keyEvent("d", "keydown");
|
keyEvent("d", "keydown");
|
||||||
keyEvent("a", "keyup");
|
keyEvent("a", "keyup");
|
||||||
|
|
||||||
} else if ((movementX * 10) < (0 - window.innerHeight)) {
|
} else if ((movementX * 10) < (0 - unsafeWindow.innerHeight)) {
|
||||||
strafeLeftButton.classList.add("active");
|
strafeLeftButton.classList.add("active");
|
||||||
strafeRightButton.classList.remove("active");
|
strafeRightButton.classList.remove("active");
|
||||||
keyEvent("a", "keydown");
|
keyEvent("a", "keydown");
|
||||||
|
@ -365,18 +374,18 @@ function insertCanvasElements() {
|
||||||
crouchButton.style.cssText = "left:10vh;bottom:10vh;"
|
crouchButton.style.cssText = "left:10vh;bottom:10vh;"
|
||||||
crouchButton.addEventListener("touchstart", function(e){
|
crouchButton.addEventListener("touchstart", function(e){
|
||||||
keyEvent("shift", "keydown")
|
keyEvent("shift", "keydown")
|
||||||
window.crouchLock = window.crouchLock ? null : false
|
unsafeWindow.crouchLock = unsafeWindow.crouchLock ? null : false
|
||||||
crouchTimer = setTimeout(function(e) {
|
crouchTimer = setTimeout(function(e) {
|
||||||
window.crouchLock = (window.crouchLock != null);
|
unsafeWindow.crouchLock = (unsafeWindow.crouchLock != null);
|
||||||
crouchButton.classList.toggle('active');
|
crouchButton.classList.toggle('active');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
crouchButton.addEventListener("touchend", function(e) {
|
crouchButton.addEventListener("touchend", function(e) {
|
||||||
if(!window.crouchLock) {
|
if(!unsafeWindow.crouchLock) {
|
||||||
keyEvent("shift", "keyup")
|
keyEvent("shift", "keyup")
|
||||||
crouchButton.classList.remove('active');
|
crouchButton.classList.remove('active');
|
||||||
window.crouchLock = false
|
unsafeWindow.crouchLock = false
|
||||||
}
|
}
|
||||||
clearTimeout(crouchTimer);
|
clearTimeout(crouchTimer);
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -404,11 +413,11 @@ function insertCanvasElements() {
|
||||||
hiddenInput.addEventListener("input", function(e) {
|
hiddenInput.addEventListener("input", function(e) {
|
||||||
e.preventDefault(true);
|
e.preventDefault(true);
|
||||||
let inputData = e.data == null ? "delete" : e.data.slice(-1);
|
let inputData = e.data == null ? "delete" : e.data.slice(-1);
|
||||||
console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`);
|
unsafeWindow.console.log(`Received input by ${e.inputType}: ${e.data} -> ${inputData}`);
|
||||||
|
|
||||||
window.lastKey = inputData
|
unsafeWindow.lastKey = inputData
|
||||||
hiddenInput.value = " "; // We need a character to detect deleting
|
hiddenInput.value = " "; // We need a character to detect deleting
|
||||||
if(window.keyboardFix) {
|
if(unsafeWindow.keyboardFix) {
|
||||||
const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof
|
const sliceInputType = e.inputType.slice(0,1); // This is a really dumb way to do this because it's not future-proof
|
||||||
if(sliceInputType== 'i') {
|
if(sliceInputType== 'i') {
|
||||||
let isShift = (inputData.toLowerCase() != inputData);
|
let isShift = (inputData.toLowerCase() != inputData);
|
||||||
|
@ -428,12 +437,12 @@ function insertCanvasElements() {
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
hiddenInput.addEventListener("keydown", function(e) {
|
hiddenInput.addEventListener("keydown", function(e) {
|
||||||
if(!(e.key && e.keyCode && e.which) && !window.keyboardFix) {
|
if(!(e.key && e.keyCode && e.which) && !unsafeWindow.keyboardFix) {
|
||||||
console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.")
|
unsafeWindow.console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.")
|
||||||
window.keyboardFix = true;
|
unsafeWindow.keyboardFix = true;
|
||||||
if(window.lastKey) {
|
if(unsafeWindow.lastKey) {
|
||||||
keyEvent(window.lastKey, "keydown");
|
keyEvent(unsafeWindow.lastKey, "keydown");
|
||||||
keyEvent(window.lastKey, "keyup");
|
keyEvent(unsafeWindow.lastKey, "keyup");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
@ -475,18 +484,18 @@ function insertCanvasElements() {
|
||||||
sprintButton.style.cssText = "right:0vh;bottom:10vh;"
|
sprintButton.style.cssText = "right:0vh;bottom:10vh;"
|
||||||
sprintButton.addEventListener("touchstart", function(e) {
|
sprintButton.addEventListener("touchstart", function(e) {
|
||||||
keyEvent("r", "keydown");
|
keyEvent("r", "keydown");
|
||||||
window.sprintLock = window.sprintLock ? null : false
|
unsafeWindow.sprintLock = unsafeWindow.sprintLock ? null : false
|
||||||
sprintTimer = setTimeout(function(e) {
|
sprintTimer = setTimeout(function(e) {
|
||||||
window.sprintLock = (window.sprintLock != null);
|
unsafeWindow.sprintLock = (unsafeWindow.sprintLock != null);
|
||||||
sprintButton.classList.toggle('active');
|
sprintButton.classList.toggle('active');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
sprintButton.addEventListener("touchend", function(e) {
|
sprintButton.addEventListener("touchend", function(e) {
|
||||||
if(!window.sprintLock) {
|
if(!unsafeWindow.sprintLock) {
|
||||||
keyEvent("r", "keyup");
|
keyEvent("r", "keyup");
|
||||||
sprintButton.classList.remove('active');
|
sprintButton.classList.remove('active');
|
||||||
window.sprintLock = false
|
unsafeWindow.sprintLock = false
|
||||||
}
|
}
|
||||||
clearTimeout(sprintTimer);
|
clearTimeout(sprintTimer);
|
||||||
}, false);
|
}, false);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user