# Spark +

**Version:** 2.1.0
**Author:** Linus Olofsson - Iver
**Platform:** Chromium-based browsers (Chrome, Edge, Brave)

---

## Overview

Spark + is a browser extension for Iver employees that integrates with the Spark ticketing system. It provides real-time ticket monitoring, status change notifications, SLA tracking, and time reporting directly from the browser toolbar.

---

## Project Structure

```
PROD-READY-SETUP/
|
|-- manifest.json                          # Extension manifest (Manifest V3)
|
|-- css/
|   |-- popup.css                          # All styles for the popup UI
|
|-- html/
|   |-- PopupUI.html                       # Main popup interface
|   |-- offscreen.html                     # Offscreen document for background tasks
|
|-- icons/
|   |-- Untitled-1 - 18-02-2026 23-08-51(2).png   # Main extension logo
|   |-- icon16.png                         # Small browser toolbar icon (16px)
|   |-- removeicon.png                     # Remove button icon for list items
|
|-- javascript/
|   |-- popup.js                           # Main popup entry point
|   |
|   |-- api/
|   |   |-- auth.js                        # Authentication and token management
|   |   |-- ssoAuth.js                     # SSO authentication via Microsoft
|   |   |-- ticketApi.js                   # Spark API client for ticket operations
|   |
|   |-- background/
|   |   |-- serviceWorker.js               # Background service worker (API, alarms, notifications)
|   |   |-- offscreen.js                   # Offscreen document logic
|   |
|   |-- common/
|   |   |-- storage.js                     # Chrome storage abstraction
|   |   |-- utils.js                       # Utility functions (date formatting, SLA calc)
|   |
|   |-- components/
|   |   |-- itemList.js                    # Ticket list rendering and detail modals
|   |   |-- modal.js                       # Generic modal management
|   |   |-- timer.js                       # Timer functionality
|   |
|   |-- contentScripts/
|   |   |-- sparkTokenReader.js            # Content script for reading Spark JWT tokens
|   |
|   |-- handlers/
|       |-- clearButton.js                 # Clear list button handler
|       |-- configButton.js                # Configuration modal handler
|       |-- notificationsButton.js         # Notification toggle handler
|       |-- teamsButton.js                 # Microsoft Teams integration handler
|       |-- timerButton.js                 # Timer settings handler
|       |-- updateButton.js                # Manual update button handler
```

---

## Table of Contents

- [Overview](#overview)
- [Project Structure](#project-structure)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Permissions](#permissions)
- [Changelog](#changelog)

---

## Prerequisites

- A Chromium-based browser (Google Chrome, Microsoft Edge, or Brave).
- An active Iver account with access to [Spark](https://spark.iver.com).

---

## Installation

1. Open your browser and navigate to the extensions page:
   - **Chrome:** `chrome://extensions/`
   - **Edge:** `edge://extensions/`
   - **Brave:** `brave://extensions/`
2. Enable **Developer mode** (toggle in the top-right corner).
3. Click **Load unpacked** and select the `PROD-READY-SETUP` folder.
4. Pin the Spark + icon in the browser toolbar for quick access.
5. Navigate to [spark.iver.com](https://spark.iver.com) and log in to activate automatic token retrieval.

---

## Permissions

The extension requires the following browser permissions:

| Permission       | Purpose                                              |
|------------------|------------------------------------------------------|
| `storage`        | Persist ticket data, settings, and timer state       |
| `activeTab`      | Interact with the currently active browser tab       |
| `scripting`      | Inject content scripts for token reading             |
| `tabs`           | Access tab information for navigation                |
| `alarms`         | Schedule periodic background updates                 |
| `notifications`  | Display desktop notifications on status changes      |
| `windows`        | Open popup windows for background update alerts      |
| `offscreen`      | Run background tasks via offscreen documents         |
| `identity`       | Support SSO authentication flows                     |

---

## Changelog

### 2.1.0 (2026-03-18)

- **Timer Minimum Reduced:** The minimum timer duration has been lowered from 5 minutes to 30 seconds. A new "Sekunder" (seconds) input field has been added to the timer settings modal, allowing precise sub-minute intervals.

### 2.0.9 (2026-03-18)

- **Custom Queue:** A new "Custom Queue" toggle has been added to the Configuration panel under "Appearance". When enabled, a multi-select list of all the user's SavedViews (queues) from Spark is displayed. The user can select which queues to monitor, replacing the default "My Tickets" search. Tickets from all selected queues are deduplicated and presented in the main list. Status change notifications and the "Uppdatera nu" button work identically for custom queue tickets. The setting is persisted in local storage.

### 2.0.8 (2026-03-16)

- **Title Override for Article Check:** A new dropdown has been added to the Configuration panel under "Notifications" that allows users to manually select their job title for time report article validation. This overrides the title provided by the JWT token, resolving cases where the token title does not match the user's actual role. A "Current Title" label displays the effective title being used. The override is persisted in local storage and takes priority over the JWT title in `checkArticleTimesheets`.

### 2.0.7 (2026-03-10)

- **Minimal Mode -- Button Text Overflow Fix:** The "Kontrollera min kö" button now correctly uses icon/text span elements instead of overwriting the entire button content. This prevents text from overflowing the button boundary in minimal mode.
- **Configuration Panel -- English Translation:** All configuration modal text has been translated to English, including section headers, toggle labels, button labels, and descriptions.
- **Configuration Panel -- Dark Theme:** The configuration modal background has been changed from white to the same dark gray used by the main popup, with all text colors adjusted for readability.
- **Minimal Mode -- Timer Countdown:** The timer button now displays a live countdown (MM:SS) in its icon slot when in minimal mode, making it visible that the timer is active and counting down.
- **Spark + Logo -- Linked:** The Spark + logo in both standard and minimal view is now clickable and links to `https://sparkplus.se/`.

### 2.0.6 (2026-03-09)

- **Bugfix -- Empty Queue Not Clearing List:** Resolved an issue where the last ticket in the list would persist in the popup even after the API confirmed zero active tickets. The `scrapedItems` storage is now explicitly cleared when the API returns an empty result set.
- **Timer Minimum Reduced:** The minimum timer duration has been lowered from 15 minutes to 5 minutes, allowing shorter recurring update intervals.
- **Improved Error Messages:** API errors caused by invalid or expired tokens (including `Unexpected token` JSON parse failures) now display a user-friendly message -- "Öppna Spark för att verifiera ditt token" -- instead of raw error text. The notification includes an **"Öppna Spark"** button for quick re-authentication.

### 2.0.4 (2026-03-06)

- **Actionable Notification Buttons:** All notifications that direct the user to a specific destination now include action buttons. Status change notifications are now created per ticket (instead of a single summary) with an **"Öppna ärende"** button that links directly to the affected ticket in Spark. Token-related notifications (`tokenMissing`, `tokenExpired`) and API error notifications include an **"Öppna Spark"** button that navigates to `spark.iver.com`. The background update fallback notification includes a **"Visa ärenden"** button that opens the extension popup. Both notification body clicks and button clicks route to the correct destination.

### 2.0.3 (2026-03-05)

- **Time Report Article Validation -- Architectural Overhaul:** The article validation logic has been extracted from the status-filtered ticket fetching flow into a standalone function (`checkArticleTimesheets`). The function performs its own API call to retrieve all tickets assigned to the user within the last seven days, regardless of ticket status. This resolves an issue where tickets with recently changed statuses (e.g., Resolved, Closed) were excluded from article validation before the user had a chance to correct the time report.
- **Notification Buttons -- Ignore and Fix:** Article mismatch notifications now include two action buttons. The **Ignore** button suppresses future notifications for the specified ticket by persisting the ticket ID in local storage. The **Fix** button opens the ticket directly in the Spark web interface for immediate correction.

- ## V2.0.2(2026-03-04)


Personlig hälsning på sparkplus.se: Tillägget skriver nu användarens namn till sparkplus.se via ett content script. Sidan visar en slumpmässig hälsning om ett namn hittas; i annat fall döljs elementet helt.
### 2.0.1 (2026-03-04)

- **Minimal View -- Cosmetic Fix:** Resolved an issue where toolbar buttons would stretch vertically to fill the available space when the ticket list was empty in minimal mode. The CSS Grid layout for `.container.minimal` now uses explicit `grid-template-rows: auto auto 1fr auto` to ensure the header row, button row, and config button maintain their natural height regardless of list content. Only the ticket list row expands to occupy remaining space.

### 2.0.0 (2026-03-04)

- Initial production release with Spark API integration, ticket monitoring, SLA tracking, status change notifications, timer, minimal view, ticket detail modal with latest updates, and time report article validation.
