Background
Functions
getNextOccurrenceFrom(timeStr, fromTimestamp) ⇒ number
| null
Calculates the next occurrence of a given time string strictly after a specified timestamp. Handles time strings in “HH:MM” format or ISO strings by extracting “HH:MM”. If the calculated time on the same day as fromTimestamp is in the past or same as fromTimestamp, it advances to the next day.
getNextWeeklyOccurrenceFrom(timeStr, daysOfWeek, fromTimestamp) ⇒ number
| null
Calculates the next weekly occurrence of a given time on specified days of the week, strictly after a specified timestamp. Handles time strings in “HH:MM” format or ISO strings by extracting “HH:MM”. It finds the earliest possible time across all specified daysOfWeek that is after fromTimestamp.
pruneClearedMissedAlarms(clearedList) ⇒ Array.<object>
Utility to prune cleared missed alarms older than a defined period (currently 30 days).
Filters an array of cleared missed alarm objects, removing entries whose clearedAt
timestamp is older than the pruning threshold relative to the current time.
checkMissedAlarmsOnStartup()
Checks for schedules that should have run while the extension was inactive (e.g., browser closed).
If missed alarms are enabled and found, it stores them in chrome.storage.local
and displays a notification to the user.
For recurring schedules, it identifies the latest missed instance.
createContextMenus()
Creates and configures context menus for the extension.
It sets up the following:
-
A parent menu “Add current page to Chronotab” (context:
page
) with options to: “Create New Schedule…” -
Add to existing schedules (if any are present).
-
A parent menu “Run Chronotab schedule now” (contexts:
action
,browser_action
,page
) with options to: Run existing schedules (if any are present). -
Shows “No schedules configured” (disabled) if none exist.
This function first removes all existing context menus to ensure a clean setup before recreating them.
Schedule data is fetched from chrome.storage.sync
to populate the menu items.
Typedefs
Alarm : object
Represents a Chrome alarm object used by the extension.
MessageRequest : object
Defines the structure of messages sent to the background script for various actions.
SendResponse : function
A callback function used to send a response to a message sender in Chrome extensions.
ContextMenuOnClickData : object
Provides information about the context menu item that was clicked.
Tab : object
Represents a browser tab in Chrome.
OnInstalledDetails : object
Contains details about the installation or update event of the extension.
StorageChange : object
Describes the change in a single storage item, as provided by chrome.storage.onChanged
.
StorageChanges : object.<string, StorageChange>
An object where each key is the name of a storage item that changed, and the value is a StorageChange object.
getNextOccurrenceFrom(timeStr, fromTimestamp) ⇒ number
| null
Calculates the next occurrence of a given time string strictly after a specified timestamp. Handles time strings in “HH:MM” format or ISO strings by extracting “HH:MM”. If the calculated time on the same day as fromTimestamp is in the past or same as fromTimestamp, it advances to the next day.
Kind: global function
Returns: number
| null
- The timestamp of the next occurrence, or null if the time string is invalid or calculation fails.
Param | Type | Description |
---|---|---|
timeStr | string | The time string, e.g., “14:30” or an ISO string like “2023-01-01T14:30:00”. |
fromTimestamp | number | The timestamp (milliseconds since epoch) from which to calculate the next occurrence. |
getNextWeeklyOccurrenceFrom(timeStr, daysOfWeek, fromTimestamp) ⇒ number
| null
Calculates the next weekly occurrence of a given time on specified days of the week, strictly after a specified timestamp. Handles time strings in “HH:MM” format or ISO strings by extracting “HH:MM”. It finds the earliest possible time across all specified daysOfWeek that is after fromTimestamp.
Kind: global function
Returns: number
| null
- The timestamp of the earliest next weekly occurrence, or null if inputs are invalid or no valid occurrence is found.
Param | Type | Description |
---|---|---|
timeStr | string | The time string, e.g., “14:30” or an ISO string. |
daysOfWeek | Array.<number> | An array of day numbers (0 for Sunday, 1 for Monday, …, 6 for Saturday). |
fromTimestamp | number | The timestamp (milliseconds since epoch) from which to calculate the next occurrence. |
pruneClearedMissedAlarms(clearedList) ⇒ Array.<object>
Utility to prune cleared missed alarms older than a defined period (currently 30 days).
Filters an array of cleared missed alarm objects, removing entries whose clearedAt
timestamp is older than the pruning threshold relative to the current time.
Kind: global function
Returns: Array.<object>
- A new array containing only the cleared missed alarm entries
that are within the 30-day retention period.
Param | Type | Description |
---|---|---|
clearedList | Array.<object> | Array of cleared missed alarm objects. Each object is expected to have a clearedAt property (timestamp in milliseconds). |
checkMissedAlarmsOnStartup()
Checks for schedules that should have run while the extension was inactive (e.g., browser closed).
If missed alarms are enabled and found, it stores them in chrome.storage.local
and displays a notification to the user.
For recurring schedules, it identifies the latest missed instance.
Kind: global function
createContextMenus()
Creates and configures context menus for the extension.
It sets up the following:
- A parent menu “Add current page to Chronotab” (context:
page
) with options to:- “Create New Schedule…”
- Add to existing schedules (if any are present).
- A parent menu “Run Chronotab schedule now” (contexts:
action
,browser_action
,page
) with options to:- Run existing schedules (if any are present).
- Shows “No schedules configured” (disabled) if none exist.
This function first removes all existing context menus to ensure a clean setup before recreating them.
Schedule data is fetched from chrome.storage.sync
to populate the menu items.
Kind: global function
Alarm : object
Represents a Chrome alarm object used by the extension.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
name | string | The name of the alarm, typically prefixed with a schedule ID. |
MessageRequest : object
Defines the structure of messages sent to the background script for various actions.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
action | string | The type of action to perform (e.g., “runMissedAlarm”, “clearMissedAlarmEntry”). |
[scheduleId] | string | The ID of the schedule, relevant for schedule-specific actions. |
[missedRunTime] | number | The specific timestamp of a missed run, used for clearing specific entries. |
SendResponse : function
A callback function used to send a response to a message sender in Chrome extensions.
Kind: global typedef
Param | Type | Description |
---|---|---|
[response] | any | The data to be sent as a response. |
ContextMenuOnClickData : object
Provides information about the context menu item that was clicked.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
menuItemId | \* | The ID of the menu item that was clicked. |
[pageUrl] | string | The URL of the page where the context menu was clicked. |
[linkUrl] | string | If the clicked item was a link, this is the URL of the link. |
[srcUrl] | string | If the clicked item was an image or video, this is its source URL. |
Tab : object
Represents a browser tab in Chrome.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[id] | number | The unique identifier for the tab. |
[url] | string | The URL the tab is displaying. |
OnInstalledDetails : object
Contains details about the installation or update event of the extension.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
reason | string | The reason for the event (e.g., “install”, “update”, “chrome_update”). |
[previousVersion] | string | The previous version of the extension, if it was updated. |
StorageChange : object
Describes the change in a single storage item, as provided by chrome.storage.onChanged
.
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
[oldValue] | \* | The old value of the item, if it existed before this change. |
[newValue] | \* | The new value of the item, if it was set or changed. |
StorageChanges : object.<string, StorageChange>
An object where each key is the name of a storage item that changed, and the value is a StorageChange object.
Kind: global typedef