diff --git a/js/card.js b/js/card.js
index c8e5b223..585081af 100644
--- a/js/card.js
+++ b/js/card.js
@@ -200,36 +200,9 @@ export const card = (() => {
return inner;
};
- const fetchTracker = (comment) => {
- comment.comments.forEach((c) => {
- fetchTracker(c);
- });
-
- if (comment.ip === undefined || comment.user_agent === undefined || comment.is_admin || tracker.has(comment.ip)) {
- return;
- }
-
- fetch(`https://freeipapi.com/api/json/${comment.ip}`)
- .then((res) => res.json())
- .then((res) => {
- let result = res.cityName + ' - ' + res.regionName;
-
- if (res.cityName == '-' && res.regionName == '-') {
- result = 'localhost';
- }
-
- tracker.set(comment.ip, result);
- document.getElementById(`ip-${comment.uuid}`).innerHTML = `${util.escapeHtml(comment.ip)} ${result}`;
- })
- .catch((err) => {
- document.getElementById(`ip-${comment.uuid}`).innerHTML = `${util.escapeHtml(comment.ip)} ${util.escapeHtml(err.message)}`;
- });
- };
-
return {
renderEdit,
renderReply,
- fetchTracker,
renderLoading,
renderReadMore,
renderInnerContent,
diff --git a/js/comment.js b/js/comment.js
index 26577a4a..6560ea52 100644
--- a/js/comment.js
+++ b/js/comment.js
@@ -375,7 +375,7 @@ export const comment = (() => {
const observer = new MutationObserver((mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' && session.isAdmin()) {
- res.data.forEach(card.fetchTracker);
+ res.data.forEach(fetchTracker);
}
}
});
@@ -422,6 +422,32 @@ export const comment = (() => {
}
};
+ const fetchTracker = (comment) => {
+ comment.comments.forEach((c) => {
+ fetchTracker(c);
+ });
+
+ if (comment.ip === undefined || comment.user_agent === undefined || comment.is_admin || tracker.has(comment.ip)) {
+ return;
+ }
+
+ fetch(`https://freeipapi.com/api/json/${comment.ip}`)
+ .then((res) => res.json())
+ .then((res) => {
+ let result = res.cityName + ' - ' + res.regionName;
+
+ if (res.cityName == '-' && res.regionName == '-') {
+ result = 'localhost';
+ }
+
+ tracker.set(comment.ip, result);
+ document.getElementById(`ip-${comment.uuid}`).innerHTML = `${util.escapeHtml(comment.ip)} ${result}`;
+ })
+ .catch((err) => {
+ document.getElementById(`ip-${comment.uuid}`).innerHTML = `${util.escapeHtml(comment.ip)} ${util.escapeHtml(err.message)}`;
+ });
+ };
+
const scroll = () => document.getElementById('comments').scrollIntoView({ behavior: 'smooth' });
return {