Skip to main content

Functions

registerAlarms() ⇒ void

Registers all alarms for current schedules stored in chrome.storage.sync. This function performs the following steps:
    • Retrieves all schedules from chrome.storage.sync.
    • Updates the calculatedWhen property for any “once” schedules based on their specified time. If a “once” schedule’s time is in the past, calculatedWhen is removed. For non-”once” schedules, calculatedWhen is always removed.
    • Clears all existing Chrome alarms.
    • Creates new alarms based on the processed schedules: For “once” schedules, a single alarm is set at calculatedWhen if it’s valid and in the future, and if the schedule hasn’t already run (checked against lastRun).
    • For “daily” schedules, a repeating alarm is set for the next occurrence of schedule.time with a 24-hour period.
    • For “weekly” schedules, a repeating alarm is set for each specified dayOfWeek at schedule.time with a 7-day period. Unique alarm names are generated for each day of a weekly schedule (e.g., schedule.id + "-" + dow).
If calculatedWhen was added, modified, or removed for any schedule, the updated schedules are saved back to chrome.storage.sync. Errors during saving are logged to the console.

getNextOccurrence(timeStr) ⇒ number | null

Calculates the next occurrence timestamp (in milliseconds since epoch) for a given time string. The time string can be in “HH:mm” format or an ISO string (e.g., “YYYY-MM-DDTHH:mm”), from which “HH:mm” is extracted. If the calculated time for today has already passed, it returns the timestamp for that time tomorrow.

getNextWeeklyOccurrence(timeStr, dayOfWeek) ⇒ number | null

Calculates the next occurrence timestamp (in milliseconds since epoch) for a weekly schedule. It considers the provided time string and the target day of the week. The time string can be in “HH:mm” format or an ISO string (e.g., “YYYY-MM-DDTHH:mm”), from which “HH:mm” is extracted. If the target day is today but the time has passed, it schedules for the same day next week.

exportScheduleById(scheduleId) ⇒ Promise.<(string|null)>

Exports a single schedule as a JSON string.

importSchedule(scheduleJson) ⇒ Promise.<(Schedule|null)>

Imports a single schedule from a JSON string. Assigns a new unique ID to the imported schedule and removes any existing lastRun or calculatedWhen properties. The imported schedule is added to the existing list of schedules in chrome.storage.sync. After successfully saving, it re-registers all alarms.

exportAllSchedules() ⇒ Promise.<string>

Exports all schedules as a JSON string.

importAllSchedules(schedulesJson) ⇒ Promise.<(Array.<Schedule>|null)>

Imports multiple schedules from a JSON string, replacing all existing schedules in chrome.storage.sync. Assigns new unique IDs to all imported schedules and removes any existing lastRun or calculatedWhen properties. Basic validation is performed on each schedule; invalid schedules are skipped with a warning. After successfully saving, it re-registers all alarms.

onSchedulesChanged() ⇒ void

A utility function that calls registerAlarms. This is intended to be used as a callback or event handler when schedules are changed, ensuring that Chrome alarms are updated accordingly.

runSchedule(schedule) ⇒ void

Opens all URLs specified in a given schedule object in new Chrome tabs. If the schedule object is invalid, or if it contains no URLs, a warning is logged to the console.

Typedefs

Schedule : object

Represents a scheduling configuration for opening URLs.

registerAlarms() ⇒ void

Registers all alarms for current schedules stored in chrome.storage.sync. This function performs the following steps:
  1. Retrieves all schedules from chrome.storage.sync.
  2. Updates the calculatedWhen property for any “once” schedules based on their specified time. If a “once” schedule’s time is in the past, calculatedWhen is removed. For non-”once” schedules, calculatedWhen is always removed.
  3. Clears all existing Chrome alarms.
  4. Creates new alarms based on the processed schedules:
    • For “once” schedules, a single alarm is set at calculatedWhen if it’s valid and in the future, and if the schedule hasn’t already run (checked against lastRun).
    • For “daily” schedules, a repeating alarm is set for the next occurrence of schedule.time with a 24-hour period.
    • For “weekly” schedules, a repeating alarm is set for each specified dayOfWeek at schedule.time with a 7-day period. Unique alarm names are generated for each day of a weekly schedule (e.g., schedule.id + "-" + dow).
If calculatedWhen was added, modified, or removed for any schedule, the updated schedules are saved back to chrome.storage.sync. Errors during saving are logged to the console. Kind: global function
Returns: void - This function does not return a value directly but operates via side effects on Chrome alarms and storage.

getNextOccurrence(timeStr) ⇒ number | null

Calculates the next occurrence timestamp (in milliseconds since epoch) for a given time string. The time string can be in “HH:mm” format or an ISO string (e.g., “YYYY-MM-DDTHH:mm”), from which “HH:mm” is extracted. If the calculated time for today has already passed, it returns the timestamp for that time tomorrow. Kind: global function
Returns: number | null - The timestamp in milliseconds for the next occurrence, or null if the time string is invalid.

getNextWeeklyOccurrence(timeStr, dayOfWeek) ⇒ number | null

Calculates the next occurrence timestamp (in milliseconds since epoch) for a weekly schedule. It considers the provided time string and the target day of the week. The time string can be in “HH:mm” format or an ISO string (e.g., “YYYY-MM-DDTHH:mm”), from which “HH:mm” is extracted. If the target day is today but the time has passed, it schedules for the same day next week. Kind: global function
Returns: number | null - The timestamp in milliseconds for the next weekly occurrence, or null if inputs are invalid.

exportScheduleById(scheduleId) ⇒ Promise.<(string\|null)>

Exports a single schedule as a JSON string. Kind: global function
Returns: Promise.<(string\|null)> - A promise that resolves with the JSON string of the schedule, or null if not found.

importSchedule(scheduleJson) ⇒ Promise.<(Schedule\|null)>

Imports a single schedule from a JSON string. Assigns a new unique ID to the imported schedule and removes any existing lastRun or calculatedWhen properties. The imported schedule is added to the existing list of schedules in chrome.storage.sync. After successfully saving, it re-registers all alarms. Kind: global function
Returns: Promise.<(Schedule\|null)> - A promise that resolves with the imported schedule object (with new ID and cleaned properties) if successful, or null if parsing or validation fails. Rejects on storage error.

exportAllSchedules() ⇒ Promise.<string>

Exports all schedules as a JSON string. Kind: global function
Returns: Promise.<string> - A promise that resolves with the JSON string of all schedules.

importAllSchedules(schedulesJson) ⇒ Promise.<(Array.<Schedule>\|null)>

Imports multiple schedules from a JSON string, replacing all existing schedules in chrome.storage.sync. Assigns new unique IDs to all imported schedules and removes any existing lastRun or calculatedWhen properties. Basic validation is performed on each schedule; invalid schedules are skipped with a warning. After successfully saving, it re-registers all alarms. Kind: global function
Returns: Promise.<(Array.<Schedule>\|null)> - A promise that resolves with the array of successfully validated and imported schedule objects if successful, or null if the input is not an array or parsing fails. Rejects on storage error.

onSchedulesChanged() ⇒ void

A utility function that calls registerAlarms. This is intended to be used as a callback or event handler when schedules are changed, ensuring that Chrome alarms are updated accordingly. Kind: global function

runSchedule(schedule) ⇒ void

Opens all URLs specified in a given schedule object in new Chrome tabs. If the schedule object is invalid, or if it contains no URLs, a warning is logged to the console. Kind: global function

Schedule : object

Represents a scheduling configuration for opening URLs. Kind: global typedef
Properties