tre3
This commit is contained in:
parent
2276587403
commit
0d91493cc7
|
@ -39,4 +39,7 @@ bin/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
### Mac OS ###
|
### Mac OS ###
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
javascript/js/
|
||||||
|
!javascript/classes.js
|
Binary file not shown.
25
build.gradle
25
build.gradle
|
@ -1,19 +1,30 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'org.teavm' version '0.9.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
group = 'net.hoosiertransfer'
|
|
||||||
version = '1.0-SNAPSHOT'
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
testImplementation platform('org.junit:junit-bom:5.9.1')
|
teavm(teavm.libs.jso)
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
teavm(teavm.libs.jsoApis)
|
||||||
|
implementation 'org.json:json:20240303'
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
teavm.js {
|
||||||
useJUnitPlatform()
|
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
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -1,10 +1,21 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<title>$Title$</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body style="margin:0px;width:100vw;height:100vh;overflow:hidden;" id="game_frame">
|
||||||
$END$
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -1,16 +1,23 @@
|
||||||
package net.hoosiertransfer.EaglerXMicrosoft.network;
|
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.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class Fetch {
|
public class PostRequest {
|
||||||
private final Map<String, String> headers;
|
public Map<String, String> headers;
|
||||||
private final String method;
|
public Map<String, String> contents;
|
||||||
|
|
||||||
|
public PostRequest() {
|
||||||
public Fetch(String method) {
|
|
||||||
headers = new HashMap<>();
|
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) {
|
public void addHeader(String key, String value) {
|
||||||
|
@ -20,4 +27,43 @@ public class Fetch {
|
||||||
public void removeHeader(String key) {
|
public void removeHeader(String key) {
|
||||||
headers.remove(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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
package net.hoosiertransfer;
|
package net.hoosiertransfer;
|
||||||
|
|
||||||
|
import net.hoosiertransfer.EaglerXMicrosoft.network.PostRequest;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue