Skip to content

Commit

Permalink
chore: carried out code formatting and stability work
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Dec 24, 2024
1 parent 8888a4f commit 54e8481
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions server-data/resources/[esx_addons]/ps-dispatch/ui/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-unused-vars */
$(document).ready(() => {
window.addEventListener('message', function (event) {
let data = event.data;
if (data.update == 'newCall') {
window.addEventListener('message', function(event) {
const data = event.data;
if (data.update === 'newCall') {
addNewCall(data.callID, data.timer, data.data, data.isPolice);
}
});
Expand Down Expand Up @@ -50,7 +51,7 @@ function timeAgo(dateParam) {
}

const date =
typeof dateParam === 'object' ? dateParam : new Date(dateParam);
typeof dateParam === 'object' ? dateParam : new Date(dateParam);
const DAY_IN_MS = 86400000;
const today = new Date();
const yesterday = new Date(today - DAY_IN_MS);
Expand All @@ -62,17 +63,23 @@ function timeAgo(dateParam) {

if (seconds < 5) {
return 'Just Now';
} else if (seconds < 60) {
}
else if (seconds < 60) {
return `${seconds} Seconds ago`;
} else if (seconds < 90) {
}
else if (seconds < 90) {
return 'About a minute ago';
} else if (minutes < 60) {
}
else if (minutes < 60) {
return `${minutes} Minutes ago`;
} else if (isToday) {
}
else if (isToday) {
return getFormattedDate(date, 'Today');
} else if (isYesterday) {
}
else if (isYesterday) {
return getFormattedDate(date, 'Yesterday');
} else if (isThisYear) {
}
else if (isThisYear) {
return getFormattedDate(date, false, true);
}

Expand All @@ -84,15 +91,16 @@ function addNewCall(callID, timer, info, isPolice) {
let DispatchItem;
if (info['isDead']) {
DispatchItem = `<div class="dispatch-item ${callID} dispatch-item-${info['isDead']} animate__animated"><div class="top-info-holder"><div class="call-id">#${callID}</div><div class="call-code priority-${prio}">${info.dispatchCode}</div><div class="call-name">${info.dispatchMessage}</div></div><div class="bottom-info-holder">`;
} else {
}
else {
DispatchItem = `<div class="dispatch-item ${callID} dispatch-item-${isPolice} animate__animated"><div class="top-info-holder"><div class="call-id">#${callID}</div><div class="call-code priority-${prio}">${info.dispatchCode}</div><div class="call-name">${info.dispatchMessage}</div></div><div class="bottom-info-holder">`;
}

// Above we are defining a default dispatch item and then we will append the data we have been sent.

if (info['time']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-clock"></span>${timeAgo(
info['time']
info['time'],
)}</div>`;
}

Expand Down Expand Up @@ -126,46 +134,56 @@ function addNewCall(callID, timer, info, isPolice) {

if (info['model'] && info['plate']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-car"></span>${info['model']}<span class="fas fa-digital-tachograph" style="margin-left: 2vh;"></span>${info['plate']}</div>`;
} else if (info['plate']) {
}
else if (info['plate']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-digital-tachograph"></span>${info['plate']}</div>`;
} else if (info['model']) {
}
else if (info['model']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-car"></span>${info['model']}</div>`;
}

if (info['firstColor']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-spray-can"></span>${info['firstColor']}</div>`;
}
if (info['automaticGunfire'] == true) {
DispatchItem += `<div class="call-bottom-info"><span class="fab fa-blackberry"></span>Automatic Gunfire</div>`;
DispatchItem += '<div class="call-bottom-info"><span class="fab fa-blackberry"></span>Automatic Gunfire</div>';
}

if (info['name'] && info['number']) {
DispatchItem += `<div class="call-bottom-info"><span class="far fa-id-badge"></span>${info['name']}<span class="fas fa-mobile-alt" style="margin-left: 2vh;"></span>${info['number']}</div>`;
} else if (info['number']) {
}
else if (info['number']) {
DispatchItem += `<div class="call-bottom-info"><span class="fas fa-mobile-alt"></span>${info['number']}</div>`;
} else if (info['name']) {
}
else if (info['name']) {
DispatchItem += `<div class="call-bottom-info"><span class="far fa-id-badge"></span>${info['name']}</div>`;
}

if (info['information']) {
DispatchItem += `<div class="line"></div><div class="call-bottom-info call-bottom-information"><span class="far fa-question-circle"></span>${info['information']}</div>`;
}

DispatchItem += `</div></div>`;
DispatchItem += '</div></div>';

$('.dispatch-holder').prepend(DispatchItem);

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.

var timer = 4000;
timer = 4000;

if (prio == 1) {
timer = 12000;
} else if (prio == 2) {
timer = 9000;
if (prio == 1) {
timer = 12000;
}
else if (prio == 2) {
timer = 9000;
}
}
}

function removeCall(callID, timer) {
$(`.${callID}`).addClass('animate__backInRight');
setTimeout(() => {
$(`.${callID}`).addClass('animate__backOutRight');

setTimeout(() => {
$(`.${callID}`).remove();
}, 1000);
Expand Down

0 comments on commit 54e8481

Please sign in to comment.