Skip to content

Commit

Permalink
zh-cn: Format /web/api using Prettier (part 10)
Browse files Browse the repository at this point in the history
  • Loading branch information
queengooborg committed Jul 28, 2023
1 parent 09c0ef4 commit 4906f0b
Show file tree
Hide file tree
Showing 100 changed files with 2,309 additions and 1,947 deletions.
12 changes: 6 additions & 6 deletions files/zh-cn/web/api/subtlecrypto/unwrapkey/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function getKeyMaterial() {
enc.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
["deriveBits", "deriveKey"],
);
}

Expand All @@ -156,7 +156,7 @@ async function getUnwrappingKey() {
keyMaterial,
{ name: "AES-KW", length: 256 },
true,
["wrapKey", "unwrapKey"]
["wrapKey", "unwrapKey"],
);
}

Expand All @@ -178,7 +178,7 @@ async function unwrapSecretKey(wrappedKey) {
"AES-KW", // 加密密钥时使用的算法
"AES-GCM", // 解包密钥使用的算法
true, // 解包后的密钥的可导出性
["encrypt", "decrypt"] // 解包后的密钥的用途
["encrypt", "decrypt"], // 解包后的密钥的用途
);
}
```
Expand Down Expand Up @@ -314,7 +314,7 @@ function getKeyMaterial() {
enc.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
["deriveBits", "deriveKey"],
);
}

Expand All @@ -339,7 +339,7 @@ async function getUnwrappingKey() {
keyMaterial,
{ name: "AES-GCM", length: 256 },
true,
["wrapKey", "unwrapKey"]
["wrapKey", "unwrapKey"],
);
}

Expand Down Expand Up @@ -371,7 +371,7 @@ async function unwrapPrivateKey(wrappedKey) {
hash: "SHA-256",
},
true, // 解包后的密钥的可导出性
["sign"] // 解包后的密钥的用途
["sign"], // 解包后的密钥的用途
);
}
```
Expand Down
10 changes: 5 additions & 5 deletions files/zh-cn/web/api/subtlecrypto/verify/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function getMessageEncoding() {
*/
async function verifyMessage(publicKey) {
const signatureValue = document.querySelector(
".rsassa-pkcs1 .signature-value"
".rsassa-pkcs1 .signature-value",
);
signatureValue.classList.remove("valid", "invalid");

Expand All @@ -82,7 +82,7 @@ async function verifyMessage(publicKey) {
"RSASSA-PKCS1-v1_5",
publicKey,
signature,
encoded
encoded,
);

signatureValue.classList.add(result ? "valid" : "invalid");
Expand Down Expand Up @@ -122,7 +122,7 @@ async function verifyMessage(publicKey) {
},
publicKey,
signature,
encoded
encoded,
);

signatureValue.classList.add(result ? "valid" : "invalid");
Expand Down Expand Up @@ -162,7 +162,7 @@ async function verifyMessage(publicKey) {
},
publicKey,
signature,
encoded
encoded,
);

signatureValue.classList.add(result ? "valid" : "invalid");
Expand Down Expand Up @@ -199,7 +199,7 @@ async function verifyMessage(key) {
"HMAC",
key,
signature,
encoded
encoded,
);

signatureValue.classList.add(result ? "valid" : "invalid");
Expand Down
24 changes: 12 additions & 12 deletions files/zh-cn/web/api/subtlecrypto/wrapkey/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function getKeyMaterial() {
enc.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
["deriveBits", "deriveKey"],
);
}

Expand All @@ -111,7 +111,7 @@ function getKey(keyMaterial, salt) {
keyMaterial,
{ name: "AES-KW", length: 256 },
true,
["wrapKey", "unwrapKey"]
["wrapKey", "unwrapKey"],
);
}

