aboutsummaryrefslogtreecommitdiff
path: root/files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html')
-rw-r--r--files/ja/mozilla/add-ons/add-on_manager/code_samples/index.html75
1 files changed, 75 insertions, 0 deletions
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
+---
+<h2 id="Getting_the_directory_where_your_addon_is_located" name="Getting_the_directory_where_your_addon_is_located">アドオンが格納されているディレクトリの取得</h2>
+
+<p>あなたのアドオンがインストールされているディレクトリを確認する必要がある場合、次の様なトリックを用います。コード中の <var>YOUREXTENSIONID</var> はあなたのアドオンの ID で置き換えてください。</p>
+
+<pre class="brush: js">Components.utils.import("resource://gre/modules/<code><a href="/ja/Add-ons/Add-on_Manager" title="Add-on Manager">AddonManager.jsm</a></code>");
+
+<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager" title="AddonManager">AddonManager</a></code>.<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager#getAddonByID()" title="AddonManager.getAddonByID()">getAddonByID</a></code>("YOUREXTENSIONID", function(addon) {
+ var addonLocation = addon.<code><a href="/ja/Add-ons/Add-on_Manager/Addon#getResourceURI()" title="Addon.getResourceURI()">getResourceURI</a></code>("").QueryInterface(Components.interfaces.{{ Interface( "nsIFileURL" ) }}).file.path;
+});
+</pre>
+
+<h2 id="Accessing_file_and_version_information" name="Accessing_file_and_version_information">ファイルとバージョン情報へのアクセス</h2>
+
+<pre class="brush: js">Components.utils.import("resource://gre/modules/<code><a href="/ja/Add-ons/Add-on_Manager" title="Add-on Manager">AddonManager.jsm</a></code>");
+
+<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager" title="AddonManager">AddonManager</a></code>.<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager#getAddonByID()" title="AddonManager.getAddonByID()">getAddonByID</a></code>("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.<code><a href="/ja/Add-ons/Add-on_Manager/Addon#hasResource()" title="Addon.hasResource()">hasResource</a></code>("file.txt") ? "YES!" : "No");
+ alert("Let's pretend I did, it's available from the URL " + addon.<code><a href="/ja/Add-ons/Add-on_Manager/Addon#getResourceURI()" title="Addon.getResourceURI()">getResourceURI</a></code>("file.txt").spec);
+});
+</pre>
+
+<h2 id="Uninstall_an_addon" name="Uninstall_an_addon">アドオンの削除</h2>
+
+<pre class="brush: js">Components.utils.import("resource://gre/modules/<code><a href="/ja/Add-ons/Add-on_Manager" title="Add-on Manager">AddonManager.jsm</a></code>");
+
+<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager" title="AddonManager">AddonManager</a></code>.<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager#getAddonByID()" title="AddonManager.getAddonByID()">getAddonByID</a></code>("youraddon@youraddon.com", function(addon) {
+ addon.<code><a href="/ja/Add-ons/Add-on_Manager/Addon#uninstall()" title="Addon.uninstall()">uninstall</a></code>();
+});
+</pre>
+
+<h2 id="Disable_an_addon" name="Disable_an_addon">アドオンの無効化</h2>
+
+<pre class="brush: js">Components.utils.import("resource://gre/modules/<code><a href="/ja/Add-ons/Add-on_Manager" title="Add-on Manager">AddonManager.jsm</a></code>");
+<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager" title="AddonManager">AddonManager</a></code>.<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager#getAddonByID()" title="AddonManager.getAddonByID()">getAddonByID</a></code>("youraddon@youraddon.com", function(addon) {
+ if (addon.isActive) addon.userDisabled = addon.isActive;
+});
+</pre>
+
+<h2 id="Listening_for_addon_uninstall" name="Listening_for_addon_uninstall">アドオンのアンインストールのリスニング</h2>
+
+
+<p>以下の例では、アドオンのアンインストール時にクリーンアップを実行する profile-before-change メッセージを取得する際に確認することができる変数 "beingUninstalled" を設定しています。</p>
+
+
+<pre class="brush: js">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.<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager#Pending_operations" title="AddonManager.pendingOperations">pendingOperations</a></code> &amp; AddonManager.PENDING_UNINSTALL) != 0;
+ }
+ }
+}
+
+try {
+ Components.utils.import("resource://gre/modules/<code><a href="/ja/Add-ons/Add-on_Manager" title="Add-on Manager">AddonManager.jsm</a></code>");
+
+ <code><a href="/ja/Add-ons/Add-on_Manager/AddonManager" title="AddonManager">AddonManager</a></code>.<code><a href="/ja/Add-ons/Add-on_Manager/AddonManager#addAddonListener()" title="AddonManager.addAddonListener()">addAddonListener</a></code>(listener);
+} catch (ex) {}
+</pre>