feat: add option to set agent name(s) with Regular Expression (#1)

Agent names can now be set either explicitly like before, or with a regular expression.

Reviewed-on: https://codeberg.org/vlw/freshdesk-filters/pulls/1
Co-authored-by: vlw <victor@vlw.se>
Co-committed-by: vlw <victor@vlw.se>
This commit is contained in:
Victor Westerlund 2025-10-14 10:42:40 +02:00 committed by Victor Westerlund
parent d0563e1edb
commit 0a7a9b676a
5 changed files with 42 additions and 7 deletions

View file

@ -13,14 +13,17 @@ This extension provides the following functionality:
### Open ticket by clicking the whole table column
Tickets can be opened by clicking anywhere inside the subject column, not just on the link itself.
### (Optional) Agent name(s)
Current agent name or names can be defined explicitly or with a regular expression.
### (Optional) Open ticket in a new tab
Open tickets in a new tab instead of navigating to the ticket directly.
### (Optional) Dim tickets not assigned to current agent
Tickets not assigned to the current agent will be dimmed.
### (Optional) Dim tickets not assigned to current agent(s)
Tickets not assigned to the current agent(s) will be dimmed.
### (Optional) Move tickets assigned to current agent to the top
> [!WARNING]
> This feature is kind of broken at the moment.
Tickets assigned to the current agent will be placed at the top of the tickets table.
Tickets assigned to the current agent(s) will be placed at the top of the tickets table.

View file

@ -9,4 +9,10 @@ body {
label {
user-select: none;
}
form {
hr {
opacity: .1;
}
}
}

View file

@ -19,6 +19,10 @@ document.querySelectorAll("input").forEach(async inputElement => {
// Fetch setting value from browser storage by input field name
const value = (await chrome.storage.sync.get([inputElement.name]))[inputElement.name];
if (!value) {
return;
}
switch (inputElement.type) {
case "checkbox":
return inputElement.checked = value === "true";

View file

@ -2,6 +2,7 @@ const CONFIG = {
AGENT_NAME : "agent_name",
DIM_NOT_ASSIGNED : "is_dim_not_assigned",
OPEN_TICKET_NEW_TAB : "is_open_ticket_new_tab",
AGENT_NAME_REGEX : "is_agent_name_regex",
MOVE_ASSIGNED_TO_TOP : "is_move_assigned_to_top",
// Resolve config value
@ -131,9 +132,16 @@ class FreshdeskFilters {
// Dim tickets not assigned to this agent is enabled
if (await CONFIG.get(CONFIG.DIM_NOT_ASSIGNED) === "true") {
tableRowElement.classList.remove(CLASSNAME.DIM_NOT_ASSIGNED);
// Check if this ticket is assigned to this agent
const isCurrentAgent = await CONFIG.get(CONFIG.AGENT_NAME_REGEX) !== "true"
// An agent name is explicitly defined
? ticketAgentName === agentName
// Agent name(s) are defined with RegEx
: new RegExp(agentName).test(ticketAgentName);
// This ticket is not assigned to this agent
if (ticketAgentName !== AGENT_UNASSIGNED && ticketAgentName !== agentName) {
if (!isCurrentAgent && ticketAgentName !== AGENT_UNASSIGNED) {
tableRowElement.classList.add(CLASSNAME.DIM_NOT_ASSIGNED);
}
}

View file

@ -20,13 +20,27 @@
<h5>My name</h5>
<input type="text" name="agent_name" placeholder="Nisse Hult">
</label>
<label class="my-1">
<input type="checkbox" name="is_agent_name_regex">
Use Regular Expression
</label>
</div>
</div>
<hr>
<div class="row my-2 g-3">
<div>
<label class="my-1"><input type="checkbox" name="is_open_ticket_new_tab">Open tickets in a new tab</label>
<label class="my-1"><input type="checkbox" name="is_dim_not_assigned">Dim tickets that are not assigned to me</label>
<label class="my-1"><input type="checkbox" name="is_move_assigned_to_top">Move tickets assigned to me to the top</label>
<label class="my-1">
<input type="checkbox" name="is_open_ticket_new_tab">
Open tickets in a new tab
</label>
<label class="my-1">
<input type="checkbox" name="is_dim_not_assigned">
Dim tickets that are not assigned to me
</label>
<label class="my-1">
<input type="checkbox" name="is_move_assigned_to_top">
Move tickets assigned to me to the top
</label>
</div>
</div>
<div class="mt-3">