From 2b761271c8d82c748fa200640611144f9efa442d Mon Sep 17 00:00:00 2001 From: Alexander Danilov Date: Sat, 26 Oct 2024 16:12:45 +0500 Subject: [PATCH] Using `IITC.utils.formatAgo` instead of the plugins own function --- plugins/machina-tracker.js | 27 ++++++++++++--------------- plugins/player-activity-tracker.js | 21 +++++++-------------- 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/plugins/machina-tracker.js b/plugins/machina-tracker.js index ac0be87ce..23bf4bfb2 100644 --- a/plugins/machina-tracker.js +++ b/plugins/machina-tracker.js @@ -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'], @@ -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 $('') .addClass('text-overflow-ellipsis') @@ -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; @@ -199,7 +192,11 @@ machinaTracker.drawData = function () { linkList.appendTo(popup); event.to.forEach((to) => { - $('
  • ').append(machinaTracker.createPortalLink(to)).append(' ').append(machinaTracker.ago(to.time, now)).appendTo(linkList); + $('
  • ') + .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 }); diff --git a/plugins/player-activity-tracker.js b/plugins/player-activity-tracker.js index 9c39f909d..373d783d4 100644 --- a/plugins/player-activity-tracker.js +++ b/plugins/player-activity-tracker.js @@ -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'], @@ -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(); @@ -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';