Expand All @@ -137,7 +137,7 @@ window.crypto.subtle
length: 256,
},
true,
["encrypt", "decrypt"]
["encrypt", "decrypt"],
)
.then((secretKey) => wrapCryptoKey(secretKey))
.then((wrappedKey) => console.log(wrappedKey));
Expand All @@ -163,7 +163,7 @@ function getKeyMaterial() {
enc.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
["deriveBits", "deriveKey"],
);
}

Expand All @@ -181,7 +181,7 @@ function getKey(keyMaterial, salt) {
keyMaterial,
{ name: "AES-GCM", length: 256 },
true,
["wrapKey", "unwrapKey"]
["wrapKey", "unwrapKey"],
);
}

Expand Down Expand Up @@ -214,7 +214,7 @@ window.crypto.subtle
hash: "SHA-256",
},
true,
["sign", "verify"]
["sign", "verify"],
)
.then((keyPair) => wrapCryptoKey(keyPair.privateKey))
.then((wrappedKey) => {
Expand Down Expand Up @@ -242,7 +242,7 @@ function getKeyMaterial() {
enc.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
["deriveBits", "deriveKey"],
);
}

Expand All @@ -260,7 +260,7 @@ function getKey(keyMaterial, salt) {
keyMaterial,
{ name: "AES-CBC", length: 256 },
true,
["wrapKey", "unwrapKey"]
["wrapKey", "unwrapKey"],
);
}

Expand Down Expand Up @@ -293,7 +293,7 @@ window.crypto.subtle
hash: "SHA-256",
},
true,
["encrypt", "decrypt"]
["encrypt", "decrypt"],
)
.then((keyPair) => wrapCryptoKey(keyPair.publicKey))
.then((wrappedKey) => console.log(wrappedKey));
Expand All @@ -319,7 +319,7 @@ function getKeyMaterial() {
enc.encode(password),
{ name: "PBKDF2" },
false,
["deriveBits", "deriveKey"]
["deriveBits", "deriveKey"],
);
}

Expand All @@ -337,7 +337,7 @@ function getKey(keyMaterial, salt) {
keyMaterial,
{ name: "AES-GCM", length: 256 },
true,
["wrapKey", "unwrapKey"]
["wrapKey", "unwrapKey"],
);
}

Expand Down Expand Up @@ -367,7 +367,7 @@ window.crypto.subtle
namedCurve: "P-384",
},
true,
["sign", "verify"]
["sign", "verify"],
)
.then((keyPair) => wrapCryptoKey(keyPair.privateKey))
.then((wrappedKey) => console.log(wrappedKey));
Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/svgaelement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ See {{domxref("HTMLAnchorElement.href")}}
var linkRef = document.querySelector("a");
linkRef.target = "_self";

