# 始める

{% hint style="info" %} <mark style="color:blue;">**これは、古いバージョンのnonstressのドキュメントです。次のURLから、nonstressの最新版を使うことを推奨します。**</mark>[<mark style="color:blue;">**https://nonstress.mintlify.app/**</mark>](https://nonstress.mintlify.app/)
{% endhint %}

## Scriptタグを追加する

以下のタグをあなたのページのhtmlに追加してください。

```javascript
<script src="https://hamutan86.pythonanywhere.com/nonstress/nonstress.js" async defer></script><script src="https://hamutan86.pythonanywhere.com/nonstress/nonstress.js" async defer></script>
```

## トークンを取得する

サーバーサイドでリクエストの安全性を確認するには「トークン」が必要です。トークンはユーザーがページを開いたときに自動で作成されます。

トークンの準備ができたら`nonstressCompleted`イベントが発火します。言葉で言うよりも見るほうがわかりやすいので、このコード例を見てみてください。

```javascript
document.addEventListener("nonstressCompleted", (e) => {
    console.log(e.detail.success); // true|false
    console.log(e.detail.token); // "0dc240c66802f7329a1cb9f85804c49f6bb34a..."
});
```

`e.detail.token`がトークンです。nonstressが失敗したら`e.detail.success`がfalseになります。その時は、ページを再読み込みさせるか、[nonstress.generateToken()](#tkunwosuru-1) を使用してください。\
\
イベント発火時でなくても、以下のように直接トークンを取得することもできます。

```javascript
nonstress.getToken(); // "0dc240c66802f7329a1cb9f85804c49f6bb34a..."
```

とてもシンプルですね。この場合、nonstressがまだ完了していない、あるいは失敗したときは空のStringが返ってきます。

## トークンを再生成する

ユーザーがパスワードを間違えたり、アクションをキャンセルしたり、あるいはnonstressに失敗した？一度認証したトークンは使いまわせません。でも、nonstressのためにページを再読み込みさせる必要はありません。

```javascript
nonstress.generateToken()
```

これにより、トークンの再生成が行われ、イベントはもう一度発火し、nonstress.getToken()も新しいトークンを返してくれます。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nonstress.gitbook.io/nonstress-docs/ja/meru.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
