mirror of
https://github.com/FlamedDogo99/EaglerMobile.git
synced 2024-11-21 19:46:05 -08:00
Updated ef.js from userscript
This commit is contained in:
parent
4846e06d0f
commit
cfe71e135c
|
@ -1,17 +1,3 @@
|
||||||
// ==UserScript==
|
|
||||||
// @name Eagler Mobile
|
|
||||||
// @description Allows eaglercraft to run on mobile, adds touch controls, and fixes a few mobile-related crashes
|
|
||||||
// @author FlamedDogo99
|
|
||||||
// @namespace http://github.com/FlamedDogo99
|
|
||||||
// @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js
|
|
||||||
// @license Apache License 2.0 - http://www.apache.org/licenses/
|
|
||||||
// @match https://eaglercraft.com/mc/*
|
|
||||||
// @version 2.12
|
|
||||||
// @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.user.js
|
|
||||||
// @run-at document-start
|
|
||||||
// ==/UserScript==
|
|
||||||
|
|
||||||
|
|
||||||
function isMobile() {
|
function isMobile() {
|
||||||
try {
|
try {
|
||||||
document.createEvent("TouchEvent");
|
document.createEvent("TouchEvent");
|
||||||
|
@ -26,6 +12,7 @@ if(!isMobile()) {
|
||||||
window.keyboardEnabled = false;
|
window.keyboardEnabled = false;
|
||||||
window.crouchLock = false;
|
window.crouchLock = false;
|
||||||
window.sprintLock = false;
|
window.sprintLock = 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
|
||||||
// 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;
|
||||||
|
@ -41,7 +28,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) {
|
if(!args[0].isValid && window.keyboardFix) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return fn.apply(this, args);
|
return fn.apply(this, args);
|
||||||
|
@ -354,7 +341,7 @@ function insertCanvasElements() {
|
||||||
document.body.appendChild(inventoryButton);
|
document.body.appendChild(inventoryButton);
|
||||||
let exitButton = createTouchButton("exitButton", "inMenu");
|
let exitButton = createTouchButton("exitButton", "inMenu");
|
||||||
exitButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right:8vh; width: 8vh; height: 8vh;"
|
exitButton.style.cssText = "top: 0vh; margin: auto; left: 0vh; right:8vh; width: 8vh; height: 8vh;"
|
||||||
exitButton.addEventListener("touchstart", function(e){keyEvent("`", "keyup")}, false);
|
exitButton.addEventListener("touchstart", function(e){keyEvent("`", "keydown")}, false);
|
||||||
exitButton.addEventListener("touchend", function(e){keyEvent("`", "keyup")}, false);
|
exitButton.addEventListener("touchend", function(e){keyEvent("`", "keyup")}, false);
|
||||||
document.body.appendChild(exitButton);
|
document.body.appendChild(exitButton);
|
||||||
// input for keyboard button
|
// input for keyboard button
|
||||||
|
@ -364,10 +351,12 @@ function insertCanvasElements() {
|
||||||
// We are hiding the text input behind button because opacity was causing problems.
|
// We are hiding the text input behind button because opacity was causing problems.
|
||||||
hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;";
|
hiddenInput.style.cssText = "position:absolute;top: 0vh; margin: auto; left: 8vh; right:0vh; width: 8vh; height: 8vh;font-size:20px;z-index:-10;color: transparent;text-shadow: 0 0 0 black;";
|
||||||
hiddenInput.value = " " //Allows delete to be detected before input is changed
|
hiddenInput.value = " " //Allows delete to be detected before input is changed
|
||||||
hiddenInput.addEventListener("input", function(e) {
|
hiddenInput.addEventListener("input", function hiddenInputHandler(e) {
|
||||||
|
let inputData = e.data ?? "delete"; // backspace makes null
|
||||||
|
window.lastKey = inputData
|
||||||
hiddenInput.value = " "; // We need a character to detect deleting
|
hiddenInput.value = " "; // We need a character to detect deleting
|
||||||
|
if(window.keyboardFix) {
|
||||||
if(e.inputType == 'insertText') {
|
if(e.inputType == 'insertText') {
|
||||||
let inputData = e.data.charAt(0);
|
|
||||||
let isShift = (inputData.toLowerCase() != inputData);
|
let isShift = (inputData.toLowerCase() != inputData);
|
||||||
if(isShift) {
|
if(isShift) {
|
||||||
keyEvent("shift", "keydown")
|
keyEvent("shift", "keydown")
|
||||||
|
@ -382,6 +371,17 @@ function insertCanvasElements() {
|
||||||
keyEvent("backspace", "keydown")
|
keyEvent("backspace", "keydown")
|
||||||
keyEvent("backspace", "keyup")
|
keyEvent("backspace", "keyup")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}, false);
|
||||||
|
hiddenInput.addEventListener("keydown", function(e) {
|
||||||
|
if(!(e.key && e.keyCode && e.which) && !window.keyboardFix) {
|
||||||
|
console.warn("Switching from keydown to input events due to invalid KeyboardEvent. Some functionality will be lost.")
|
||||||
|
window.keyboardFix = true;
|
||||||
|
if(window.lastKey) {
|
||||||
|
keyEvent(window.lastKey, "keydown")
|
||||||
|
keyEvent(window.lastKey, "keyup")
|
||||||
|
}
|
||||||
|
}
|
||||||
}, false);
|
}, false);
|
||||||
document.body.appendChild(hiddenInput);
|
document.body.appendChild(hiddenInput);
|
||||||
let keyboardButton = createTouchButton("keyboardButton", "inMenu");
|
let keyboardButton = createTouchButton("keyboardButton", "inMenu");
|
||||||
|
|
|
@ -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 2.19
|
// @version 3.0.1
|
||||||
// @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
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
Loading…
Reference in New Issue
Block a user