Hey
Im making a gang menu and i made it with my own ui.
Now the problem is that when i do the addEventListener click it fires multiple times.
I have added a thing that it only generates it one time but that doesnt seem to fix it.
Even preventDefault doesnt work.
Anyone can help me?
This is the setup part
window.addEventListener('message', function(event) {
data = event.data;
if (data.type == "open") {
var background = document.querySelector('#background');
background.style.display = 'block';
var cont = document.querySelector('#container');
cont.style.display = 'block';
setup();
if(!IsLoaded) {
navigation();
upgrade();
bank();
members();
IsLoaded = true;
}
} else if (data.type == "update") {
setup();
}
});
This is for example the upgrade tab that fires multiple times
function upgrade() {
var upgradestash = document.querySelector('#upgradestash');
var upgradealarm = document.querySelector('#upgradealarm');
upgradestash.addEventListener("click", (e) => {
e.preventDefault();
if(data.isgangboss) {
$.post(`https://flex-gangmenu/upgradeStash`, JSON.stringify({
safeid: data.safeid,
gang: data.gang,
cost: data.stashupgrade.cost,
lv: data.securitylv,
}));
}
});
upgradealarm.addEventListener("click", (e) => {
e.preventDefault();
if(data.isgangboss) {
$.post(`https://flex-gangmenu/upgradeAlarm`, JSON.stringify({
safeid: data.safeid,
gang: data.gang,
cost: data.securityupgrade.cost,
lv: data.stashlv,
}));
}
});
}
Check whether the upgrade function is being called more than once
I run all these
setup();
if(!IsLoaded) {
navigation();
upgrade();
bank();
members();
IsLoaded = true;
}
Everytime you open the menu with target.
I have set a variable that blocks
navigation();
upgrade();
bank();
members();
from executing every time the menu opens.
So it isnt called multiple times.
You can check out all the code here if that helps
Created a PR with slight change
1 Like