From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../add-ons/add-on_manager/code_samples/index.html | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html (limited to 'files/ja/mozilla/add-ons/add-on_manager/code_samples') diff --git a/files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html b/files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html new file mode 100644 index 0000000000..0cc6c7b6ee --- /dev/null +++ b/files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html @@ -0,0 +1,75 @@ +--- +title: コードの実例 +slug: Mozilla/Add-ons/Add-on_Manager/Code_Samples +tags: + - Add-on Manager + - Add-ons +translation_of: Mozilla/JavaScript_code_modules/Add-on_Manager/Code_Samples +--- +

アドオンが格納されているディレクトリの取得

+ +

あなたのアドオンがインストールされているディレクトリを確認する必要がある場合、次の様なトリックを用います。コード中の YOUREXTENSIONID はあなたのアドオンの ID で置き換えてください。

+ +
Components.utils.import("resource://gre/modules/AddonManager.jsm");
+
+AddonManager.getAddonByID("YOUREXTENSIONID", function(addon) {
+  var addonLocation = addon.getResourceURI("").QueryInterface(Components.interfaces.{{ Interface( "nsIFileURL" ) }}).file.path;
+});
+
+ +

ファイルとバージョン情報へのアクセス

+ +
Components.utils.import("resource://gre/modules/AddonManager.jsm");
+
+AddonManager.getAddonByID("my-addon@foo.com", function(addon) {
+  alert("My extension's version is " + addon.version);
+  alert("Did I remember to include that file.txt file in my XPI? " +
+        addon.hasResource("file.txt") ? "YES!" : "No");
+  alert("Let's pretend I did, it's available from the URL " + addon.getResourceURI("file.txt").spec);
+});
+
+ +

アドオンの削除

+ +
Components.utils.import("resource://gre/modules/AddonManager.jsm");
+
+AddonManager.getAddonByID("youraddon@youraddon.com", function(addon) {
+  addon.uninstall();
+});
+
+ +

アドオンの無効化

+ +
Components.utils.import("resource://gre/modules/AddonManager.jsm");
+AddonManager.getAddonByID("youraddon@youraddon.com", function(addon) {
+  if (addon.isActive) addon.userDisabled = addon.isActive;
+});
+
+ +

アドオンのアンインストールのリスニング

+ + +

以下の例では、アドオンのアンインストール時にクリーンアップを実行する profile-before-change メッセージを取得する際に確認することができる変数 "beingUninstalled" を設定しています。

+ + +
var beingUninstalled;
+
+let listener = {
+  onUninstalling: function(addon) {
+    if (addon.id == "youraddon@youraddon.com") {
+      beingUninstalled = true;
+    }
+  },
+  onOperationCancelled: function(addon) {
+    if (addon.id == "youraddon@youraddon.com") {
+      beingUninstalled = (addon.pendingOperations & AddonManager.PENDING_UNINSTALL) != 0;
+    }
+  }
+}
+
+try {
+  Components.utils.import("resource://gre/modules/AddonManager.jsm");
+
+  AddonManager.addAddonListener(listener);
+} catch (ex) {}
+
-- cgit v1.2.3-54-g00ecf