Skip to content

Commit

Permalink
feat: move method
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Oct 5, 2024
1 parent f47d8b6 commit bd899c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
27 changes: 0 additions & 27 deletions js/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<i class="fa-solid fa-location-dot me-1"></i>${util.escapeHtml(comment.ip)} <strong>${result}</strong>`;
})
.catch((err) => {
document.getElementById(`ip-${comment.uuid}`).innerHTML = `<i class="fa-solid fa-location-dot me-1"></i>${util.escapeHtml(comment.ip)} <strong>${util.escapeHtml(err.message)}</strong>`;
});
};

return {
renderEdit,
renderReply,
fetchTracker,
renderLoading,
renderReadMore,
renderInnerContent,
Expand Down
28 changes: 27 additions & 1 deletion js/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down Expand Up @@ -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)) {

Check failure on line 430 in js/comment.js

View workflow job for this annotation

GitHub Actions / analyze-code

'tracker' is not defined
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);

Check failure on line 443 in js/comment.js

View workflow job for this annotation

GitHub Actions / analyze-code

'tracker' is not defined
document.getElementById(`ip-${comment.uuid}`).innerHTML = `<i class="fa-solid fa-location-dot me-1"></i>${util.escapeHtml(comment.ip)} <strong>${result}</strong>`;
})
.catch((err) => {
document.getElementById(`ip-${comment.uuid}`).innerHTML = `<i class="fa-solid fa-location-dot me-1"></i>${util.escapeHtml(comment.ip)} <strong>${util.escapeHtml(err.message)}</strong>`;
});
};

const scroll = () => document.getElementById('comments').scrollIntoView({ behavior: 'smooth' });

return {
Expand Down

0 comments on commit bd899c3

Please sign in to comment.