Thursday, September 19, 2024 11:52:30 PM
> settings

Customize


Authenticate

> util.js
///////////////////////////////////////////////////////////////////
/*
	Formats a javascript time to am or pm time
	https://stackoverflow.com/a/8888498
*/
///////////////////////////////////////////////////////////////////
function formatAMPM(date) 
{
  var hours = date.getHours();
  var minutes = date.getMinutes();
  var ampm = hours >= 12 ? 'pm' : 'am';
  hours = hours % 12;
  hours = hours ? hours : 12; // the hour '0' should be '12'
  minutes = minutes < 10 ? '0'+minutes : minutes;
  var strTime = hours + ':' + minutes + ampm;
  return strTime;
}



///////////////////////////////////////////////////////////////////
/*
	Shows a toast notification
*/
///////////////////////////////////////////////////////////////////
function showToast(_body, _template = "info", _title = "Information", _hideAfter = 5000)
{
	var left = ($(document).width() < 998) ? 45 : 425;

	$.toast({
		heading: _title,
		text: _body,
		showHideTransition: 'slide',
		icon: _template,
		loader: false,
		position: {
				left: left,
				top: 75
		},
		stack: 10,
		hideAfter: _hideAfter
	});
}




///////////////////////////////////////////////////////////////////
/*
	Compairs the value of two cells
*/
///////////////////////////////////////////////////////////////////
function comparer(index) 
{
    return function(a, b) 
    {
        var valA = getCellValue(a, index), valB = getCellValue(b, index)
        return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB)
    }
}



///////////////////////////////////////////////////////////////////
/*
	Gets the value of a cell 
*/
///////////////////////////////////////////////////////////////////
function getCellValue(row, index)
{ 
	return $(row).children('td').eq(index).text() 
}




///////////////////////////////////////////////////////////////////
/*
	Creates a spinner and sets it's values
	http://heartcode.robertpataki.com/canvasloader/
*/
///////////////////////////////////////////////////////////////////
function createSpinner(name = "canvasloader-container")
{
	var cl = new CanvasLoader(name);
	cl.setColor('#3fd3fc');
	cl.setShape('spiral');
	cl.setDiameter(50);
	cl.setDensity(49);
	cl.setRange(0.4);
	cl.setFPS(23);
	return cl;
}


///////////////////////////////////////////////////////////////////
/*
	Shows payment notifications based on time due. 
*/
///////////////////////////////////////////////////////////////////
function showPaymentWarning(paymentTime)
{
	var now = Date.now();
	if (paymentTime < now)
	{
		showToast("<span style='color: #c62551;'>Your territory is no longer protected!</span><br>Pay your protection money immediately to avoid having your base deleted!", "warning", "Territory Payment");
	}
	else
	{
		// get total seconds between the times
		var seconds = Math.abs(paymentTime - now) / 1000;

		// calculate (and subtract) whole days
		var days = Math.floor(seconds / 86400);
		
		// Only show this message when we have less than 2 days remaining
		if (days < 2)
		{
			seconds -= days * 86400;

			// calculate (and subtract) whole hours
			var hours = Math.floor(seconds / 3600) % 24;
			seconds -= hours * 3600;

			// calculate (and subtract) whole minutes
			var minutes = Math.floor(seconds / 60) % 60;

			// Show it
			var timeLeft = days + " days " + hours + " hours and " + minutes + " minutes";
			showToast("You have<br><span style='color: #c62551;'>" + timeLeft + "</span><br>left until your protection money is due.<br><br>Consider paying ahead of time to avoid unintended consequences!", "warning", "Territory Payment");
		}
	}
}
All opinions represented herein are my own
- © 2024 itsthedevman
- build 3c15a1b