skinswitcher/html/partials/random.html

78 lines
2.6 KiB
HTML
Raw Normal View History

<h1 class="title">Random Skin</h1>
<div class="columns is-mobile">
<div class="column">
<img src="" class="skin" id="flat" alt="Current Skin" style="display: none;">
2021-09-06 19:40:51 +02:00
<div id="mesh"></div>
</div>
<div class="column">
<article class="message is-warning">
<div class="message-body">
I am not responsible for any explicit content displayed when using the random skin function.
</div>
</article>
<div class="buttons">
<button class="button" id="random">Random</button>
<button class="button" id="set">Use this skin</button>
</div>
<div class="buttons has-addons">
<button class="button" id="download">Download</button>
<button class="button" id="save">Save</button>
</div>
<div class="buttons">
<button class="button" id="switch" style="display: none;">Switch to 2D</button>
</div>
</div>
</div>
<script src="../src/skin.js"></script>
<script>
var parser = new DOMParser();
var randomUrls = [];
axios({
method: "GET",
url: "https://nl.namemc.com/minecraft-skins/random"
}).then((data) => {
var namemc = parser.parseFromString(data.data, "text/html");
namemc.querySelectorAll("a").forEach((e) => {
var href = e.getAttribute("href");
if (href.includes("skin")) {
var id = href.split("/")[2];
if (id && id.length == 16 && !(id.includes("-"))) {
randomUrls.push("https://nl.namemc.com/texture/" + id + ".png");
}
}
});
function random() {
if (randomUrls.length == 0) {
2020-06-25 14:21:53 +02:00
load("/partials/random.html");
} else {
var id = Math.floor(Math.random() * (randomUrls.length - 0)) + 0;
setView(randomUrls[id]);
randomUrls.splice(id, 1);
}
}
random();
2021-09-06 19:40:51 +02:00
$("button#random").on("click", (e) => {
random();
});
2021-09-06 19:40:51 +02:00
$("button#set").on("click", (e) => {
axios({
method: "get",
url: view.flat.src,
responseType: "arraybuffer",
adapter: require("axios/lib/adapters/http")
}).then((res) => {
settings.set = "data:image/png;base64," + res.data.toString("base64");
load("/partials/upload.html");
}).catch((err) => {
notify("danger", "Something went wrong: " + err)
});
});
});
</script>