linkRef.onclick = function(){
linkRef.onclick = function () {
if (linkRef.target === "_blank") {
console.log("BLANK!");
linkRef.target = "_self";
} else {
console.log("SORRY! not _blank");
}
}
};
```

## 规范
Expand Down
6 changes: 3 additions & 3 deletions files/zh-cn/web/api/svgcircleelement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ slug: Web/API/SVGCircleElement

## 属性

| 名称 | 类型 | 描述 |
| ---- | -------------------------------------------- | -------------------------------------------------------------------------------- |
| 名称 | 类型 | 描述 |
| ---- | ---------------------------------- | ----------------------------------------------------------------- |
| `cx` | {{ domxref("SVGAnimatedLength") }} | 对应于给定{{ SVGElement("circle") }}元素的{{ SVGAttr("cx") }}属性 |
| `cy` | {{ domxref("SVGAnimatedLength") }} | 对应于给定{{ SVGElement("circle") }}元素的{{ SVGAttr("cy") }}属性 |
| `r` | {{ domxref("SVGAnimatedLength") }} | 对应于给定{{ SVGElement("circle") }}元素的{{ SVGAttr("r") }}属性 |
| `r` | {{ domxref("SVGAnimatedLength") }} | 对应于给定{{ SVGElement("circle") }}元素的{{ SVGAttr("r") }}属性 |

## 方法

Expand Down
10 changes: 5 additions & 5 deletions files/zh-cn/web/api/svgevent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ slug: Web/API/SVGEvent

## Properties

| Property | Type | Description |
| ------------------------------------- | ------------------------------------ | -------------------------- |
| Property | Type | Description |
| ------------------------------- | -------------------------- | -------------------------- |
| `target` {{readonlyInline}} | {{domxref("EventTarget")}} | 事件目标(DOM 树的最顶端) |
| `type` {{readonlyInline}} | {{domxref("DOMString")}} | 事件类型 |
| `bubbles` {{readonlyInline}} | {{jsxref("Boolean")}} | 事件是否冒泡 |
| `cancelable` {{readonlyInline}} | {{jsxref("Boolean")}} | 事件是否可取消 |
| `type` {{readonlyInline}} | {{domxref("DOMString")}} | 事件类型 |
| `bubbles` {{readonlyInline}} | {{jsxref("Boolean")}} | 事件是否冒泡 |
| `cancelable` {{readonlyInline}} | {{jsxref("Boolean")}} | 事件是否可取消 |
40 changes: 21 additions & 19 deletions files/zh-cn/web/api/svggraphicselement/getbbox/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,37 @@ The returned value is a [SVGRect](/zh-CN/docs/Web/API/SVGRect) object, which def

```html
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<g id="group_text_1">
<text x="5" y="16" transform="scale(2, 2)">Hello World!</text>
<text x="8" y="32" transform="translate(0 20) scale(1.25 1)">Hello World Again!</text>
</g>
<!-- Shows BBox in green -->
<rect id="rect_1" stroke="#00ff00" stroke-width="3" fill="none"> </rect>
<!-- Shows BoundingClientRect in red -->
<rect id="rect_2" stroke="#ff0000" stroke-width="3" fill="none"></rect>
<g id="group_text_1">
<text x="5" y="16" transform="scale(2, 2)">Hello World!</text>
<text x="8" y="32" transform="translate(0 20) scale(1.25 1)">
Hello World Again!
</text>
</g>
<!-- Shows BBox in green -->
<rect id="rect_1" stroke="#00ff00" stroke-width="3" fill="none"></rect>
<!-- Shows BoundingClientRect in red -->
<rect id="rect_2" stroke="#ff0000" stroke-width="3" fill="none"></rect>
</svg>
```

### JavaScript

```js
var rectBBox = document.querySelector('#rect_1');
var rectBoundingClientRect = document.querySelector('#rect_2');
var groupElement = document.querySelector('#group_text_1');
var rectBBox = document.querySelector("#rect_1");
var rectBoundingClientRect = document.querySelector("#rect_2");
var groupElement = document.querySelector("#group_text_1");

var bboxGroup = groupElement.getBBox();
rectBBox.setAttribute('x', bboxGroup.x);
rectBBox.setAttribute('y', bboxGroup.y);
rectBBox.setAttribute('width', bboxGroup.width);
rectBBox.setAttribute('height', bboxGroup.height);
rectBBox.setAttribute("x", bboxGroup.x);
rectBBox.setAttribute("y", bboxGroup.y);
rectBBox.setAttribute("width", bboxGroup.width);
rectBBox.setAttribute("height", bboxGroup.height);

