Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Enabling the behavior - updating the status periodically

これで Tinderbox のステータスを取得してアイコンを更新するコードができたので、それを定期的に実行するようにしましょう。

function loadTinderboxStatus() {
  gXMLHttpRequest = new XMLHttpRequest();
  gXMLHttpRequest.onload = updateTinderboxStatus;
  gXMLHttpRequest.open("GET", "https://tinderbox.mozilla.org/SeaMonkey/panel.html");
  gXMLHttpRequest.send(null);
  window.setTimeout(loadTinderboxStatus, 60000);
}

window.setTimeout(loadTinderboxStatus, 1000);

window.setTimeout は、指定された関数を一定時間後に実行させます。これを loadTinderboxStatus 関数の中で使い、この関数を スタートアップの 1 秒後 (1,000 ミリ秒) とその後 1 分毎 (60,000 ミリ秒) に実行するようにします。これで、ユーザは Tinderbox サーバに負荷をあまりかけず、かつ Mozilla がリクエストのせいで遅くならずに、比較的多く Tinderbox の更新ができるようになります。

我々のコードはこれで動くようになりましたが、Mozilla はこのコードについて何も知りません。この機能を有効にするには、外見を指定する で我々の CSS のコードへの参照を navigator.xul に追加したのと同様に、navigator.xul に我々の JavaScript のコードの参照を加えます。tinderstatus.js という名前の JavaScript のコードを navigator.xul と同じディレクトリに置き、navigator.xul の他の JavaScript スクリプトを参照している所に tinderstatus.js も参照させるようにします。

...

<!-- Navigator -->
<script type="application/x-javascript"
      src="chrome://navigator/content/browser.js"/>
<script type="application/x-javascript"
      src="chrome://navigator/content/navigator.js"/>
<script type="application/x-javascript"
      src="chrome://navigator/content/navigatorDD.js"/>
<script type="application/x-javascript"
      src="chrome://navigator/content/sessionHistoryUI.js"/>

<script type="application/x-javascript"
      src="chrome://navigator/content/tinderstatus.js"/>

<!-- hook for stringbundle overlays -->

...

この変更を行い、Mozilla を再起動すれば、Tinderbox ステータスパネルに 現在の Tinderbox の状態が表示されるはずです。Tinderbox に行き、パネルがアクティブな Tinderbox クライアントの現在の状態のうち最悪のものを表示しているか確かめてください。

ドキュメントのタグと貢献者

タグ: 
 このページの貢献者: Kohei
 最終更新者: Kohei,