2024-05-26 14:17:04 -07:00
// ==UserScript==
2024-05-26 15:03:18 -07:00
// @name Eagler Mobile
// @description Allows eaglercraft to run on mobile, adds touch controls, and fixes a few mobile-related crashes
2024-05-26 14:17:04 -07:00
// @author FlamedDogo99
2024-05-26 15:03:18 -07:00
// @namespace http://github.com/FlamedDogo99
2024-05-26 14:17:04 -07:00
// @downloadURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.js
2024-05-26 15:03:18 -07:00
// @license Apache License 2.0 - http://www.apache.org/licenses/
2024-05-26 14:17:04 -07:00
// @match https://eaglercraft.com/mc/*
2024-05-26 15:03:18 -07:00
// @grant none
// @version 1.1
2024-05-26 14:17:04 -07:00
// @updateURL https://raw.githubusercontent.com/FlamedDogo99/EaglerMobile/main/eaglermobile.js
// @run-at document-start
// ==/UserScript==
// Hides inventory button
window . inInventory = false ;
// Used for changing touchmove events to mousemove events
var previousX = null ;
var previousY = null ;
// Key and mouse events
function keyEvent ( name , state ) {
const keyName = name . toUpperCase ( ) . charCodeAt ( 0 )
window . dispatchEvent ( new KeyboardEvent ( state , {
key : name ,
keyCode : keyName ,
which : keyName
} ) ) ;
}
function shiftKey ( state ) {
window . dispatchEvent ( new KeyboardEvent ( state , {
keyCode : 16 ,
which : 16
} ) ) ;
}
function mouseEvent ( number , state , canvas ) {
canvas . dispatchEvent ( new PointerEvent ( state , { "button" : number } ) )
}
// POINTERLOCK
// When requestpointerlock is called, this dispatches an event, saves the requested element to window.fakelock, and unhides the touch controls
window . fakelock = null ;
Element . prototype . requestPointerLock = function ( ) {
window . fakelock = this
document . dispatchEvent ( new Event ( 'pointerlockchange' ) ) ;
console . log ( "requested pointerlock" )
var hideButtonStyleDOM = document . getElementById ( 'hideButtonStyle' ) ;
var hideInventoryStyleDOM = document . getElementById ( 'hideInventoryStyle' ) ;
hideButtonStyleDOM . disabled = true ;
hideInventoryStyleDOM . disabled = true ;
return true
}
// Makes pointerLockElement return window.fakelock
Object . defineProperty ( document , "pointerLockElement" , {
get : function ( ) {
return window . fakelock ;
}
} ) ;
// When exitPointerLock is called, this dispatches an event, clears the
document . exitPointerLock = function ( ) {
window . fakelock = null
document . dispatchEvent ( new Event ( 'pointerlockchange' ) ) ;
var hideButtonStyleDOM = document . getElementById ( 'hideButtonStyle' ) ;
var hideInventoryStyleDOM = document . getElementById ( 'hideInventoryStyle' ) ;
hideButtonStyleDOM . disabled = false ;
hideInventoryStyleDOM . disabled = window . inInventory ;
return true
}
// FULLSCREEN
window . fakefull = null ;
// Stops the client from crashing when fullscreen is requested
Element . prototype . requestFullscreen = function ( ) {
window . fakefull = this
document . dispatchEvent ( new Event ( 'fullscreenchange' ) ) ;
return true
}
Object . defineProperty ( document , "fullscreenElement" , {
get : function ( ) {
return window . fakefull ;
}
} ) ;
document . exitFullscreen = function ( ) {
window . fakefull = null
document . dispatchEvent ( new Event ( 'fullscreenchange' ) ) ;
return true
}
// FILE UPLOADING
// Safari doesn't recognize the element.click() used to display the file uplaoder as an action performed by the user, so it ignores it.
// This hijacks the element.createElement() function to add the file upload to the DOM, so the user can manually press the button again.
var oldCreate = document . createElement ;
document . createElement = function ( type ) {
this . oldCreate = oldCreate ;
var element = this . oldCreate ( type ) ;
if ( type == "input" ) {
var newElement = document . querySelector ( 'input' ) ;
if ( ! newElement ) {
this . body . appendChild ( element ) ;
newElement = document . querySelector ( 'input' ) ;
newElement . addEventListener ( 'change' , function ( e ) {
this . hidden = true ;
} )
}
newElement . value = null ;
newElement . style . cssText = "position:absolute;left:0%;right:100%;top:0%;bottom:100%;width:100%;height:100%;background-color:rgba(255,255,255,0.5);" ;
newElement . hidden = false ;
return newElement ;
}
return this . oldCreate ( type ) ;
}
// CSS for touch screen buttons, along with fixing iOS's issues with 100vh ignoring the naviagtion bar, and actually disabling zoom because safari ignores user-scalable=no :(
let customStyle = document . createElement ( "style" ) ;
customStyle . textContent = `
button {
position : absolute ;
width : 9.5 vh ;
height : 9.5 vh ;
font - size : 4 vh ;
- webkit - user - select : none ;
- ms - user - select : none ;
user - select : none ;
line - height : 0 px ;
padding : 0 px ;
color : # ffffff ;
text - shadow : 0.35 vh 0.35 vh # 000000 ;
box - sizing : content - box ;
image - rendering : pixelated ;
background : url ( data : image / png ; base64 , iVBORw0KGgoAAAANSUhEUgAAAAIAAAAUCAYAAACnOeyiAAAABGdBTUEAALGPC / xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAAACoAMABAAAAAEAAAAUAAAAABBl8JYAAAIvaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI + CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI + CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI + CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4yMDwvZXhpZjpQaXhlbFlEaW1lbnNpb24 + CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yPC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6Q29sb3JTcGFjZT4xPC9leGlmOkNvbG9yU3BhY2U + CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24 + CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY + CjwveDp4bXBtZXRhPgp + x0mNAAAAU0lEQVQIHV2OXQoAIAiDdSIdt0N3iAiMfhz00IPzw01URWSdEtRabxe01ghmRlgrIwJ352TOSUg9ggdjDFqlFAJAF733z3pbqvqF34mISOsG8o8N3G8YG4Y + w98AAAAASUVORK5CYII = ) no - repeat right center , url ( data : image / png ; base64 , iVBORw0KGgoAAAANSUhEUgAAAMgAAAAUCAYAAADIpHLKAAAABGdBTUEAALGPC / xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAADIoAMABAAAAAEAAAAUAAAAAMWDgdMAAAIxaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI + CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI + CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI + CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4yMDwvZXhpZjpQaXhlbFlEaW1lbnNpb24 + CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yMDA8L2V4aWY6UGl4ZWxYRGltZW5zaW9uPgogICAgICAgICA8ZXhpZjpDb2xvclNwYWNlPjE8L2V4aWY6Q29sb3JTcGFjZT4KICAgICAgICAgPHRpZmY6T3JpZW50YXRpb24 + MTwvdGlmZjpPcmllbnRhdGlvbj4KICAgICAgPC9yZGY6RGVzY3JpcHRpb24 + CiAgIDwvcmRmOlJERj4KPC94OnhtcG1ldGE + CuGU9JQAAA1TSURBVGgF7dlZjlTLDoXhLPpu8kyDefDEQJB4QUL0fX5R + W98guKMoCztjAh7eXnZsTOLe + 7 V6XT6dX5u7XYCtxO4YQL3 + F68ePFX6MePH8t39 + 7 dv2I5rq6uTr9 + / f f 7 l a / 1 5 8 + f C + P M 7 t y 5 s 1 b + 9 h z 7 e Y E u H 8 W s b O Z d I H 8 t M O E L 6 m n X M W O z 1 5 v y Y a u N G 5 / + + T z x h 4 H P Z 8 / E 6 u f a 8 + / P Z v h v x J 9 I v d 5 U u 5 q 0 1 v + 9 e + v q T 9 + / f z / 0 t 4 8 V l s 8 6 O Z q T m p 4 4 9 Y o 3 D X u f 8 y w H n s U d V / z p g N t 9 x c r F t 7 + L Y f B 6 b u o 5 z L 6 + f P n y 9 P z 5 8 9 P 1 l M 5 R j p t M U e T 3 7 9 8 / f f v 2 7 U a h i S y / x h t Y 4 h O 4 8 / C r w d 9 w G 0 r D p 4 O v R s O p y d e 5 W u G f P H m y L h m G i a v n 4 m F m f / a s 3 C 5 l 8 r e 3 4 o D B Z z 7 s 6 9 e v x 5 c C j 7 i a t H v o j N c + X f b w z a B + F u n 2 k Q a 8 u D 5 9 + r Q 0 2 M c n p T 1 e T z r r H a Y e c K X B v l y Y j B + P P u y Z H L 3 j Y Q 8 e P F g 9 l K 9 m e D 5 P v e F i D x 8 + X H P T e 3 N c g f N H d e S 1 7 / 7 C W P l Y O u z x 0 y M P d / X E G D 9 f v G q b J Y 4 3 b 9 4 s z P E F A d R I h U S J c k Z g 3 8 U 6 8 y v K 7 6 V w 1 r i Y h h V R U J z F Y R 9 P / p p q c H T I o w l X e + d H j x 4 d n P J Z e W q o S Q 8 s e / / + / Y o 7 i 6 t N N 8 O 7 6 1 y B 8 4 d + Y L 9 8 + b I 0 0 I S D v 9 7 V 9 d B o s H j l 1 B 9 + + T S p H V 4 N X O m A F 1 P D h c q D x w v X l 0 4 8 b D p x N C O 9 y M V B o 7 z d q p k f n x z 1 6 6 / 7 g O H L n 6 7 H j x + v u c G p w Y 8 H T r / O 6 t B g P 2 e G U 0 w 9 Z o 3 D n J z l M K t z 9 6 q e R x 0 + F j 7 N / P N L u v e 7 k i 4 f e M r n o k M f r H V 9 Q Q i Z I h J V g y v j 8 g G L 2 O r p B a p Q l w j u p V G o x u 1 7 0 e L E x a w e l 9 0 Q + N V g t K h R E w 0 o P X L U S Z u z e o b F B 1 + s / q z i D A 9 t 1 b G P I + 5 q 0 m D w D b E v A Z 7 Z H 8 5 y r P A 0 s H n G P z W K O 3 / + / H n x 0 d l T L p 3 y + N P B p 7 6 6 v X T l 0 a s m X r 5 d V z V 7 o X D h Y D j j i Z u f z / y s N N S H c 3 c O p 2 b 9 z b p w m T 3 u 3 p n u o T 7 N G M a Z h W / G 6 v X l t K o D 0 / s i h 8 b y 9 G n v f Y N n u J s 5 v c v n A z B T C G l C + I k w J L 6 J R d 5 L W e M z 7 p e m f A X x G G K + t T l / G L K n C 8 9 v L S 8 f f r V w a V J 9 5 3 x W O T U o z 2 A a Z C 8 T n H 5 w i M H j Y s 5 M f / q W Y 2 9 4 6 W / Y 1 S 2 H P j n 8 M H O O c q u / C p w / w u 2 8 4 n j 8 x a S R v j T X i z P M h w 8 f F h 3 u y U + L P P c J 2 + x g c K R Z s r 2 4 l R a r n P L 0 w d 9 c x a t l 3 0 M r b D H c c n r B z T h d Y q w + r L 0 z 1 5 E / / 2 S K D 9 f U W S 5 t / C w t z u J y p m 4 Y f H I + f v x 4 Y M x J D o 2 9 C + v r O B t H N C + 1 g n y K T T M M F y S W A P E E 8 R O r K J w h E c a f A H F 4 X M y Z y Y H t 5 Y B R n 7 + 4 Y c 6 6 N S d H r r O m w 5 f r r I 7 h w H o J 4 T M 4 v H L 5 1 f U S p o F + e X o S z y 9 f r i + T m T Z X c X 5 5 0 5 p N f e H L + P S n D n M W r 6 Z Z 2 v O b p Z X h t F f T Q 9 + s y 0 f X N P h + o O D r C R e s f L X 0 F S 8 / H 4 x 4 v c A w u u c d w z d X W D 8 2 a q p V T / L g 0 g 2 f 8 d F Z b / z i c q 3 y 1 J s 5 9 v B q q B e H 3 P S m E y 4 8 H F 6 2 b q w B J h S w Q s A K e 7 w w C U p s u Y v t 8 k E Q A T 2 J a H h y G 5 g U n C 7 c w H o p 1 Z c P 6 3 9 o 4 6 B l m j i D 8 Z L T 0 h e C H y 9 f / V Q X D 1 + 8 9 U R T O u T 1 o q v N 5 N M I z / T J + G + y f v 3 F 0 k 5 z f P u v Z X z h 6 4 V W + e m p b z i x a c 7 0 0 N / L x u d M u x + F m S + 3 u d g 3 C 3 t 5 8 c O Y z b Q Z t 6 9 u H O o 0 a 7 V h + L x L 9 U o X f P N x x i P O b 9 U H H 2 u N V z x 8 / c K l G 4 5 / 8 j o X p 4 v B 0 c Z f j P / 4 S S t o d T G a S
background - size : contain , cover ;
outline : none ;
box - shadow : none ;
border : none ;
}
button : active {
position : absolute ;
width : 9.5 vh ;
height : 9.5 vh ;
font - size : 4 vh ;
- webkit - user - select : none ;
- ms - user - select : none ;
user - select : none ;
line - height : 0 px ;
padding : 0 px ;
color : # ffffff ;
text - shadow : 0.35 vh 0.35 vh # 000000 ;
box - sizing : content - box ;
image - rendering : pixelated ;
background : url ( data : image / png ; base64 , iVBORw0KGgoAAAANSUhEUgAAAAIAAAAUCAYAAACnOeyiAAAABGdBTUEAALGPC / xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAwAAAAEAAQAAoAIABAAAAAEAAAACoAMABAAAAAEAAAAUAAAAABBl8JYAAAIvaVRYdFhNTDpjb20uYWRvYmUueG1wAAAAAAA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJYTVAgQ29yZSA2LjAuMCI + CiAgIDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI + CiAgICAgIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiCiAgICAgICAgICAgIHhtbG5zOmV4aWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20vZXhpZi8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyI + CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4yMDwvZXhpZjpQaXhlbFlEaW1lbnNpb24 + CiAgICAgICAgIDxleGlmOlBpeGVsWERpbWVuc2lvbj4yPC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6Q29sb3JTcGFjZT4xPC9leGlmOkNvbG9yU3BhY2U + CiAgICAgICAgIDx0aWZmOk9yaWVudGF0aW9uPjE8L3RpZmY6T3JpZW50YXRpb24 + CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY + CjwveDp4bXBtZXRhPgp + x0mNAAAAWUlEQVQIHV2OUQrAMAhDNaX01vverXYPL1IES9ca1o99GB8moioic5Xgup / dBWZGKKUQ5syIoNbKyRiDkLoEB9ydVmuNANBF7 / 1 nnS1VpXWORgQnH + xA / vECGrAYeIZg8CAAAAAASUVORK5CYII = ) no - repeat right center , url ( data : image / png ; base64 , iVBORw0KGgoAAAANSUhEUgAAAMgAAAAUCAYAAADIpHLKAAAABGdBTUEAALGPC / xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAUGVYSWZNTQAqAAAACAACARIAAwAAAAEAAQAAh2kABAAAAAEAAAAmAAAAAAADoAEAAw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svPDgX9Nzm94dk4fHvGN90LrRWqMjjE+CL7Flqf6Nf7VWNQw8pENzTUZjGuYiEcFuwBlDgAABEkZWyy6GaxUDWY+5KeIRcHsXd1BCB/iWYhIpMsfMb7ZnBWhqzF2XEQNEFD+I+bZG8uicA1rN+RxAccGUTDQ00CkTgdhGiL+g316zScbm8Bd7ZaKReAQs+NqyDE8ipKdTGFwFhErxcoYTMay04Zj83BoQHZ4iG7nKb5Naj/78mU73MGkCSLyZqeeuXvB6xzvqQH9NJqj5tnvu/7NWd9N5ZXGgS2PimzCY2oidkSsaYPDYCyiFrAYT89k7sh35yU+3+KLqXcd8WYc3uCRJ99isUvv8U2X3fX1dtiYv75+HnXVB6tVb5xjgfgi1ol346aoHBMFMSb4VASQgLm271nnQCqWo8SBszqNnZ93IfmTqDiK4jpFk8DZ2Xw0joXFp3m+iHm3+oxb
background - size : contain , cover ;
outline : none ;
box - shadow : none ;
border : none ;
}
html , body {
height : - webkit - fill - available ! important ;
touch - action : pan - x pan - y ;
}
` ;
document . documentElement . appendChild ( customStyle ) ;
// Lazy way to hide touch controls through CSS.
let hideButtonStyle = document . createElement ( "style" ) ;
hideButtonStyle . id = "hideButtonStyle" ;
hideButtonStyle . textContent = `
# hideButton {
display : none ;
} ` ;
document . documentElement . appendChild ( hideButtonStyle ) ;
let hideInventoryStyle = document . createElement ( "style" ) ;
hideInventoryStyle . id = "hideInventoryStyle" ;
hideInventoryStyle . textContent = `
# hideInventory {
display : none ;
} ` ;
document . documentElement . appendChild ( hideInventoryStyle ) ;
// The canvas is created by the client after it finishes unzipping and loading. When the canvas is created, this applies any necessary event listeners
function waitForElm ( selector ) {
return new Promise ( resolve => {
if ( document . querySelector ( selector ) ) {
return resolve ( document . querySelector ( selector ) ) ;
}
const observer = new MutationObserver ( mutations => {
if ( document . querySelector ( selector ) ) {
observer . disconnect ( ) ;
resolve ( document . querySelector ( selector ) ) ;
}
} ) ;
observer . observe ( document . documentElement , {
childList : true ,
subtree : true
} ) ;
} ) ;
}
waitForElm ( 'canvas' ) . then ( ( ) => { insertCanvasElements ( ) } ) ;
function insertCanvasElements ( ) {
// Translates touchmove events to mousemove events
var canvas = document . querySelector ( 'canvas' ) ;
canvas . addEventListener ( "touchmove" , ( e ) => {
const touch = e . targetTouches [ 0 ] ; // We can get away with this because every other touch event will be on different elements
if ( ! previousX ) {
previousX = touch . pageX ;
previousY = touch . pageY ;
}
e . movementX = touch . pageX - previousX ;
e . movementY = touch . pageY - previousY ;
var evt = new MouseEvent ( "mousemove" , {
movementX : e . movementX ,
movementY : e . movementY
} ) ;
canvas . dispatchEvent ( evt ) ;
previousX = touch . pageX ;
previousY = touch . pageY ;
event . preventDefault ( ) ;
} , false ) ;
canvas . addEventListener ( "touchend" , ( e ) => {
previousX = null ;
previousY = null ;
} , false )
// Adds all of the touch screen controls
// Theres probably a better way to do this but this works for now
var forwardButton = document . createElement ( 'button' ) ;
forwardButton . id = "hideButton"
forwardButton . textContent = "▲" ;
forwardButton . style . cssText = "left:10vh;bottom:20vh;"
forwardButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( "w" , "keydown" ) } , false ) ;
forwardButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "w" , "keyup" ) } , false ) ;
forwardButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( forwardButton ) ;
var rightButton = document . createElement ( 'button' ) ;
rightButton . id = "hideButton"
rightButton . textContent = "▶" ;
rightButton . style . cssText = "left:20vh;bottom:10vh;"
rightButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( "d" , "keydown" ) } , false ) ;
rightButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "d" , "keyup" ) } , false ) ;
rightButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( rightButton ) ;
var leftButton = document . createElement ( 'button' ) ;
leftButton . id = "hideButton"
leftButton . textContent = "◀" ;
leftButton . style . cssText = "left: 0vh; bottom:10vh;"
leftButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( "a" , "keydown" ) } , false ) ;
leftButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "a" , "keyup" ) } , false ) ;
leftButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( leftButton ) ;
var backButton = document . createElement ( 'button' ) ;
backButton . id = "hideButton"
backButton . textContent = "▼" ;
backButton . style . cssText = "left:10vh;bottom:0vh;"
backButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( "s" , "keydown" ) } , false ) ;
backButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "s" , "keyup" ) } , false ) ;
backButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( backButton ) ;
var jumpButton = document . createElement ( 'button' ) ;
jumpButton . id = "hideButton"
jumpButton . textContent = "⇧" ;
jumpButton . style . cssText = "right:10vh;bottom:10vh;"
jumpButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( " " , "keydown" ) } , false ) ;
jumpButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( " " , "keyup" ) } , false ) ;
jumpButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( jumpButton ) ;
var crouchButton = document . createElement ( 'button' ) ;
crouchButton . id = "hideButton"
crouchButton . textContent = "⇩" ;
crouchButton . style . cssText = "left:10vh;bottom:10vh;"
crouchButton . addEventListener ( "touchstart" , function ( e ) { shiftKey ( "keydown" ) } , false ) ;
crouchButton . addEventListener ( "touchend" , function ( e ) { shiftKey ( "keyup" ) } , false ) ;
crouchButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( crouchButton ) ;
var inventoryButton = document . createElement ( 'button' ) ;
inventoryButton . id = "hideInventory"
inventoryButton . textContent = "🎒" ;
inventoryButton . style . cssText = "right:0vh;bottom:0vh;"
inventoryButton . addEventListener ( "touchstart" , function ( e ) {
window . inInventory = ( window . fakelock != null )
keyEvent ( "e" , "keydown" ) ;
} , false ) ;
inventoryButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "e" , "keyup" ) } , false ) ;
inventoryButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( inventoryButton ) ;
var chatButton = document . createElement ( 'button' ) ;
chatButton . id = "hideButton"
chatButton . textContent = "💬" ;
chatButton . style . cssText = "right:0vh;top:0vh;"
chatButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( "¿" , "keydown" ) } , false ) ;
chatButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "¿" , "keydown" ) } , false ) ;
chatButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( chatButton ) ;
var exitButton = document . createElement ( 'button' ) ;
exitButton . id = "exitButton"
exitButton . textContent = "⮐" ;
exitButton . style . cssText = "left:0vh;top:0vh;"
exitButton . addEventListener ( "touchstart" , function ( e ) { keyEvent ( "À" , "keydown" ) } , false ) ;
exitButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "À" , "keyup" ) } , false ) ;
exitButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( exitButton ) ;
var placeButton = document . createElement ( 'button' ) ;
placeButton . id = "hideButton"
placeButton . textContent = "⊹" ;
placeButton . style . cssText = "right:0vh;bottom:20vh;"
placeButton . addEventListener ( "touchstart" , function ( e ) { mouseEvent ( 2 , "mousedown" , canvas ) } , false ) ;
placeButton . addEventListener ( "touchend" , function ( e ) { mouseEvent ( 2 , "mouseup" , canvas ) } , false ) ;
placeButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( placeButton ) ;
var breakButton = document . createElement ( 'button' ) ;
breakButton . id = "hideButton"
breakButton . textContent = "🗡" ;
breakButton . style . cssText = "right:10vh;bottom:20vh;"
breakButton . addEventListener ( "touchstart" , function ( e ) { mouseEvent ( 0 , "mousedown" , canvas ) } , false ) ;
breakButton . addEventListener ( "touchend" , function ( e ) { mouseEvent ( 0 , "mouseup" , canvas ) } , false ) ;
breakButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( breakButton ) ;
var scrollUpButton = document . createElement ( 'button' ) ;
scrollUpButton . id = "hideButton"
scrollUpButton . textContent = "⇨" ;
scrollUpButton . style . cssText = "right:0vh;bottom:30vh;"
scrollUpButton . addEventListener ( "touchstart" , function ( e ) {
canvas . dispatchEvent ( new WheelEvent ( "wheel" , { "wheelDeltaY" : - 10 } ) )
} , false ) ;
scrollUpButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( scrollUpButton ) ;
var scrollDownButton = document . createElement ( 'button' ) ;
scrollDownButton . id = "hideButton"
scrollDownButton . textContent = "⇦" ;
scrollDownButton . style . cssText = "right:10vh;bottom:30vh;"
scrollDownButton . addEventListener ( "touchstart" , function ( e ) {
canvas . dispatchEvent ( new WheelEvent ( "wheel" , { "wheelDeltaY" : 10 } ) )
} , false ) ;
scrollDownButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( scrollDownButton ) ;
var throwButton = document . createElement ( 'button' ) ;
2024-05-26 14:45:05 -07:00
throwButton . id = "hideButton"
2024-05-26 14:17:04 -07:00
throwButton . textContent = "Q" ;
throwButton . style . cssText = "right:0vh;bottom:10vh;"
throwButton . addEventListener ( "touchstart" , function ( e ) {
window . inInventory = ( window . fakelock != null )
keyEvent ( "q" , "keydown" ) ;
} , false ) ;
throwButton . addEventListener ( "touchend" , function ( e ) { keyEvent ( "q" , "keyup" ) } , false ) ;
throwButton . addEventListener ( "touchmove" , function ( e ) { e . preventDefault ( ) } , false ) ;
document . body . appendChild ( throwButton ) ;
}