-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zh-CN: create
action.isEnabled()
(#22949)
Co-authored-by: A1lo <[email protected]>
- Loading branch information
1 parent
90daa90
commit 94f965f
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
files/zh-cn/mozilla/add-ons/webextensions/api/action/isenabled/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
--- | ||
title: action.isEnabled() | ||
slug: Mozilla/Add-ons/WebExtensions/API/action/isEnabled | ||
l10n: | ||
sourceCommit: b30a10c08b986ebabd44733fb62f67667350403e | ||
--- | ||
|
||
{{AddonSidebar}} | ||
|
||
如果浏览器操作已启用,则返回 `true`。 | ||
|
||
> [!NOTE] | ||
> 该 API 在 Manifest V3 或更高版本中可用。 | ||
这是一个返回 [`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise) 的异步函数。 | ||
|
||
## 语法 | ||
|
||
```js-nolint | ||
let gettingIsEnabled = browser.action.isEnabled( | ||
details // 对象 | ||
) | ||
``` | ||
|
||
### 参数 | ||
|
||
- `details` | ||
|
||
- : `object`。可选的包含要检查的 `tabId` 或 `windowId` 的对象。 | ||
|
||
- `tabId` {{optional_inline}} | ||
- : `integer`,指定要检查的标签页的 id。 | ||
- `windowId` {{optional_inline}} | ||
- : `integer`,指定要检查的窗口的 id。 | ||
|
||
<!----> | ||
|
||
- 若同时指定了 `windowId` 和 `tabId`,则函数出错。 | ||
- 若同时未指定 `windowId` 和 `tabId`,则返回全局的启用/禁用状态。 | ||
|
||
### 返回值 | ||
|
||
[`Promise`](/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Promise),如果浏览器操作已启用,则兑现 `true`,否则兑现 `false`。 | ||
|
||
## 示例 | ||
|
||
检查全局的启用状态: | ||
|
||
```js | ||
browser.action.isEnabled({}).then((result) => { | ||
console.log(result); | ||
}); | ||
``` | ||
|
||
检查当前活动标签页的启用状态: | ||
|
||
```js | ||
async function enabledInActiveTab() { | ||
let tabs = await browser.tabs.query({ | ||
currentWindow: true, | ||
active: true, | ||
}); | ||
let enabled = await browser.action.isEnabled({ | ||
tabId: tabs[0].id, | ||
}); | ||
console.log(enabled); | ||
} | ||
``` | ||
|
||
{{WebExtExamples}} | ||
|
||
## 浏览器兼容性 | ||
|
||
{{Compat}} |