Skip to content

Commit

Permalink
Filter on activity on the enemy list.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKleineKobini committed Nov 26, 2024
1 parent a0ec1bc commit 48bae7f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 2 additions & 1 deletion extension/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
{
"message": "Only show seconds in the oc timer and faction oc timer when there is less than an hour left.",
"contributor": "DeKleineKobini"
}
},
{ "message": "Filter on activity on the enemy list.", "contributor": "DeKleineKobini" }
],
"removed": [
{ "message": "Removed bazaar prices from the popup, as they are set to be removed from the API.", "contributor": "DeKleineKobini" },
Expand Down
30 changes: 29 additions & 1 deletion extension/scripts/features/enemy-filter/ttEnemyFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@
class: "content",
});

const activityFilter = createFilterSection({
type: "Activity",
defaults: filters.enemies.activity,
callback: () => applyFilters(true),
});
filterContent.appendChild(activityFilter.element);
localFilters["Activity"] = { getSelections: activityFilter.getSelections };

const statusFilter = createFilterSection({
title: "Status",
checkboxes: [
Expand Down Expand Up @@ -114,6 +122,7 @@

// Get the set filters
const content = findContainer("Enemy Filter", { selector: "main" });
const activity = localFilters["Activity"].getSelections(content);
const status = localFilters["Status"].getSelections(content);
const levels = localFilters["Level Filter"].getStartEnd(content);
const levelStart = parseInt(levels.start);
Expand All @@ -130,6 +139,7 @@
await ttStorage.change({
filters: {
enemies: {
activity,
status,
levelStart,
levelEnd,
Expand All @@ -140,7 +150,7 @@

// Actual Filtering
for (const row of document.findAll("ul.user-info-blacklist-wrap > li")) {
filterRow(row, { status, level: { start: levelStart, end: levelEnd }, statsEstimates }, false);
filterRow(row, { activity, status, level: { start: levelStart, end: levelEnd }, statsEstimates }, false);
}

triggerCustomListener(EVENT_CHANNELS.FILTER_APPLIED);
Expand All @@ -153,6 +163,24 @@
}

function filterRow(row, filters, individual) {
if (filters.activity) {
if (
filters.activity.length &&
!filters.activity.some(
(x) =>
x.trim() ===
row
.find("#iconTray li")
.getAttribute("title")
.match(/(?<=<b>).*(?=<\/b>)/g)[0]
.toLowerCase()
.trim()
)
) {
hide("activity");
return;
}
}
if (filters.status?.length && filters.status.length !== 2) {
let status = row.find(".status :last-child").textContent.toLowerCase().trim();

Expand Down
1 change: 1 addition & 0 deletions extension/scripts/global/globalData.js
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@ const DEFAULT_STORAGE = {
},
},
enemies: {
activity: new DefaultSetting({ type: "array", defaultValue: [] }),
status: new DefaultSetting({ type: "array", defaultValue: [] }),
levelStart: new DefaultSetting({ type: "number", defaultValue: 1 }),
levelEnd: new DefaultSetting({ type: "number", defaultValue: 100 }),
Expand Down

0 comments on commit 48bae7f

Please sign in to comment.