Add visitor bot visibility toggle
This commit is contained in:
+15
-4
@@ -7,6 +7,7 @@ const state = {
|
||||
active: null,
|
||||
events: null,
|
||||
statusFilter: "active",
|
||||
hideBots: localStorage.getItem("mf_admin_hide_bots") !== "0",
|
||||
replyFiles: [],
|
||||
attentionTimer: null,
|
||||
attentionOn: false,
|
||||
@@ -167,6 +168,12 @@ $("#conversationFilter").addEventListener("change", () => {
|
||||
renderConversations();
|
||||
});
|
||||
|
||||
$("#hideBotsToggle").addEventListener("click", () => {
|
||||
state.hideBots = !state.hideBots;
|
||||
localStorage.setItem("mf_admin_hide_bots", state.hideBots ? "1" : "0");
|
||||
renderVisitors();
|
||||
});
|
||||
|
||||
$("#conversationList").addEventListener("click", async (event) => {
|
||||
const photoButton = event.target.closest("[data-photo-url]");
|
||||
const openButton = event.target.closest("[data-open]");
|
||||
@@ -326,14 +333,18 @@ function renderConversations() {
|
||||
}
|
||||
|
||||
function renderVisitors() {
|
||||
$("#visitorCount").textContent = `${state.visitors.length} online`;
|
||||
$("#visitorList").innerHTML = state.visitors.length ? state.visitors.map((visitor) => `
|
||||
<article class="visitor-card ${visitor.lastConversationId ? "clickable" : ""}" data-visitor-conversation="${escapeHtml(visitor.lastConversationId || "")}">
|
||||
const visitors = state.hideBots ? state.visitors.filter((visitor) => !visitor.isBot) : state.visitors;
|
||||
const botCount = state.visitors.filter((visitor) => visitor.isBot).length;
|
||||
$("#hideBotsToggle").classList.toggle("active", state.hideBots);
|
||||
$("#hideBotsToggle").textContent = state.hideBots ? "Skryt boty" : "Boty videt";
|
||||
$("#visitorCount").textContent = `${visitors.length} online${state.hideBots && botCount ? ` · ${botCount} bot` : ""}`;
|
||||
$("#visitorList").innerHTML = visitors.length ? visitors.map((visitor) => `
|
||||
<article class="visitor-card ${visitor.lastConversationId ? "clickable" : ""} ${visitor.isBot ? "bot" : ""}" data-visitor-conversation="${escapeHtml(visitor.lastConversationId || "")}">
|
||||
<div class="visitor-card-head">
|
||||
<span class="visitor-avatar">${escapeHtml(visitor.initials || "??")}</span>
|
||||
<div>
|
||||
<strong>${escapeHtml(visitor.label || "Navstevnik")}</strong>
|
||||
<small>${escapeHtml(browserLabel(visitor.device))}</small>
|
||||
<small>${escapeHtml(visitor.isBot ? `bot: ${visitor.botReason || "crawler"}` : browserLabel(visitor.device))}</small>
|
||||
</div>
|
||||
<span class="online-dot" title="Online"></span>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user