Skip to content

Commit

Permalink
Using IITC.utils.formatAgo instead of the plugins own function
Browse files Browse the repository at this point in the history
  • Loading branch information
modos189 committed Nov 10, 2024
1 parent c16f591 commit 2b76127
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
27 changes: 12 additions & 15 deletions plugins/machina-tracker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// @name Machina tracker
// @author McBen
// @category Layer
// @version 1.0.1
// @version 1.1.0
// @description Show locations of Machina activities

/* exported setup, changelog --eslint */
/* global L */
/* global IITC, L */

var changelog = [
{
version: '1.1.0',
changes: ['Using `IITC.utils.formatAgo` instead of the plugin own function'],
},
{
version: '1.0.1',
changes: ['Version upgrade due to a change in the wrapper: plugin icons are now vectorized'],
Expand Down Expand Up @@ -146,17 +150,6 @@ machinaTracker.processNewData = function (data) {
});
};

machinaTracker.ago = function (time, now) {
var s = (now - time) / 1000;
var h = Math.floor(s / 3600);
var m = Math.floor((s % 3600) / 60);
var returnVal = m + 'm';
if (h > 0) {
returnVal = h + 'h' + returnVal;
}
return returnVal + ' ago';
};

machinaTracker.createPortalLink = function (portal) {
return $('<a>')
.addClass('text-overflow-ellipsis')
Expand Down Expand Up @@ -188,7 +181,7 @@ machinaTracker.drawData = function () {
var ageBucket = Math.min((now - event.time) / split, 3);
var position = event.from.latLng;

var title = isTouchDev ? '' : machinaTracker.ago(event.time, now);
var title = isTouchDev ? '' : IITC.utils.formatAgo(event.time, now) + ' ago';
var icon = machinaTracker.icon;
var opacity = 1 - 0.2 * ageBucket;

Expand All @@ -199,7 +192,11 @@ machinaTracker.drawData = function () {
linkList.appendTo(popup);

event.to.forEach((to) => {
$('<li>').append(machinaTracker.createPortalLink(to)).append(' ').append(machinaTracker.ago(to.time, now)).appendTo(linkList);
$('<li>')
.append(machinaTracker.createPortalLink(to))
.append(' ')
.append(IITC.utils.formatAgo(to.time, now) + ' ago')
.appendTo(linkList);
});

var m = L.marker(position, { icon: icon, opacity: opacity, desc: popup[0], title: title });
Expand Down
21 changes: 7 additions & 14 deletions plugins/player-activity-tracker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// @author breunigs
// @name Player activity tracker
// @category Layer
// @version 0.13.2
// @version 0.14.0
// @description Draw trails for the path a user took onto the map based on status messages in COMMs. Uses up to three hours of data. Does not request chat data on its own, even if that would be useful.

/* exported setup, changelog --eslint */
/* global L -- eslint */
/* global IITC, L -- eslint */

var changelog = [
{
version: '0.14.0',
changes: ['Using `IITC.utils.formatAgo` instead of the plugin own function'],
},
{
version: '0.13.2',
changes: ['Refactoring: fix eslint'],
Expand Down Expand Up @@ -274,17 +278,6 @@ window.plugin.playerTracker.getLatLngFromEvent = function (ev) {
return L.latLng(lats / ev.latlngs.length, lngs / ev.latlngs.length);
};

window.plugin.playerTracker.ago = function (time, now) {
var s = (now - time) / 1000;
var h = Math.floor(s / 3600);
var m = Math.floor((s % 3600) / 60);
var returnVal = m + 'm';
if (h > 0) {
returnVal = h + 'h' + returnVal;
}
return returnVal;
};

window.plugin.playerTracker.drawData = function () {
var isTouchDev = window.isTouchDevice();

Expand Down Expand Up @@ -314,7 +307,7 @@ window.plugin.playerTracker.drawData = function () {

var evtsLength = playerData.events.length;
var last = playerData.events[evtsLength - 1];
var ago = window.plugin.playerTracker.ago;
const ago = IITC.utils.formatAgo;

// tooltip for marker - no HTML - and not shown on touchscreen devices
var tooltip = isTouchDev ? '' : plrname + ', ' + ago(last.time, now) + ' ago';
Expand Down

0 comments on commit 2b76127

Please sign in to comment.