correção do bugs e melhora nos cookies
This commit is contained in:
11
rpg/js/globais.js
Normal file
11
rpg/js/globais.js
Normal file
@@ -0,0 +1,11 @@
|
||||
window.api = "http://192.168.1.102:8085/";
|
||||
|
||||
window.msg = (status, msg) => {
|
||||
tata.text(status, msg, {
|
||||
position: "br",
|
||||
duration: 3000,
|
||||
progress: true,
|
||||
closeBtn: true,
|
||||
animate: "slide",
|
||||
});
|
||||
};
|
||||
2
rpg/js/libs/jquery.js
vendored
Normal file
2
rpg/js/libs/jquery.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
rpg/js/libs/tata.js
Normal file
1
rpg/js/libs/tata.js
Normal file
File diff suppressed because one or more lines are too long
60
rpg/js/loadPlayer.js
Normal file
60
rpg/js/loadPlayer.js
Normal file
@@ -0,0 +1,60 @@
|
||||
let img;
|
||||
let playerID;
|
||||
|
||||
function loadFicha(id) {
|
||||
$.ajax({
|
||||
url: `${window.api}player/info/${id}`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
if (!img) {
|
||||
img = resp.Foto;
|
||||
$("#hero").attr("src", `data:image/*;base64,${resp.Foto}`);
|
||||
}
|
||||
|
||||
if (!playerID) playerID = resp.PlayerID;
|
||||
$("#vdp").text(resp.Vida);
|
||||
$("#nmp").text(resp.PlayerName);
|
||||
$("#lvp").text(resp.Level);
|
||||
$("#idp").text(resp.Idade);
|
||||
$("#alp").text(resp.Altura);
|
||||
$("#progress nav").css({ width: resp.VidaPorcentagem + "%" });
|
||||
|
||||
const statusMap = [
|
||||
{ limit: 0, text: "Status: morto(a)" },
|
||||
{ limit: 5, text: "Status: morrendo" },
|
||||
{ limit: 50, text: "Status: muito ferido(a)" },
|
||||
{ limit: 70, text: "Status: ferido(a)" },
|
||||
{ limit: 100, text: "Status: normal" },
|
||||
];
|
||||
|
||||
const status = statusMap.find((s) => resp.VidaPorcentagem <= s.limit);
|
||||
$("#playerDATA ul h3").text(status?.text || "Status: desconhecido");
|
||||
},
|
||||
error() {
|
||||
return $("body").html(
|
||||
'<div class="erro">a url esta incorreta ou usuario não existe</div>',
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
function getParam(param) {
|
||||
let urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get(param);
|
||||
}
|
||||
|
||||
let id = getParam("id");
|
||||
|
||||
if (!id) {
|
||||
return $("body").html(
|
||||
'<div class="erro">Você precisa passar uma ID na url</div>',
|
||||
);
|
||||
}
|
||||
setInterval(() => {
|
||||
loadFicha(id);
|
||||
}, 1000);
|
||||
|
||||
loadFicha(id);
|
||||
});
|
||||
303
rpg/js/load_ficha.js
Normal file
303
rpg/js/load_ficha.js
Normal file
@@ -0,0 +1,303 @@
|
||||
let img;
|
||||
let update;
|
||||
let playerID;
|
||||
let lastPowerID = 0;
|
||||
|
||||
async function useInv(id, type) {
|
||||
try {
|
||||
const resp = await $.ajax({
|
||||
url: `${window.api}player/inv/${type}/${id}`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
});
|
||||
msg(resp.Status, resp.Message);
|
||||
} catch (err) {
|
||||
msg(
|
||||
err.responseJSON?.Status || "Erro",
|
||||
err.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function invpower() {
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv/ph`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
const $invpower = $("#powers ul");
|
||||
|
||||
let latestId = lastPowerID;
|
||||
|
||||
resp.InvPws.forEach((item) => {
|
||||
if (item.id > lastPowerID) {
|
||||
const $li = $("<li>");
|
||||
$li.append($("<a>").text(item.name));
|
||||
|
||||
const $del = $("<a>")
|
||||
.attr("id", "DelBTN")
|
||||
.append(
|
||||
$("<span>").addClass("material-symbols-outlined").text("close"),
|
||||
);
|
||||
|
||||
$li.on("click", () => alert(item.desc));
|
||||
$del.on("click", (e) => {
|
||||
e.stopPropagation();
|
||||
useInv(item.id, "ph/del");
|
||||
$del.closest("li").remove();
|
||||
});
|
||||
|
||||
$li.append($del);
|
||||
$invpower.append($li);
|
||||
|
||||
if (item.id > latestId) latestId = item.id;
|
||||
}
|
||||
});
|
||||
|
||||
lastPowerID = latestId;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function invPlayer() {
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
const $invList = $("#inv ul").empty();
|
||||
|
||||
resp.InvItems.forEach((item) => {
|
||||
const $li = $("<li>");
|
||||
$li.append($("<label>").text(item.itemname));
|
||||
$li.append($("<label>").text(`tem: ${item.itemquantidade}`));
|
||||
$li.append($("<label>").text(`peso: ${item.itempeso}`));
|
||||
|
||||
const $delBtn = $("<a>")
|
||||
.attr("id", "DelBTN")
|
||||
.append(
|
||||
$("<span>").addClass("material-symbols-outlined").text("close"),
|
||||
);
|
||||
|
||||
$li.on("click", () => useInv(item.id, "use"));
|
||||
$delBtn.on("click", (e) => {
|
||||
e.stopPropagation();
|
||||
useInv(item.id, "del");
|
||||
});
|
||||
|
||||
$li.append($delBtn);
|
||||
$invList.append($li);
|
||||
});
|
||||
|
||||
$("#invPA").text(resp.invPeso);
|
||||
},
|
||||
error() {
|
||||
$("#inv ul").empty();
|
||||
$("#invPA").text(0);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function invPowerAdd() {
|
||||
const habilidade = $("input[name='habilidade']").val();
|
||||
const desc = $("textarea[name='desc']").val();
|
||||
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv/ph`,
|
||||
type: "POST",
|
||||
data: { nameph: habilidade, descph: desc },
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
$("input[name='habilidade'], textarea[name='desc']").val("");
|
||||
},
|
||||
error(resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function invAdd() {
|
||||
const nome = $("input[name='item_name']").val();
|
||||
const durabilidade = $("select[name='durabilite']").val();
|
||||
const peso = $("input[name='peso']").val();
|
||||
const quantidade = $("input[name='quantidade']").val();
|
||||
|
||||
$.ajax({
|
||||
url: `${window.api}player/inv`,
|
||||
type: "POST",
|
||||
data: { item_name: nome, durabilite: durabilidade, peso, quantidade },
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
$(
|
||||
"input[name='peso'], input[name='quantidade'], input[name='item_name'], select",
|
||||
).val("");
|
||||
$("select[name='durabilite']").val("duravel?");
|
||||
},
|
||||
error(resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function loadFicha() {
|
||||
$.ajax({
|
||||
url: `${window.api}player`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
if (!img) {
|
||||
img = resp.Foto;
|
||||
$("#hero").attr("src", `data:image/*;base64,${resp.Foto}`);
|
||||
}
|
||||
|
||||
if (!playerID) playerID = resp.PlayerID;
|
||||
$("#vdp").text(resp.Vida);
|
||||
$("#nmp").text(resp.PlayerName);
|
||||
$("#lvp").text(resp.Level);
|
||||
$("#idp").text(resp.Idade);
|
||||
$("#alp").text(resp.Altura);
|
||||
$("#conhecimento").text(resp.Conhecimento);
|
||||
$("#força").text(resp.Força);
|
||||
$("#destresa").text(resp.Destresa);
|
||||
$("#constitution").text(resp.Constituição);
|
||||
$("#inteligencia").text(resp.Inteligencia);
|
||||
$("#cárisma").text(resp.Cárisma);
|
||||
$("#mip").text(resp.Inventario);
|
||||
$("#lore").text(resp.Descrição);
|
||||
|
||||
if ($("#lore_edit").attr("placeholder") !== resp.Descrição) {
|
||||
$("#lore_edit").attr("placeholder", resp.Descrição);
|
||||
$("#lore_edit").val(resp.Descrição);
|
||||
}
|
||||
|
||||
const statusMap = [
|
||||
{ limit: 0, text: "Status: morto(a)" },
|
||||
{ limit: 5, text: "Status: morrendo" },
|
||||
{ limit: 50, text: "Status: muito ferido(a)" },
|
||||
{ limit: 70, text: "Status: ferido(a)" },
|
||||
{ limit: 100, text: "Status: normal" },
|
||||
];
|
||||
|
||||
const status = statusMap.find((s) => resp.VidaPorcentagem <= s.limit);
|
||||
$("#statusPlayer").text(status?.text || "Status: desconhecido");
|
||||
},
|
||||
error() {
|
||||
window.location.href = "login.html";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function rollLoad() {
|
||||
$.ajax({
|
||||
url: `${window.api}roll`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
let latestId = update || 0;
|
||||
|
||||
resp.Logs.forEach((item) => {
|
||||
if (item.id > (update || 0)) {
|
||||
const $li = $("<li>");
|
||||
$li.append($("<label>").text(item.log));
|
||||
$("#log").append($li);
|
||||
|
||||
if (item.id > latestId) latestId = item.id;
|
||||
}
|
||||
});
|
||||
|
||||
update = latestId;
|
||||
$("#log").scrollTop($("#log")[0].scrollHeight);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function roll(dado) {
|
||||
$.ajax({
|
||||
url: `${window.api}roll`,
|
||||
type: "POST",
|
||||
data: { roll: dado },
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
},
|
||||
error(resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Falha ao rolar dados.",
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function share(textToCopy) {
|
||||
if (navigator.clipboard) {
|
||||
return navigator.clipboard
|
||||
.writeText(textToCopy)
|
||||
.then(() => msg("success", "Link copiado com sucesso!"))
|
||||
.catch(() => msg("error", "Erro ao copiar link"));
|
||||
}
|
||||
const $tempInput = $("<input>");
|
||||
$("body").append($tempInput);
|
||||
$tempInput.val(textToCopy).select();
|
||||
try {
|
||||
document.execCommand("copy");
|
||||
msg("success", "Link copiado com sucesso!");
|
||||
} catch (err) {
|
||||
msg("error", "Erro ao copiar link");
|
||||
}
|
||||
$tempInput.remove();
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".updown").click(function () {
|
||||
const atb = $(this).data("atb");
|
||||
const dir = $(this).data("updown");
|
||||
|
||||
$.ajax({
|
||||
url: `${window.api}player/${atb}/${dir}`,
|
||||
type: "PATCH",
|
||||
xhrFields: { withCredentials: true },
|
||||
error(resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
$(".inv_add").on("click", function () {
|
||||
invAdd();
|
||||
});
|
||||
|
||||
$(".powerAdd").on("click", function () {
|
||||
invPowerAdd();
|
||||
});
|
||||
|
||||
$(".share").on("click", function () {
|
||||
const textToCopy = `${window.location.origin}/profile.html?id=${playerID}`;
|
||||
share(textToCopy);
|
||||
});
|
||||
|
||||
$(".obs").on("click", function () {
|
||||
const textToCopy = `${window.location.origin}/obs.html?id=${playerID}`;
|
||||
share(textToCopy);
|
||||
});
|
||||
|
||||
setInterval(() => {
|
||||
loadFicha();
|
||||
rollLoad();
|
||||
invPlayer();
|
||||
invpower();
|
||||
}, 1000);
|
||||
|
||||
loadFicha();
|
||||
});
|
||||
64
rpg/js/login.js
Normal file
64
rpg/js/login.js
Normal file
@@ -0,0 +1,64 @@
|
||||
function load_ficha() {
|
||||
$.ajax({
|
||||
url: window.api + "player",
|
||||
type: "GET",
|
||||
xhrFields: {
|
||||
withCredentials: true,
|
||||
},
|
||||
success: function (resp) {
|
||||
window.location.href = "index.html";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function verifyInputs(player, passwd) {
|
||||
if (player && !player.includes(" ") && passwd && !passwd.includes(" ")) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
load_ficha();
|
||||
$("#loginBtn").on("click", function () {
|
||||
const $btn = $(this);
|
||||
$btn.prop("disabled", true).val("Logando ...");
|
||||
|
||||
const player = $("#loginInput[name='player']").val();
|
||||
const password = $("#loginInput[name='password']").val();
|
||||
|
||||
if (!verifyInputs(player, password)) {
|
||||
msg("Error", "Por favor, preencha todos os dados corretamente.");
|
||||
return finalizarErro($btn, "Login");
|
||||
}
|
||||
|
||||
const form = new FormData();
|
||||
form.append("player", player);
|
||||
form.append("password", password);
|
||||
|
||||
$.ajax({
|
||||
url: window.api + "login",
|
||||
type: "POST",
|
||||
data: form,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
xhrFields: { withCredentials: true },
|
||||
success: function (resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
$btn.val("Concluído");
|
||||
window.location.href = "index.html";
|
||||
},
|
||||
error: function (resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
finalizarErro($btn, "Login");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function finalizarErro($btn, texto = "Login") {
|
||||
$btn.prop("disabled", false).val(texto);
|
||||
}
|
||||
});
|
||||
67
rpg/js/profile.js
Normal file
67
rpg/js/profile.js
Normal file
@@ -0,0 +1,67 @@
|
||||
let img;
|
||||
let playerID;
|
||||
|
||||
function loadFicha(id) {
|
||||
$.ajax({
|
||||
url: `${window.api}player/info/${id}`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
if (!img) {
|
||||
img = resp.Foto;
|
||||
$("#hero").attr("src", `data:image/*;base64,${resp.Foto}`);
|
||||
}
|
||||
|
||||
if (!playerID) playerID = resp.PlayerID;
|
||||
$("#vdp").text(resp.Vida);
|
||||
$("#nmp").text(resp.PlayerName);
|
||||
$("#lvp").text(resp.Level);
|
||||
$("#idp").text(resp.Idade);
|
||||
$("#alp").text(resp.Altura);
|
||||
$("#conhecimento").text(resp.Conhecimento);
|
||||
$("#força").text(resp.Força);
|
||||
$("#destresa").text(resp.Destresa);
|
||||
$("#constitution").text(resp.Constituição);
|
||||
$("#inteligencia").text(resp.Inteligencia);
|
||||
$("#cárisma").text(resp.Cárisma);
|
||||
$("#mip").text(resp.Inventario);
|
||||
$("#lore").text(resp.Descrição);
|
||||
|
||||
const statusMap = [
|
||||
{ limit: 0, text: "Status: morto(a)" },
|
||||
{ limit: 5, text: "Status: morrendo" },
|
||||
{ limit: 50, text: "Status: muito ferido(a)" },
|
||||
{ limit: 70, text: "Status: ferido(a)" },
|
||||
{ limit: 100, text: "Status: normal" },
|
||||
];
|
||||
|
||||
const status = statusMap.find((s) => resp.VidaPorcentagem <= s.limit);
|
||||
$("#statusPlayer").text(status?.text || "Status: desconhecido");
|
||||
},
|
||||
error() {
|
||||
return $("body").html(
|
||||
'<div class="erro">a url esta incorreta ou usuario não existe</div>',
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
function getParam(param) {
|
||||
let urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get(param);
|
||||
}
|
||||
|
||||
let id = getParam("id");
|
||||
|
||||
if (!id) {
|
||||
return $("body").html(
|
||||
'<div class="erro">Você precisa passar uma ID na url</div>',
|
||||
);
|
||||
}
|
||||
setInterval(() => {
|
||||
loadFicha(id);
|
||||
}, 1000);
|
||||
|
||||
loadFicha(id);
|
||||
});
|
||||
96
rpg/js/register.js
Normal file
96
rpg/js/register.js
Normal file
@@ -0,0 +1,96 @@
|
||||
function load_ficha() {
|
||||
$.ajax({
|
||||
url: window.api + "player",
|
||||
type: "GET",
|
||||
xhrFields: {
|
||||
withCredentials: true,
|
||||
},
|
||||
success: function (resp) {
|
||||
window.location.href = "index.html";
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function verifyInputs(player, passwd, confpasswd, lore) {
|
||||
if (
|
||||
player &&
|
||||
!player.includes(" ") &&
|
||||
passwd &&
|
||||
!passwd.includes(" ") &&
|
||||
confpasswd &&
|
||||
!confpasswd.includes(" ") &&
|
||||
lore
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$("#imgClick").on("click", () => $("#inputImagem").click());
|
||||
|
||||
$("#inputImagem").on("change", function () {
|
||||
const file = this.files[0];
|
||||
if (file && file.type.startsWith("image/")) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => $("#imgClick").attr("src", e.target.result);
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).ready(function () {
|
||||
load_ficha();
|
||||
$("#loginBtn").on("click", function () {
|
||||
const $btn = $(this);
|
||||
$btn.prop("disabled", true).val("Criando conta...");
|
||||
|
||||
const fileInput = $("#inputImagem")[0];
|
||||
const file = fileInput.files[0];
|
||||
|
||||
const player = $("#loginInput[name='player']").val();
|
||||
const password = $("#loginInput[name='password']").val();
|
||||
const confPassword = $("#loginInput[name='confirmpassword']").val();
|
||||
const lore = $("#playerlore[name='playerlore']").val();
|
||||
|
||||
if (!file) {
|
||||
msg("Error", "Você é obrigado a colocar uma imagem.");
|
||||
return finalizarErro($btn, "Registrar");
|
||||
}
|
||||
|
||||
if (!verifyInputs(player, password, confPassword, lore)) {
|
||||
msg("Error", "Por favor, preencha todos os dados corretamente.");
|
||||
return finalizarErro($btn, "Registrar");
|
||||
}
|
||||
|
||||
const form = new FormData();
|
||||
form.append("PlayerImage", fileInput.files[0]);
|
||||
form.append("player", player);
|
||||
form.append("password", password);
|
||||
form.append("confirmpassword", confPassword);
|
||||
form.append("playerlore", lore);
|
||||
console.log(form);
|
||||
$.ajax({
|
||||
url: window.api + "register",
|
||||
type: "POST",
|
||||
data: form,
|
||||
contentType: false,
|
||||
processData: false,
|
||||
xhrFields: { withCredentials: true },
|
||||
success: function (resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
$btn.val("Concluído");
|
||||
window.location.href = "index.html";
|
||||
},
|
||||
error: function (resp) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
finalizarErro($btn, "Registrar");
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function finalizarErro($btn, texto = "Registrar") {
|
||||
$btn.prop("disabled", false).val(texto);
|
||||
}
|
||||
});
|
||||
41
rpg/js/roll.js
Normal file
41
rpg/js/roll.js
Normal file
@@ -0,0 +1,41 @@
|
||||
let update;
|
||||
|
||||
function msg_(status, msg) {
|
||||
tata.text(status, msg, {
|
||||
position: "bl",
|
||||
duration: 3000,
|
||||
progress: true,
|
||||
closeBtn: false,
|
||||
animate: "slide",
|
||||
});
|
||||
}
|
||||
|
||||
function rollLoad() {
|
||||
$.ajax({
|
||||
url: `${window.api}roll`,
|
||||
type: "GET",
|
||||
xhrFields: { withCredentials: true },
|
||||
success(resp) {
|
||||
let latestLog = null;
|
||||
|
||||
resp.Logs.forEach((item) => {
|
||||
if (update === undefined || item.id > update) {
|
||||
if (!latestLog || item.id > latestLog.id) {
|
||||
latestLog = item;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (latestLog) {
|
||||
msg_("Rolagem", latestLog.log);
|
||||
update = latestLog.id;
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
setInterval(() => {
|
||||
rollLoad();
|
||||
}, 1000);
|
||||
});
|
||||
112
rpg/js/script.js
Normal file
112
rpg/js/script.js
Normal file
@@ -0,0 +1,112 @@
|
||||
var $inp;
|
||||
|
||||
let lore = false;
|
||||
let cordX = 0;
|
||||
let cordY = 0;
|
||||
|
||||
function data_update(name, value) {
|
||||
return new Promise((resulve, reject) => {
|
||||
$.ajax({
|
||||
url: window.api + "player/update",
|
||||
type: "POST",
|
||||
data: { [name]: value },
|
||||
|
||||
xhrFields: { withCredentials: true },
|
||||
success: function (resp) {
|
||||
msg(resp.Status, resp.Message);
|
||||
resulve(true);
|
||||
},
|
||||
error: function (resp, status, jqXHR) {
|
||||
msg(
|
||||
resp.responseJSON?.Status || "Erro",
|
||||
resp.responseJSON?.Message || "Algo deu errado.",
|
||||
);
|
||||
resulve(false);
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function editInput(name, x, y) {
|
||||
var input = `
|
||||
<nav id="FloatInput" style="top: ${y - 50}px; left: ${x - 100}px">
|
||||
<input type="text" placeholder="${name}" name="${name}" />
|
||||
</nav>
|
||||
`;
|
||||
$inp = $(input).appendTo("body").focus();
|
||||
|
||||
$inp.on("keydown", function (e) {
|
||||
if (e.which === 13) {
|
||||
switch ($(this).find("input").val().length > 0) {
|
||||
case true:
|
||||
let name = $(this).find("input").attr("name");
|
||||
let value = $(this).find("input").val();
|
||||
data_update(name, value).then((result) => {
|
||||
if (result) {
|
||||
$(this).remove();
|
||||
}
|
||||
});
|
||||
break;
|
||||
case false:
|
||||
$(this).remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
$inp.on("keypress keydown", function (e) {
|
||||
switch (e.key) {
|
||||
case "Delete":
|
||||
$(this).remove();
|
||||
break;
|
||||
case "Backspace":
|
||||
if ($(this).find("input").val() === "") {
|
||||
$(this).remove();
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$(document).on("mousemove", function (e) {
|
||||
cordX = e.clientX;
|
||||
cordY = e.clientY;
|
||||
});
|
||||
$(".editbtn").on("click", function (e) {
|
||||
let reqbtn = e.currentTarget.className.split(" ");
|
||||
let nameclass =
|
||||
reqbtn.length > 1
|
||||
? editInput(reqbtn[1], cordX, cordY)
|
||||
: msg("Error", "erro, ainda não foi definido a classe desse botão");
|
||||
});
|
||||
|
||||
$(".lore").on("click", function (e) {
|
||||
switch (lore) {
|
||||
case false:
|
||||
$(".lore span").text("close");
|
||||
$("#lore").hide();
|
||||
$("#lore_edit").show();
|
||||
$(".lore_edit").css("display", "block");
|
||||
lore = true;
|
||||
break;
|
||||
case true:
|
||||
$(".lore span").text("edit");
|
||||
$("#lore").show();
|
||||
$("#lore_edit").hide();
|
||||
$(".lore_edit").css("display", "none");
|
||||
lore = false;
|
||||
break;
|
||||
}
|
||||
});
|
||||
$(".lore_edit").on("click", function (e) {
|
||||
data_update("lore", $("#lore_edit").val()).then((result) => {
|
||||
if (result) {
|
||||
$(".lore span").text("edit");
|
||||
$("#lore").show();
|
||||
$("#lore_edit").hide();
|
||||
$(".lore_edit").css("display", "none");
|
||||
lore = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user