From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/storagemanager/estimate/index.html | 82 ++++++++++++++++++++++ files/zh-cn/web/api/storagemanager/index.html | 42 +++++++++++ .../web/api/storagemanager/persist/index.html | 53 ++++++++++++++ .../web/api/storagemanager/persisted/index.html | 53 ++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 files/zh-cn/web/api/storagemanager/estimate/index.html create mode 100644 files/zh-cn/web/api/storagemanager/index.html create mode 100644 files/zh-cn/web/api/storagemanager/persist/index.html create mode 100644 files/zh-cn/web/api/storagemanager/persisted/index.html (limited to 'files/zh-cn/web/api/storagemanager') diff --git a/files/zh-cn/web/api/storagemanager/estimate/index.html b/files/zh-cn/web/api/storagemanager/estimate/index.html new file mode 100644 index 0000000000..6f094fa705 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/estimate/index.html @@ -0,0 +1,82 @@ +--- +title: StorageManager.estimate() +slug: Web/API/StorageManager/estimate +translation_of: Web/API/StorageManager/estimate +--- +

{{securecontext_header}}{{APIRef("Storage")}}

+ +

estimate()方法是{{domxref("StorageManager")}}的一个接口,用于估算某一个域名(或一个站点)下Storage Manager的总存储空间和已经使用了的存储空间。此方法为一个异步方法,如果此方法可用,那么其返回一个结果为resolved的{{jsxref("Promise")}}对象。resolved接收的参数是一个带有已使用数据存储空间和总可用总存储空间的{{domxref("StorageEstimate")}}对象。

+ +

语法

+ +
var estimatePromise = StorageManager.estimate();
+ +

参数

+ +

+ +

返回值

+ +

{{domxref('StorageEstimate')}}类型的状态为resolved的{{jsxref('Promise')}}

+ +

此数据包含了此应用(或域名)可用的存储空间({{domxref("StorageEstimate.quota")}})和目前已经使用了的存储空间({{domxref("StorageEstimate.usage")}})。

+ +

这些值不是明确的数字,在进行压缩,重复数据删除和出于安全原因起见进行了混淆之后,这个数据是不精确的。

+ +

你可能会发现不同的应用或站点分配的存储空间不同,具体取决于用户访问频率,和网站受欢迎程度等数据。

+ +

示例

+ +

在这个示例中,我们使用estimate()得到目前所使用的存储空间占全部存储空间的百分比。

+ +

HTML 内容

+ +
<p>
+  You're currently using about <span id="percent">
+  </span>% of your available storage.
+</p>
+
+ +

JavaScript 内容

+ +
navigator.storage.estimate().then(function(estimate) {
+  document.getElementById("percent").innerHTML =
+      (estimate.usage / estimate.quota * 100).toFixed(2);
+});
+
+ +

结果

+ +

{{ EmbedLiveSample('Example', 600, 40) }}

+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Storage','#dom-storagemanager-estimate','estimate()')}}{{Spec2('Storage')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.StorageManager.estimate")}}

+ +

参见

+ + diff --git a/files/zh-cn/web/api/storagemanager/index.html b/files/zh-cn/web/api/storagemanager/index.html new file mode 100644 index 0000000000..83676931c2 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/index.html @@ -0,0 +1,42 @@ +--- +title: StorageManager +slug: Web/API/StorageManager +translation_of: Web/API/StorageManager +--- +

{{securecontext_header}}{{SeeCompatTable}}{{APIRef("Storage")}}

+ +

Storage APIStorageManager接口提供了用于管理数据本地存储权限和估算可用存储空间的接口。 您可以使用{{domxref("navigator.storage")}}或{{domxref("WorkerNavigator.storage")}}对此接口进行引用。

+ +

方法

+ +
+
{{domxref("StorageManager.estimate()")}} {{securecontext_inline}}
+
返回一个{{domxref("StorageEstimate")}}对象,此对象包含为你的域名预留的存储空间总大小和你已经使用的存储空间大小。
+
{{domxref("StorageManager.persist()")}} {{securecontext_inline}}
+
如果您的user agent能够将你域名下的数据持久保存,那么将返回一个状态为resolve的{{jsxref('Promise')}}
+
{{domxref("StorageManager.persisted()")}} {{securecontext_inline}}
+
如果您的站点已经被授予可使用数据本地存储的权限,则返回一个状态为resolve的{{jsxref('Promise')}}
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Storage','#storagemanager','StorageManger')}}{{Spec2('Storage')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.StorageManager")}}

diff --git a/files/zh-cn/web/api/storagemanager/persist/index.html b/files/zh-cn/web/api/storagemanager/persist/index.html new file mode 100644 index 0000000000..2f778b9832 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/persist/index.html @@ -0,0 +1,53 @@ +--- +title: StorageManager.persist() +slug: Web/API/StorageManager/persist +translation_of: Web/API/StorageManager/persist +--- +

{{securecontext_header}}{{APIRef("Storage")}}{{SeeCompatTable}}

+ +

persist()方法是{{domxref("StorageManager")}}的一个接口,用于请求本地数据存储的权限,如果被授予权限,则返回一个resolved状态值为true的{{jsxref('Promise')}}对象,否则返回false

+ +

语法

+ +
navigator.storage.persist().then(function(persistent) { ... })
+ +

参数

+ +

+ +

返回值

+ +

一个resolved状态,值为{{jsxref('Boolean')}}类型的{{jsxref('Promise')}}对象。

+ +

示例

+ +
if (navigator.storage && navigator.storage.persist)
+  navigator.storage.persist().then(function(persistent) {
+    if (persistent)
+      console.log("Storage will not be cleared except by explicit user action");
+    else
+      console.log("Storage may be cleared by the UA under storage pressure.");
+  });
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Storage','#dom-storagemanager-persist','persist')}}{{Spec2('Storage')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.StorageManager.persist")}}

diff --git a/files/zh-cn/web/api/storagemanager/persisted/index.html b/files/zh-cn/web/api/storagemanager/persisted/index.html new file mode 100644 index 0000000000..0e3c7c4711 --- /dev/null +++ b/files/zh-cn/web/api/storagemanager/persisted/index.html @@ -0,0 +1,53 @@ +--- +title: StorageManager.persisted() +slug: Web/API/StorageManager/persisted +translation_of: Web/API/StorageManager/persisted +--- +

{{securecontext_header}}{{APIRef("Storage")}}{{SeeCompatTable}}

+ +

persisted()方法是{{domxref("StorageManager")}}的一个接口,如果盒存储模式(box mode)的值为 “persistent” 则返回一个resolved状态值为true的{{jsxref('Promise')}}。

+ +

语法

+ +
navigator.storage.persisted().then(function(persistent) { ... })
+ +

参数

+ +

+ +

返回值

+ +

一个状态为resolved,值为{{jsxref('Boolean')}}类型的{{jsxref('Promise')}}。

+ +

示例

+ +
if (navigator.storage && navigator.storage.persist)
+  navigator.storage.persisted().then(function(persistent) {
+    if (persistent)
+      console.log("Storage will not be cleared except by explicit user action");
+    else
+      console.log("Storage may be cleared by the UA under storage pressure.");
+  });
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Storage','#dom-storagemanager-persisted','persisted')}}{{Spec2('Storage')}}Initial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("api.StorageManager.persisted")}}

-- cgit v1.2.3-54-g00ecf