This commit is contained in:
HoosierTransfer 2024-05-16 19:42:10 -04:00
parent 2276587403
commit 0d91493cc7
8 changed files with 25135 additions and 20 deletions

5
.gitignore vendored
View File

@ -39,4 +39,7 @@ bin/
.vscode/
### Mac OS ###
.DS_Store
.DS_Store
javascript/js/
!javascript/classes.js

View File

@ -1,19 +1,30 @@
plugins {
id 'java'
id 'org.teavm' version '0.9.2'
}
group = 'net.hoosiertransfer'
version = '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:5.9.1')
testImplementation 'org.junit.jupiter:junit-jupiter'
teavm(teavm.libs.jso)
teavm(teavm.libs.jsoApis)
implementation 'org.json:json:20240303'
}
test {
useJUnitPlatform()
teavm.js {
obfuscated = false
sourceMap = true
targetFileName = "../classes.js"
optimization = org.teavm.gradle.api.OptimizationLevel.BALANCED
outOfProcess = false
fastGlobalAnalysis = false
processMemory = 512
entryPointName = 'main'
mainClass = 'net.hoosiertransfer.Main'
outputDir = file("javascript")
properties = null
sourceMap = true
debugInformation = false
}

25037
javascript/classes.js Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>$Title$</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>EaglerXMicrosoft</title>
<script type="text/javascript" src="classes.js"></script>
<script type="text/javascript">
"use strict";
window.addEventListener("load", () => {
if(document.location.href.startsWith("file:")) {
alert("HTTP please, do not open this file locally, run a local HTTP server and load it via HTTP");
}else {
main();
}
});
</script>
</head>
<body>
$END$
<body style="margin:0px;width:100vw;height:100vh;overflow:hidden;" id="game_frame">
</body>
</html>

View File

@ -1,16 +1,23 @@
package net.hoosiertransfer.EaglerXMicrosoft.network;
import org.json.JSONObject;
import org.teavm.interop.Async;
import org.teavm.interop.AsyncCallback;
import org.teavm.jso.JSBody;
import org.teavm.jso.ajax.XMLHttpRequest;
import java.util.HashMap;
import java.util.Map;
public class Fetch {
private final Map<String, String> headers;
private final String method;
public class PostRequest {
public Map<String, String> headers;
public Map<String, String> contents;
public Fetch(String method) {
public PostRequest() {
headers = new HashMap<>();
this.method = method;
contents = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded");
}
public void addHeader(String key, String value) {
@ -20,4 +27,43 @@ public class Fetch {
public void removeHeader(String key) {
headers.remove(key);
}
public void put(String key, String value) {
contents.put(key, value);
}
@Async
public native JSONObject send(String url);
private void send(String url, AsyncCallback<JSONObject> callback) {
XMLHttpRequest xhr = XMLHttpRequest.create();
String corsProxyUrl = "https://corsproxy.io/?" + encodeURIComponent(url);
xhr.open("POST", corsProxyUrl);
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
for (Map.Entry<String, String> entry : headers.entrySet()) {
xhr.setRequestHeader(entry.getKey(), entry.getValue());
}
StringBuilder bodyBuilder = new StringBuilder();
for (Map.Entry<String, String> entry : contents.entrySet()) {
bodyBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
String body = bodyBuilder.substring(0, bodyBuilder.length() - 1);
xhr.setOnReadyStateChange(() -> {
if (xhr.getReadyState() == XMLHttpRequest.DONE) {
if (xhr.getStatus() == 200) {
callback.complete(new JSONObject(xhr.getResponseText()));
if (xhr.getStatus() == 400) {
callback.error(new Exception("HTTP error " + xhr.getStatus() + ": " + xhr.getResponseText()));
} else {
callback.error(new Exception("HTTP error " + xhr.getStatus()));
}
}
}
});
xhr.send(body);
}
@JSBody(params = "url", script = "return encodeURIComponent(url);")
private static native String encodeURIComponent(String url);
}

View File

@ -1,7 +1,13 @@
package net.hoosiertransfer;
import net.hoosiertransfer.EaglerXMicrosoft.network.PostRequest;
import org.json.JSONObject;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
PostRequest postRequest = new PostRequest();
postRequest.put("key", "value");
JSONObject response = postRequest.send("https://login.live.com/oauth20_token.srf");
System.out.println(response);
}
}