var boundingClientRectGroup = groupElement.getBoundingClientRect();
rectBoundingClientRect.setAttribute('x', boundingClientRectGroup.x);
rectBoundingClientRect.setAttribute('y', boundingClientRectGroup.y);
rectBoundingClientRect.setAttribute('width', boundingClientRectGroup.width);
rectBoundingClientRect.setAttribute('height', boundingClientRectGroup.height);
rectBoundingClientRect.setAttribute("x", boundingClientRectGroup.x);
rectBoundingClientRect.setAttribute("y", boundingClientRectGroup.y);
rectBoundingClientRect.setAttribute("width", boundingClientRectGroup.width);
rectBoundingClientRect.setAttribute("height", boundingClientRectGroup.height);
```

## Specifications
Expand Down
4 changes: 2 additions & 2 deletions files/zh-cn/web/api/svgpathelement/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ slug: Web/API/SVGPathElement

## 属性

| 名称 | 类型 | 描述 |
| ------------ | -------------------------------------------- | ------------------------------------------------------------------------------------------ |
| 名称 | 类型 | 描述 |
| ------------ | ---------------------------------- | ------------------------------------------------------------------------- |
| `pathLength` | {{ domxref("SVGAnimatedNumber") }} | 对应于给定{{ SVGElement("path") }}元素的{{ SVGAttr("pathLength") }}属性。 |

## 方法
Expand Down
8 changes: 4 additions & 4 deletions files/zh-cn/web/api/text/splittext/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ newNode = textNode.splitText(offset)
### HTML

```html
<p id="p">foobar</p>
<p id="p">foobar</p>
```

### JavaScript

```js
const p = document.getElementById('p');
const p = document.getElementById("p");

// 将 <p> 的内容读取为一个文本节点
const foobar = p.firstChild;
Expand All @@ -55,8 +55,8 @@ const foobar = p.firstChild;
const bar = foobar.splitText(3);

// 创建一个包含了内容为 ' new content ' 的文本节点的 <u> 元素
const u = document.createElement('u');
u.appendChild(document.createTextNode(' new content '));
const u = document.createElement("u");
u.appendChild(document.createTextNode(" new content "));

// 将 <u> 元素插入到后一个文本节点 'bar' 的前面
p.insertBefore(u, bar);
Expand Down
24 changes: 15 additions & 9 deletions files/zh-cn/web/api/text/wholetext/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ str = textnode.wholeText;
假设你的网页上有如下的简单文本 (包括其中为了格式化代码而添加的一些空格), 其 DOM 节点 被储存在变量 `para` 中:

```html
<p>Thru-hiking is great! <strong>No insipid election coverage!</strong>
However, <a href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a
ballot</a> is tricky.</p>
<p>
Thru-hiking is great! <strong>No insipid election coverage!</strong> However,
<a href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a ballot</a> is
tricky.
</p>
```

你觉得你不喜欢中间的句子,所以你移除了它:
Expand All @@ -38,9 +40,11 @@ para.firstChild.data = "Thru-hiking is great, but ";
一切妥当,是么?_不!_ 这会使你移除 `strong` 元素,而被删掉的句子分隔了两个文本节点。一个是第一句,一个是最后一个单词。相反,你现在获得如下效果:

```html
<p>Thru-hiking is great, but However, <a
href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a
ballot</a> is tricky.</p>
<p>
Thru-hiking is great, but However,
<a href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a ballot</a> is
tricky.
</p>
```

实际上,你更倾向于将这些相邻扽文本节点作为同一文本节点。这就是 `wholeText` 的用武之地:如果你有许多相邻的文本节点,你可以通过`wholeText`访问这些节点里的所有内容。让我们假设你从未犯过最后一个错误。在这种情况下,我们有:
Expand All @@ -60,9 +64,11 @@ para.firstChild.replaceWholeText("Thru-hiking is great, but ");
我们移除了所有的相邻文本节点 (所有构成 whole text 的文本节点) 除了调用`replaceWholeText()` 的,并且把剩余的文本改成了新文本。我们现在所得到的是这样的:

```html
<p>Thru-hiking is great, but <a
href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a
ballot</a> is tricky.</p>
<p>
Thru-hiking is great, but
<a href="http://en.wikipedia.org/wiki/Absentee_ballot">casting a ballot</a> is
tricky.
</p>
```

有时候使用 whole-text 功能同时使用`Node.textContent` 或长期支持的 {{domxref("Element.innerHTML")}}; 可以得到更好的处理。如果你需要处理一个元素内的混合内容,正如本文所介绍的,`wholeText``replaceWholeText()` 是有用的。
Expand Down
Loading

0 comments on commit 4906f0b

Please sign in to comment.