Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryohidaka/chrome-alarms
Helper for chrome.alarms API.
https://github.com/ryohidaka/chrome-alarms
alarm chrome ext extension extensions
Last synced: about 2 months ago
JSON representation
Helper for chrome.alarms API.
- Host: GitHub
- URL: https://github.com/ryohidaka/chrome-alarms
- Owner: ryohidaka
- License: mit
- Created: 2024-01-27T07:01:56.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-04-08T07:57:57.000Z (9 months ago)
- Last Synced: 2024-04-08T08:57:53.355Z (9 months ago)
- Topics: alarm, chrome, ext, extension, extensions
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/chrome-alarms
- Size: 544 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# chrome-alarms
[![npm version](https://badge.fury.io/js/chrome-alarms.svg)](https://badge.fury.io/js/chrome-alarms)
![build](https://github.com/ryohidaka/chrome-alarms/workflows/Build/badge.svg)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/B0B6TVH92)
## Overview
Helper for `chrome.alarms` API.
## Notes
To use the `chrome.alarms` API, declare the `"alarms"` permission in the [manifest](https://developer.chrome.com/docs/extensions/reference/manifest):
```json
{
"name": "My extension","permissions": ["alarms"]
}
```## Installation
You can install this library using npm:
```shell
npm install chrome-alarms
```## Properties
| Key | Type | Optional | Description |
| ----------------- | ------ | -------- | --------------------------------------------------------------------------------------------- |
| `name` | string | | Name of this alarm. |
| `periodInMinutes` | number | ◯ | If not null, the alarm is a repeating alarm and will fire again in `periodInMinutes` minutes. |## Methods
### `create`
Creates an alarm. If there is another alarm with the same name (or no name if none is specified), it will be cancelled and replaced by this alarm.
```typescript
import { Alarm } from "chrome-alarms";const name = "test";
const periodInMinutes = 1;await Alarm.create(name, periodInMinutes);
```### `clear`
Clears the alarm with the given name.
```typescript
import { Alarm } from "chrome-alarms";const name = "test";
await Alarm.clear(name);
```### `clearAll`
Clears all alarms.
```typescript
import { Alarm } from "chrome-alarms";await Alarm.clearAll();
```### `get`
Retrieves details about the specified alarm.
```typescript
import { Alarm } from "chrome-alarms";const name = "test";
const alarm = await Alarm.get(name);
console.log(alarm);// Output: Object{ name: "test", periodInMinutes: 1, scheduledTime: 1706435598914.826 }
```### `getAll`
Gets an array of all the alarms.
```typescript
import { Alarm } from "chrome-alarms";const alarms = await Alarm.getAll();
console.log(alarms);// Output: Array[{ name: "test", periodInMinutes: 1, scheduledTime: 1706435598914.826 }]
```### `onAlarm`
Fired when an alarm has elapsed. Useful for event pages.
```typescript
import { Alarm } from "chrome-alarms";Alarm.onAlarm((alarm) => {
console.log(alarm);
});// Output: Object{ name: "test", periodInMinutes: 1, scheduledTime: 1706435598914.826 }
```## Link
- [chrome.alarms](https://developer.chrome.com/docs/extensions/reference/api/alarms)
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.