// ==UserScript==
// @name Gladiatus Tools
// @namespace https://greasyfork.org/users/904482
// @version 0.4.0
// @description Set of tools and aids for the game Gladiatus
// @author lpachecob
// @grant none
// @match *.gladiatus.gameforge.com/game/index.php*
// @icon https://cdn.jsdelivr.net/gh/lpachecob/Gladiatus-Tools@main/images/favicon.ico
// @license MIT
// @downloadURL none
// ==/UserScript==
//global variables
const getURL = window.location.search.split("&");
const oro = parseInt(document.getElementById("sstat_gold_val").innerText.replace(/\./g, ''));
var dobleClickEvent = document.createEvent('MouseEvents');
dobleClickEvent.initEvent('dblclick', true, true);
let sh = {
get : ()=>{
for (let element of getURL) {
if(element.includes("sh") == true){
return element;
}
}
}
}
class GladiatusTools{
static SetTool(){
const mainMenu = document.getElementById("mainmenu");
if (getURL[0] == "?mod=guildMarket" && getURL[1] != "submod=control") {
Mercado.Run();
} else if (getURL[0] == "?mod=guildMarket" && getURL[1] == "submod=control") {
//comming soon
} else if (getURL[0] == "?mod=auction") {
AcutionHouseTools();
} else if (getURL[0] == "?mod=forge" && getURL[1] == "submod=smeltery") {
SmelteryTimeSaverExtension();
} else if (getURL[0] == "?mod=forge" && getURL[1] == "submod=forge") {
Herreria();
}else if(getURL[0] == "?mod=packages"){
Paquetes.UI();
Paquetes.MoverFiltros();
}
}
static Run(){
Menu.Dibujar();
GladiatusTools.SetTool();
Notificaciones.Rotativos();
GuardarOro.Run();
ExtenderBotones.Paquetes();
window.addEventListener("load", () => {
localStorage.TimeSaverExist = TimeSaver.Exist();
TimeSaver.setKeyForStop(JSON.parse(localStorage.TimeSaverExist));
TimeSaver.StopOnKey();
});
}
}
class insertOnPage{
// Antes que el propio elemento.
static beforebegin(object, html){
object.insertAdjacentHTML("beforebegin", html);
}
//Justo dentro del elemento, antes de su primer elemento hijo.
static afterbegin(object, html){
object.insertAdjacentHTML("afterbegin", html);
}
//Justo dentro del elemento, después de su último elemento hijo.
static beforeend(object, html){
object.insertAdjacentHTML("beforeend", html);
}
//Después del propio elemento.
static afterend(object, html){
object.insertAdjacentHTML("afterend", html);
}
}
class Observer{
static ForRemovedNodes(ItemForWait, instructions){
const observer = new MutationObserver((mutationList) => {
mutationList.forEach((mutation)=> {
if(mutation.removedNodes.length){
instructions();
}
})
});
// Opcions para el observer
const observerOptions = {
attributes: true,
childList: true,
subtree: true,
characterData: false,
attributeOldValue: false,
characterDataOldValue: false
};
observer.observe(ItemForWait, observerOptions);
}
}
class Formatter{
static abbreviateNumber(number){
var SI_SYMBOL = ["", "k", "kk", "kkk", "kkkk", "kkkkk", "kkkkkk"];
// what tier? (determines SI symbol)
var tier = Math.log10(Math.abs(number)) / 3 | 0;
// if zero, we don't need a suffix
if(tier == 0) return number;
// get suffix and determine scale
var suffix = SI_SYMBOL[tier];
var scale = Math.pow(10, tier * 3);
// scale the number
var scaled = number / scale;
// format number and add suffix
return scaled.toFixed(1) + suffix;
}
}
class Menu{
static Dibujar(){
document.body.insertAdjacentHTML("afterbegin",`
`);
let menuOpen = document.getElementById("MenuOpen");
menuOpen.addEventListener("click", Menu.openNav);
menuOpen.addEventListener("touchstart",Menu.openNav);
let closeMenu = document.getElementById("CloseMenu");
closeMenu.addEventListener("click", Menu.closeNav);
}
static openNav() {
document.getElementById("menuSidenav").style.display = "block";
}
static closeNav() {
document.getElementById("menuSidenav").style.display = "none";
}
static addConfig(html){
html+= "
"
insertOnPage.beforeend(document.getElementById("menuContent"),html);
}
}
class Notificaciones{
static Rotativos(){
Menu.addConfig(`
Notificaciones
`);
let MontosNotificar = document.getElementById("MontosNotificar");
let InputNotificarOro = document.getElementById("InputNotificarOro");
let MontosGuardados = [];
if(localStorage.MontosGuardados == undefined){
localStorage.MontosGuardados = '["100000"]';
}else{
MontosGuardados = JSON.parse(localStorage.MontosGuardados)
}
InputNotificarOro.addEventListener("keypress",(input)=>{
if (input.key === 'Enter') {
if (!MontosGuardados.includes(InputNotificarOro.value) && InputNotificarOro.value != "") {
MontosGuardados.push(InputNotificarOro.value);
InputNotificarOro.value = "";
localStorage.MontosGuardados = JSON.stringify(MontosGuardados.sort(function(a, b){return a - b}));
window.location.reload()
}
}
});
let NotificarOro = document.getElementById("NotificarOro"); //.checked indica si está activo o no
if (localStorage.NotificarOro == undefined) {
localStorage.NotificarOro = NotificarOro.checked
} else {
NotificarOro.checked = JSON.parse(localStorage.NotificarOro);
}
NotificarOro.addEventListener("change", () => {
localStorage.NotificarOro = NotificarOro.checked;
})
if (JSON.parse(localStorage.NotificarOro) == true) {
Notificaciones.Mensaje();
Notificaciones.MostrarRotativosSeleccionados();
Notificaciones.EliminarRotativo();
}
}
static Mensaje(){
let MontosGuardados = JSON.parse(localStorage.MontosGuardados);
let mensaje = "";
for(let monto of MontosGuardados){
if (Math.floor(oro / monto) >= 2) {
mensaje += `Empaqueta ` + Math.floor(oro / monto) + ` rotativos de `+ Formatter.abbreviateNumber(monto)+`\n`;
} else if (Math.floor(oro / monto) == 1) {
mensaje += `Empaqueta ` + Math.floor(oro / monto) + ` rotativo de `+ Formatter.abbreviateNumber(monto)+`\n`;
}
}
if (mensaje != "") {
document.getElementById("mmonetbar").insertAdjacentHTML("beforeend",`
`)
let buscarRotativos = document.getElementById("buscarRotativos");
let categoria = document.getElementById("categoria");
buscarRotativos.addEventListener("click",()=>{
Paquetes.PonerEnFavoritos(categoria.value)
})
buscarRotativos.addEventListener("touchstart",()=>{
Paquetes.PonerEnFavoritos(categoria.value)
})
if(localStorage.paquetesCategoria == undefined){
localStorage.paquetesCategoria = "Mercado";
}else{categoria.value = localStorage.paquetesCategoria}
categoria.addEventListener("change",()=>{localStorage.paquetesCategoria = categoria.value});
}
static PonerEnFavoritos(textContent){
let MercadoFavoritos = document.getElementById("MercadoFavoritos");
let rotativos = Paquetes.EncontrarRotativos(textContent);
MercadoFavoritos.style.display = "block";
MercadoFavoritos.innerHTML = ``;
let mensaje = document.getElementById("mensaje");
if (rotativos.length > 0){
mensaje.innerText = "Objetos Encontrados!";
for (let item of rotativos) {
MercadoFavoritos.append(item)
}
} else {mensaje.innerHTML = `
No se encontraron objetos, intenta nuevamente.
`;}
}
static EncontrarRotativos(textContent){
let rotativos = []
let packages = document.getElementById("packages");
//packages.children[1].children[2].children[0].attributes[6].textContent.includes("Oro")
for (let item of packages.children) {
if(!!item.children[1] == true &&
item.children[1].textContent == textContent
){
let atributes = item.children[2].children[0].attributes;
for (let atribute of atributes) {
if(atribute.name == "data-tooltip"){
if(atribute.textContent.includes('Oro","white"') == false){
rotativos.push(item)
}
}
}
}
}
return rotativos
}
static MoverFiltros(){
let filtros = document.getElementsByClassName("package-advance-filters")[0];
filtros.setAttribute("style","width: 500px;margin-left: auto;")
let article = document.getElementsByTagName("article")[0];
let sectionHeaders = document.getElementsByClassName("section-header")
for (let section of sectionHeaders) {
if(section.innerHTML.includes("Paquetes")==true){
article.insertBefore(filtros,section)
}
}
}
}
//style="width: 500px;margin-left: auto;"
class TimeSaver{
static Exist(){
const timeSaverr = !!document.getElementsByClassName("auto-settings")[0]
return timeSaverr;
}
static setKeyForStop(timeSaverExist){
if(timeSaverExist==true){
Menu.addConfig(`
TimeSaver
Atajos de Teclado
✔ Cambios guardados correctamente
`);
let timeSaverHotKeySelectedKey = document.getElementById("timeSaverHotKeySelectedKey");
let timeSaverHotKeyCheckbox = document.getElementById("timeSaverHotKeyCheckbox");
let timeSaverHotKeyConfirmation = document.getElementById("timeSaverHotKeyConfirmation");
let Btnconfirmar = document.getElementById("Btnconfirmar");
Btnconfirmar.addEventListener("click",()=>{Btnconfirmar.textContent = ""; timeSaverHotKeyConfirmation.hidden = false;});
if(localStorage.timeSaverHotKeyCheckbox == undefined){
localStorage.timeSaverHotKeyCheckbox = false;
} else {
timeSaverHotKeyCheckbox.checked = JSON.parse(localStorage.timeSaverHotKeyCheckbox);
}
timeSaverHotKeyCheckbox.addEventListener("change",()=>{localStorage.timeSaverHotKeyCheckbox=timeSaverHotKeyCheckbox.checked;})
if(localStorage.timeSaverHotKeySelectedKey == undefined){
localStorage.timeSaverHotKeySelectedKey = "";
} else {
timeSaverHotKeySelectedKey.value = localStorage.timeSaverHotKeySelectedKey;
}
timeSaverHotKeySelectedKey.addEventListener("keydown",()=>{timeSaverHotKeySelectedKey.select();
Btnconfirmar.textContent = "✅";
})
timeSaverHotKeySelectedKey.addEventListener("change",()=>{localStorage.timeSaverHotKeySelectedKey = timeSaverHotKeySelectedKey.value;})
}
}
static StopOnKey(){
document.addEventListener('keyup', (e)=>{
let selectKey = localStorage.timeSaverHotKeySelectedKey;
let useControl = JSON.parse(localStorage.timeSaverHotKeyCheckbox);
if (useControl == true && e.ctrlKey && e.key === selectKey) {
TimeSaver.StopBot();
}
if (useControl == false && e.key === selectKey) {
TimeSaver.StopBot();
}
}, false);
}
static StopBot(){
let timeSaver = document.getElementsByClassName("auto-settings")[0]
let botonPlay = timeSaver.children[3];
if (botonPlay.classList[2] == "show") {
//bot desactivado
botonPlay.click();
}
}
}
class ExtenderBotones{
static Paquetes(){
let menue_packages = document.getElementById("menue_packages");
let url = window.location.search.split("&");
insertOnPage.afterend(menue_packages,`
`);
let menuBotonPaquetes = document.getElementById("menuBotonPaquetes");
let extenderPaquetes = document.getElementById("extenderPaquetes");
let menuAbierto = false;
extenderPaquetes.addEventListener("click",()=>{
menuAbierto = !menuAbierto;
if(menuAbierto == true){
menuBotonPaquetes.style.display = 'block';
} else {
menuBotonPaquetes.style.display = 'none';
}
})
document.addEventListener('mouseup', function(e) {
var container = document.getElementById("extenderPaquetes");
if (!container.contains(e.target)) {
menuBotonPaquetes.style.display = 'none';
}
});
}
}
class GuardarOro{
static UI(){
Menu.addConfig(`
Guardar Oro
`);
let GuardarOroCheck = document.getElementById("GuardarOroCheck");
;
let TipoDeGuardado = document.getElementById("TipoDeGuardado")
if (localStorage.GuardarOroCheck == undefined) {
localStorage.GuardarOroCheck = GuardarOroCheck.checked
} else {
GuardarOroCheck.checked = JSON.parse(localStorage.GuardarOroCheck);
}
GuardarOroCheck.addEventListener("change", () => {
localStorage.GuardarOroCheck = GuardarOroCheck.checked;
})
if (localStorage.TipoDeGuardado == undefined) {
localStorage.TipoDeGuardado = TipoDeGuardado.selectedIndex
} else {
TipoDeGuardado.selectedIndex = localStorage.TipoDeGuardado;
}
TipoDeGuardado.addEventListener("change", () => {
localStorage.TipoDeGuardado = TipoDeGuardado.selectedIndex;
location.reload();
})
if(TipoDeGuardado.selectedIndex == 0 || TipoDeGuardado.selectedIndex == 1){
insertOnPage.afterend(TipoDeGuardado,` {
localStorage.OroMaximoSuelto = OroMaximoSuelto.value;
})
}
if(TipoDeGuardado.selectedIndex == 2){
insertOnPage.afterend(TipoDeGuardado,`
`)
let SeleccionarEntrenamiento = document.getElementById("SeleccionarEntrenamiento");
if (localStorage.SeleccionarEntrenamiento == undefined) {
localStorage.SeleccionarEntrenamiento = SeleccionarEntrenamiento.selectedIndex
} else {
SeleccionarEntrenamiento.selectedIndex = localStorage.SeleccionarEntrenamiento;
}
SeleccionarEntrenamiento.addEventListener("change", () => {
localStorage.SeleccionarEntrenamiento = SeleccionarEntrenamiento.selectedIndex;
})
}
}
static VerSiTengoOro(oroTrigger){
let oroTriggerParse = parseInt(oroTrigger)
if(oro > oroTriggerParse){
return true;
}else{
return false;
}
}
static Guardar(){
let EntrenamientoLink = "https://s45-es.gladiatus.gameforge.com/game/index.php?mod=training&"+sh.get();
let GuardarOroCheck = document.getElementById("GuardarOroCheck")
if(GuardarOroCheck.checked){
let tipoDeGuardado = {
get : ()=>{
let TipoDeGuardado = document.getElementById("TipoDeGuardado");
return TipoDeGuardado.selectedIndex
},
__ifNeedTriggerGold : ()=>{
},
__ifNeedChoiseAnStat : ()=>{
let SeleccionarEntrenamiento = document.getElementById("SeleccionarEntrenamiento");
return SeleccionarEntrenamiento.selectedIndex;
}
}
let data = {
init : ()=>{
if (getURL[0] == "?mod=training") {
let TrainingBox = document.getElementById("training_box");
let Stats = {
get : ()=>{
let stats = []
for (let index = 1; index < 7; index++){
stats.push(TrainingBox.children[index])
}
return stats;
},
push : ()=>{
let statPrices = []
for (let statPrice of Stats.get()) {
statPrices.push(parseInt(statPrice.children[1].children[0].children[0].innerText.replace(/\./g, '')))
}
localStorage.PlayerStatsPrices = JSON.stringify(statPrices);
}
}
Stats.push();
}
}
}
if(localStorage.PlayerStatsPrices == undefined){
window.location.href = "https://s45-es.gladiatus.gameforge.com/game/index.php?mod=training&"+sh.get();
}
data.init()
let training_box = document.getElementById("training_box");
let trainButtons = {
get : ()=>{
let buttons = []
for (let index = 1; index < 7; index++) {
buttons.push(training_box.children[index].children[1].children[1])
}
return buttons;
}
}
/////////////
//ir a guardar
let playerStatsPrices = JSON.parse(localStorage.PlayerStatsPrices)
if(playerStatsPrices[tipoDeGuardado.__ifNeedChoiseAnStat()] < oro){
window.location.href = EntrenamientoLink;
trainButtons.get()[tipoDeGuardado.__ifNeedChoiseAnStat()].click();
}
}
}
static Run(){
GuardarOro.UI();
GuardarOro.Guardar();
}
}
//////////////////////////////////////////////////////////////////////
/**
* run script
*/
GladiatusTools.Run();