Skip to content

Commit 99abb3b

Browse files
nickytonlinefregante
authored andcommitted
Add TypeScript definition (#6)
1 parent c7e0d3a commit 99abb3b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

index.d.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/// <reference types="firefox-webext-browser" />
2+
3+
/**
4+
* Same as `addToTab`, but it will automatically listen to new tabs and inject the scripts as needed.
5+
*
6+
* @param contentScripts {string[]} An array of content scripts.
7+
*/
8+
export function addToFutureTabs(contentScripts?: string[]): Promise<void>;
9+
10+
/**
11+
* This is an advanced version of `chrome.tabs.executeScript`/`chrome.tabs.insertCSS`:
12+
* - It accepts a mixed JS/CSS object just like in `manifest.json`.
13+
*
14+
* @param tab {browser.tabs.Tab|number} Tab or tab ID to add the content scripts to.
15+
* @param contentScripts {string[]} An array of content scripts.
16+
*
17+
* @example
18+
* DCS.addToTab(tab, {
19+
* run_at: 'document_start',
20+
* all_frames: true,
21+
* css: [
22+
* 'content.css'
23+
* ],
24+
* js: [
25+
* 'webext-dynamic-content-scripts.js',
26+
* 'jquery.slim.min.js',
27+
* 'browser-polyfill.min.js',
28+
* 'content.js'
29+
* ]
30+
* // Not supported: all matches and globs properties
31+
* });
32+
*/
33+
export function addToTab(tab: browser.tabs.Tab|number, contentScripts?: string[]): Promise<void>;

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"main": "dist/webext-dynamic-content-scripts.js",
2222
"files": [
2323
"src",
24-
"dist"
24+
"dist",
25+
"index.d.ts"
2526
],
2627
"scripts": {
2728
"watch:xo": "onchange 'src/*.js' --initial -- xo --fix",
@@ -40,6 +41,7 @@
4041
"webext-content-script-ping": "^2.0.1"
4142
},
4243
"devDependencies": {
44+
"@types/firefox-webext-browser": "^65.0.0",
4345
"onchange": "^3.2.0",
4446
"rollup": "^0.41.6",
4547
"rollup-config-webext": "^1.1.0",

0 commit comments

Comments
 (0)