From a065e04d529da1d847b5062a12c46d916408bf32 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 21:46:22 -0500 Subject: update based on https://github.com/mdn/yari/issues/2028 --- .../mozilla/add-ons/add-on_debugger/index.html | 78 --- .../mozilla/add-ons/add-on_guidelines/index.html | 117 ---- files/zh-tw/mozilla/add-ons/amo/index.html | 9 - files/zh-tw/mozilla/add-ons/amo/policy/index.html | 21 - .../index.html" | 24 - .../add-ons/firefox_for_android/api/index.html | 30 -- .../mozilla/add-ons/firefox_for_android/index.html | 70 --- files/zh-tw/mozilla/add-ons/sdk/builder/index.html | 13 - files/zh-tw/mozilla/add-ons/sdk/guides/index.html | 115 ---- .../sdk/high-level_apis/context-menu/index.html | 588 --------------------- .../mozilla/add-ons/sdk/high-level_apis/index.html | 10 - files/zh-tw/mozilla/add-ons/sdk/index.html | 82 --- .../mozilla/add-ons/sdk/low-level_apis/index.html | 20 - .../mozilla/add-ons/themes/obsolete/index.html | 10 - 14 files changed, 1187 deletions(-) delete mode 100644 files/zh-tw/mozilla/add-ons/add-on_debugger/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/add-on_guidelines/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/amo/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/amo/policy/index.html delete mode 100644 "files/zh-tw/mozilla/add-ons/amo/policy/\350\201\257\347\265\241\350\263\207\350\250\212/index.html" delete mode 100644 files/zh-tw/mozilla/add-ons/firefox_for_android/api/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/firefox_for_android/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/sdk/builder/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/sdk/guides/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/sdk/high-level_apis/context-menu/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/sdk/high-level_apis/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/sdk/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/sdk/low-level_apis/index.html delete mode 100644 files/zh-tw/mozilla/add-ons/themes/obsolete/index.html (limited to 'files/zh-tw/mozilla/add-ons') diff --git a/files/zh-tw/mozilla/add-ons/add-on_debugger/index.html b/files/zh-tw/mozilla/add-ons/add-on_debugger/index.html deleted file mode 100644 index 2b3106d6af..0000000000 --- a/files/zh-tw/mozilla/add-ons/add-on_debugger/index.html +++ /dev/null @@ -1,78 +0,0 @@ ---- -title: 附加元件除錯工具箱 -slug: Mozilla/Add-ons/Add-on_Debugger -translation_of: 'https://extensionworkshop.com/documentation/develop/debugging/' ---- -

{{AddonSidebar}}

- -

附加元件除錯工具箱提供 Firefox 工具箱中的部分工具,能在附加元件的作用範圍中除錯:

- - - -

需要重新啟動瀏覽器的 XUL overlay 附加元件無法使用附加元件除錯工具箱,這類的元件請使用瀏覽器工具箱

- -

請看這段影片,快速認識附加元件除錯工具箱:

- -

{{EmbedYouTube("KU3Xsck7qy0")}}

- -

啟用附加元件除錯工具箱

- -
-

如欲啟用附加元件除錯工具箱,您必須啟用 Firefox 裡的「啟用瀏覽器 chrome 與附加元件除錯工具箱」及「啟用遠端除錯」兩項設定。您可開啟網頁工具箱裡的設定,而後在「進階設定」一區中啟用上述選項。

-
- -

開啟附加元件除錯工具箱

- -

註:如前所述,附加元件除錯工具是專供不需重新啟動、以 SDK 製作的附加元件使用。若想為其他類型的附加元件除錯,請使用瀏覽器工具箱裡的工具。

- -

Now open the Add-on Manager. Next to the entry for your add-on you will see a button labeled "Debug". Click this button to launch the debugger.

- -

Next you'll see a dialog asking you to accept an incoming connection. Click "OK", and the debugger will start in a separate window. Note that sometimes the debugger window is hidden by the main Firefox window.

- -

{{EmbedYouTube("DvNpUVJcG_E")}}

- -

使用附加元件除錯工具

- -

The Add-on Debugger looks and behaves very much like the Browser Toolbox, except that while the scope of the Browser Toolbox is the whole browser, the Add-on Debugger is focused on the specific add-on for which you launched it. Like the Browser Toolbox, a toolbar along the top lets you switch between a number of different tools. In Firefox 31 there's only one such tool, the JavaScript Debugger, but with Firefox 32 you also get the Console and Scratchpad.

- -

JavaScript 除錯器

- -

This behaves just like the normal JavaScript Debugger, except its scope is the add-on rather than a web page. On the left-hand side it lists JavaScript sources:

- - - -

Content scripts

- -

Content scripts are only listed if and when they are loaded. So, if your Add-on loads a content script with contentScriptFile, the file will not appear in the debugger sources until you go to a page that loads the content script.

- -

If you set a breakpoint in a content script, it will not be active for instances of the content script which are loaded after the breakpoint is set.

- -

For example, suppose you have an add-on that attaches a content script to every tab the user loads. The content script adds a click handler to the page. As soon as you open a tab, this content script will be listed in the debugger. If you then set a breakpoint in the content script's click handler, then execution will pause whenever you click the page. But if you open a new tab, there are now two instances of the content script, and the breakpoint will not be enabled for the second instance You'll need to set a new breakpoint now if you want to it work for the second instance.

- -

We're investigating improvements to this in bug 1016046.

- -

主控台

- -

The Console behaves just like the Web Console, but its scope is the add-on rather than the web page.

- -

However, note that it actually runs in the context of the add-on's bootstrap.js, which may not be what you expect if your add-on uses the SDK: you won't see any objects defined in your add-on's main.js, and you won't see require() either. This issue is being tracked as bug 1005193.

- -

You can execute Console statements in the context of main.js while execution is paused inside main.js.

- -

程式碼速記本

- -

The Scratchpad behaves just like the normal Scratchpad, but its scope is the add-on rather than the web page.

- -

Like the Console, the add-on Scratchpad runs in the context of the add-on's bootstrap.js even if the add-on uses the SDK, and as with the Console you can execute Scratchpad code in the context of main.js while execution is paused inside main.js.

- -

為 chrome: 或 about: 頁面除錯

- -

從 Firefox 37 起,一般的除錯工具已經可以用來為 chrome: 及 about: 兩類頁面除錯,使用方法同一般網頁除錯。

diff --git a/files/zh-tw/mozilla/add-ons/add-on_guidelines/index.html b/files/zh-tw/mozilla/add-ons/add-on_guidelines/index.html deleted file mode 100644 index fe05866a87..0000000000 --- a/files/zh-tw/mozilla/add-ons/add-on_guidelines/index.html +++ /dev/null @@ -1,117 +0,0 @@ ---- -title: Add-on guidelines -slug: Mozilla/Add-ons/Add-on_guidelines -translation_of: 'https://extensionworkshop.com/documentation/publish/add-on-policies/' ---- -

These add-on guidelines were created to foster an open and diverse add-on developer community while ensuring an excellent user experience. They apply to all add-ons and add-on updates regardless of where they are hosted, and also apply to customizations performed by installers that configure Firefox without using an add-on. Add-ons hosted on AMO are subject to additional policies.

-

Be Transparent

- -

Be Respectful to Users

- -

Be Safe

- -

Be Stable

- -

Exceptions

- -

Other exceptions may apply.

-

Enforcement

-

Add-ons that do not follow these guidelines may qualify for blocklisting, depending on the extent of the violations. Guidelines qualified with the word - - must - are especially important, and violations thereof will most likely result in a blocklisting nomination.

-

The Add-ons Team will do their best to contact the add-on's developers and provide a reasonable time frame for the problems to be corrected before a block is put in place. If an add-on is considered malicious or its developers have proven unreachable or unresponsive, or in case of repeat violations, blocklisting may be immediate.

-

Guideline violations should be reported via Bugzilla, under Tech Evangelism > Add-ons. Questions can be posted in the #addons IRC channel.

-

These guidelines may change in the future. All updates will be announced in the Add-ons Blog.

diff --git a/files/zh-tw/mozilla/add-ons/amo/index.html b/files/zh-tw/mozilla/add-ons/amo/index.html deleted file mode 100644 index 3857ed65ca..0000000000 --- a/files/zh-tw/mozilla/add-ons/amo/index.html +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: AMO -slug: Mozilla/Add-ons/AMO -tags: - - NeedsTranslation - - TopicStub -translation_of: Mozilla/Add-ons/AMO ---- -

Content to be added.

diff --git a/files/zh-tw/mozilla/add-ons/amo/policy/index.html b/files/zh-tw/mozilla/add-ons/amo/policy/index.html deleted file mode 100644 index 8ac1738387..0000000000 --- a/files/zh-tw/mozilla/add-ons/amo/policy/index.html +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: AMO 政策 -slug: Mozilla/Add-ons/AMO/Policy -tags: - - NeedsTranslation - - TopicStub -translation_of: Mozilla/Add-ons/AMO/Policy ---- -

{{AddonSidebar}}

- -

Mozilla 致力於確保套件的用戶與開發者,都有著良好的體驗。提交套件以前,請閱讀以下政策。

- -
-
Developer Agreement
-
Effective January 5, 2016
Review Process
-
Add-ons extend the core capabilities of Firefox, allowing users to modify and personalize their Web experience. A healthy add-on ecosystem, built on trust, is vital for developers to be successful and users to feel safe making Firefox their own. For these reasons, Mozilla requires all add-ons to comply with the following set of policies on acceptable practices. The below is not intended to serve as legal advice, nor is it intended to serve as a comprehensive list of terms to include in your add-on’s privacy policy.
Featured Add-ons
-
How up-and-coming add-ons become featured and what's involved in the process.
聯絡我們 - -

如何就這些套件的政策,與我們取得聯繫

- -
diff --git "a/files/zh-tw/mozilla/add-ons/amo/policy/\350\201\257\347\265\241\350\263\207\350\250\212/index.html" "b/files/zh-tw/mozilla/add-ons/amo/policy/\350\201\257\347\265\241\350\263\207\350\250\212/index.html" deleted file mode 100644 index 7358e5f642..0000000000 --- "a/files/zh-tw/mozilla/add-ons/amo/policy/\350\201\257\347\265\241\350\263\207\350\250\212/index.html" +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: 附加元件聯絡資訊 -slug: Mozilla/Add-ons/AMO/Policy/聯絡資訊 -translation_of: Mozilla/Add-ons#Contact_us ---- -

誠摯的感謝您連絡 Mozilla 附加元件團隊,淺請先閱讀本頁說明以確保您的訊息被正確的遞送。

- -

附加元件支援服務

- -

若你需要特定附加元件的支援訊息,比如說 "我該如何使用這個附加元件?" 或 "它怎麼不能...?",請透過列於附加元建列表中的聯絡方式,聯絡該附加元件的開發者。

- -

附加元件編輯者審閱

- -

若你有任何關於某個附加元件的編輯者審閱(Editor's review)的疑問,或想回報政策違反,請 E-mail 至 amo-editors@mozilla.orgAlmost all add-on reports fall under this category. Please be sure to include a link to the add-on in question and a detailed description of your question or comment.

- -

Add-on Security Vulnerabilities

- -

If you have discovered a security vulnerability in an add-on, even if it is not hosted here, Mozilla is very interested in your discovery and will work with the add-on developer to correct the issue as soon as possible. Add-on security issues can be reported confidentially in Bugzilla or by emailing amo-admins@mozilla.org.

- -

Website Functionality & Development

- -

If you've found a problem with the site, we'd love to fix it. Please file a bug report in Bugzilla, including the location of the problem and how you encountered it.

- -

How to get in touch with us regarding these policies or your add-on.

diff --git a/files/zh-tw/mozilla/add-ons/firefox_for_android/api/index.html b/files/zh-tw/mozilla/add-ons/firefox_for_android/api/index.html deleted file mode 100644 index a8e6ebf9e0..0000000000 --- a/files/zh-tw/mozilla/add-ons/firefox_for_android/api/index.html +++ /dev/null @@ -1,30 +0,0 @@ ---- -title: API -slug: Mozilla/Add-ons/Firefox_for_Android/API -tags: - - NeedsTranslation - - TopicStub -translation_of: Archive/Add-ons/Legacy_Firefox_for_Android/API ---- -

There are a couple of differences between desktop Firefox and Firefox for Android that are particularly relevant to add-on developers:

- - - -

Instead, Firefox for Android provides its own APIs:

- - - -

In these pages we've documented the main functions and properties exposed by these objects. To see all the details, refer to the code at browser.js.

diff --git a/files/zh-tw/mozilla/add-ons/firefox_for_android/index.html b/files/zh-tw/mozilla/add-ons/firefox_for_android/index.html deleted file mode 100644 index 8ade48ff37..0000000000 --- a/files/zh-tw/mozilla/add-ons/firefox_for_android/index.html +++ /dev/null @@ -1,70 +0,0 @@ ---- -title: Extensions for Firefox for Android -slug: Mozilla/Add-ons/Firefox_for_Android -tags: - - NeedsTranslation - - TopicStub -translation_of: Archive/Add-ons/Legacy_Firefox_for_Android ---- -

Firefox for Android supports add-ons using the same extension system used by all other Gecko-based applications. You can use the Add-on SDK or build manually bootstrapped restartless add-ons. You can even develop traditional restart-required add-ons, although the other two approaches are preferable.

- -

Add-ons that work with desktop Firefox do not automatically work in Firefox for Android:

- - - -

The following articles provide help with developing extensions for Firefox on Android. In addition, please refer to the general extension documentation that applies to all Mozilla applications.

- -
-
-

Tutorials

- -
-
Walkthrough
-
Developing, packaging and installing a simple add-on for Firefox for Android.
-
Firefox Hub Walkthrough
-
How to develop a Firefox Hub add-on to add content to the Firefox for Android home page.
-
Add-on SDK
-
How to develop Firefox for Android add-ons using the Add-on SDK.
-
- -

Sample code

- -
-
Code Snippets
-
Code samples for common tasks.
-
Initialization and Cleanup
-
How to initialize your add-on when it is started and clean up when it is shut down.
-
Firefox for Android Add-ons Github Repo
-
A collection of JS modules, sample code, and boilerplate repos to help you build add-ons for Firefox for Android.
-
-
- -
-

API reference

- -
-
NativeWindow
-
Create native Android UI widgets.
-
BrowserApp
-
Access browser tabs and the web content they host.
-
Prompt.jsm
-
Show native Android dialogs.
-
HelperApps.jsm
-
Query and launch native apps installed on the system.
-
Notifications.jsm
-
Use extended properties for Android system notifications.
-
Home.jsm
-
Customize the home page.
-
HomeProvider.jsm
-
Store data to display on the home page.
-
 
-
-
-
- -

 

diff --git a/files/zh-tw/mozilla/add-ons/sdk/builder/index.html b/files/zh-tw/mozilla/add-ons/sdk/builder/index.html deleted file mode 100644 index f7dc93a009..0000000000 --- a/files/zh-tw/mozilla/add-ons/sdk/builder/index.html +++ /dev/null @@ -1,13 +0,0 @@ ---- -title: Builder -slug: Mozilla/Add-ons/SDK/Builder -translation_of: Archive/Add-ons/Add-on_SDK/Builder ---- -

Add-on Builder 是 Web-based 的開發環境,讓開發者能以 SDK API 來開發附加元件,而不必使用 cfx 命令列工具。Add-on Builder 已經於 2014 年 4 月 1 日下架,而原本的網址「builder.addons.mozilla.org」則轉至此頁。
-
- 若您過去使用 Builder 來開發採用 SDK 的附加元件,便已獲得絕大部分以 SDK 直接開發的必備知識。Builder 中的 high-levellow-level API,就跟 SDK 裡的一模一樣。改用 SDK 很簡單:

- diff --git a/files/zh-tw/mozilla/add-ons/sdk/guides/index.html b/files/zh-tw/mozilla/add-ons/sdk/guides/index.html deleted file mode 100644 index f4e37d9e10..0000000000 --- a/files/zh-tw/mozilla/add-ons/sdk/guides/index.html +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: Guides -slug: Mozilla/Add-ons/SDK/Guides -translation_of: Archive/Add-ons/Add-on_SDK/Guides ---- -

This page lists more theoretical in-depth articles about the SDK.

-
-

Contributor's guide

-
-
-
-
- Getting Started
-
- Learn how to contribute to the SDK: getting the code, opening/taking a bug, filing a patch, getting reviews, and getting help.
-
- Modules
-
- Learn about the module system used by the SDK (which is based on the CommonJS specification), how sandboxes and compartments can be used to improve security, and about the built-in SDK module loader, known as Cuddlefish.
-
- Classes and Inheritance
-
- Learn how classes and inheritance can be implemented in JavaScript, using constructors and prototypes, and about the helper functions provided by the SDK to simplify this.
-
-
-
-
-
- Private Properties
-
- Learn how private properties can be implemented in JavaScript using prefixes, closures, and WeakMaps, and how the SDK supports private properties by using namespaces (which are a generalization of WeakMaps).
-
- Content Processes
-
- The SDK was designed to work in an environment where the code to manipulate web content runs in a different process from the main add-on code. This article highlights the main features of that design.
-
-
-
-
-

SDK infrastructure

-
-
-
-
- Module structure of the SDK
-
- The SDK, and add-ons built using it, are of composed from reusable JavaScript modules. This explains what these modules are, how to load modules, and how the SDK's module tree is structured.
-
- SDK API lifecycle
-
- Definition of the lifecycle for the SDK's APIs, including the stability ratings for APIs.
-
-
-
-
-
- Program ID
-
- The Program ID is a unique identifier for your add-on. This guide explains how it's created, what it's used for and how to define your own.
-
- Firefox compatibility
-
- Working out which Firefox releases a given SDK release is compatible with, and dealing with compatibility problems.
-
-
-
-
-

SDK idioms

-
-
-
-
- Working With Events
-
- Write event-driven code using the the SDK's event emitting framework.
-
- Content scripts guide
-
- An overview of content scripts, including: what they are, what they can do, how to load them, how to communicate with them.
-
-
-
-
-
- Two Types of Scripts
-
- This article explains the differences between the APIs available to your main add-on code and those available to content scripts.
-
-
-
-
-

XUL migration

-
-
-
-
- XUL Migration Guide
-
- Techniques to help port a XUL add-on to the SDK.
-
- XUL versus the SDK
-
- A comparison of the strengths and weaknesses of the SDK, compared to traditional XUL-based add-ons.
-
-
-
-
-
- Porting Example
-
- A walkthrough of porting a relatively simple XUL-based add-on to the SDK.
-
-
-
-

 

diff --git a/files/zh-tw/mozilla/add-ons/sdk/high-level_apis/context-menu/index.html b/files/zh-tw/mozilla/add-ons/sdk/high-level_apis/context-menu/index.html deleted file mode 100644 index 42c5e0ca85..0000000000 --- a/files/zh-tw/mozilla/add-ons/sdk/high-level_apis/context-menu/index.html +++ /dev/null @@ -1,588 +0,0 @@ ---- -title: context-menu -slug: Mozilla/Add-ons/SDK/High-Level_APIs/context-menu -translation_of: Archive/Add-ons/Add-on_SDK/High-Level_APIs/context-menu ---- -
-

Stable

-
-

加入選單項目、子選單、選單分隔線到頁面右鍵選單。

-

用法

-

Instead of manually adding items when particular contexts occur and then removing them when those contexts go away, you bind items to contexts, and the adding and removing is automatically handled for you. Items are bound to contexts in much the same way that event listeners are bound to events. When the user invokes the context menu, all of the items bound to the current context are automatically added to the menu. If no items are bound, none are added. Likewise, any items that were previously in the menu but are not bound to the current context are automatically removed from the menu. You never need to manually remove your items from the menu unless you want them to never appear again.

-

For example, if your add-on needs to add a context menu item whenever the user visits a certain page, don't create the item when that page loads, and don't remove it when the page unloads. Rather, create your item only once and supply a context that matches the target URL.

-

Context menu items are displayed in the order created or in the case of sub menus the order added to the sub menu. Menu items for each add-on will be grouped together automatically. If the total number of menu items in the main context menu from all add-ons exceeds a certain number (normally 10 but configurable with the extensions.addon-sdk.context-menu.overflowThreshold preference) all of the menu items will instead appear in an overflow menu to avoid making the context menu too large.

-

Specifying Contexts

-

As its name implies, the context menu should be reserved for the occurrence of specific contexts. Contexts can be related to page content or the page itself, but they should never be external to the page.

-

For example, a good use of the menu would be to show an "Edit Image" item when the user right-clicks an image in the page. A bad use would be to show a submenu that listed all the user's tabs, since tabs aren't related to the page or the node the user clicked to open the menu.

-

The Page Context

-

First of all, you may not need to specify a context at all. When a top-level item does not specify a context, the page context applies. An item that is in a submenu is visible unless you specify a context.

-

The page context occurs when the user invokes the context menu on a non-interactive portion of the page. Try right-clicking a blank spot in this page, or on text. Make sure that no text is selected. The menu that appears should contain the items "Back", "Forward", "Reload", "Stop", and so on. This is the page context.

-

The page context is appropriate when your item acts on the page as a whole. It does not occur when the user invokes the context menu on a link, image, or other non-text node, or while a selection exists.

-

宣告式場景條件(Declarative Contexts)

-

當你藉由設定 context 屬性(該屬性為: 傳給 constructor 的選項物件之屬性)來新增選單項目時,你可以指定一些簡單的宣告式場景條件, 如下:

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "My Menu Item",
-  context: cm.URLContext("*.mozilla.org")
-});
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Constructor選單項目出現的條件
PageContext() 當場景為網頁時.
SelectionContext() 當使用者在網頁上選取項目時.
SelectorContext(selector) 當選單在符合下述條件之一的節點上顯示: selector匹配, CSS 選擇器, 或 其祖先節點匹配選擇器. selector可以有多個(以逗點分隔), 例如, "a[href], img".
URLContext(matchPattern) 特定網址的網頁. matchPattern is a match pattern string or an array of match pattern strings. 當 matchPattern 是陣列, 網址符合任何陣列元素之一時. These are the same match pattern strings that you use with the page-mod include property. Read more about patterns.
PredicateContext(predicateFunction)當選單被觸發時,predicateFunction 函數被呼叫,若函數傳回值為真值,則選單項目顯示。這函數傳入一物件,物件有著描述選單觸發場景條件的屬性.
arrayAn array of any of the other types. This context occurs when all contexts in the array occur.
-

選單項目也有 context 屬性,可以用在新增或移除宣告式場景條件,當建構後. 例如:

-
var context = require("sdk/context-menu").SelectorContext("img");
-myMenuItem.context.add(context);
-myMenuItem.context.remove(context);
-

當選單項目被指定了多個場景條件, 選單項目顯示於所有場景條件皆成立時.

-

In Content Scripts

-

宣告式場景條件很容易使用,但功能不強. 舉例來說, 你希望選單項目出現的條件為:「有著至少一張圖片的頁面」, 但宣告式場景條件並不能達成這一點.

-

當你需要對選單項目的出現時機有著更多的控制, 你可以使用 content scripts. 如同 SDK 的其他 APIs 一樣, context-menu API 使用 content scripts 以讓你的附加元件與瀏覽器中的頁面互動. 在最上層選單的每一個選單項目可以使用 content script.

-

每當選單即將顯示時,一個特殊事件,其名為 "context" ,觸發於你的 content scripts. 如果你為這個事件註冊了偵聽(listener)函數,當函數傳回真值時, 與偵聽函數關聯的選單項目會被顯示於選單中.

-

下例中, 當選單觸發於「有著至少一張圖片的頁面」時,顯示選單項目.

-
require("sdk/context-menu").Item({
-  label: "This Page Has Images",
-  contentScript: 'self.on("context", function (node) {' +
-                 '  return !!document.querySelector("img");' +
-                 '});'
-});
-

需要注意的是偵聽函數有一個參數叫 node. 這個 node 指的是使用者在頁面上按右鍵來觸發選單的頁面觸發節點. 你可以使用它來決定是否要顯示選單項目.

-

你可以在 content script 中,同時指定宣告式場景條件和 context 偵聽函數. 在這種情況下, 先評估宣告式場景條件, 然後你的選單項目顯示條件為:所有宣告式場景條件成立,並且你的 context 偵聽函數傳回真值.

-

如果任一宣告式場景條件未成立, 那麼你的 context 偵聽函數不會被呼叫. 下面的例子利用了這點. 確保了偵聽函數只在 image node 上觸發選單時,才會被呼叫:

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "A Mozilla Image",
-  context: cm.SelectorContext("img"),
-  contentScript: 'self.on("context", function (node) {' +
-                 '  return /mozilla/.test(node.src);' +
-                 '});'
-});
-

However, if you do combine SelectorContext and the "context" event, be aware that the node argument passed to the "context" event will not always match the type specified in SelectorContext.

-

SelectorContext will match if the menu is invoked on the node specified or any descendant of that node, but the "context" event handler is passed the actual node on which the menu was invoked. 上個例子有作用,是因為 <IMG> 元素內不能包含其他元素, 但底下的例子裡, node.nodeName 不能保證是 "P" - 例如說, 當使用者在一個段落(<P>)的連結(<A>)上點右鍵時,它不會是 "P" :

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "A Paragraph",
-  context: cm.SelectorContext("p"),
-  contentScript: 'self.on("context", function (node) {' +
-                 '  console.log(node.nodeName);' +
-                 '  return true;' +
-                 '});'
-});
-

The content script is executed for every page that a context menu is shown for. It will be executed the first time it is needed (i.e. 當右鍵選單第一次顯示,並且選單項目的所有宣告式場景條件皆成立時) ,接著處於作用中,直到你銷毀你的選單項目或者關閉頁面.

-

處理選單項目上的點擊

-

content script 除了上述所說的功能(用來偵聽 "context" 事件)以外,你可以使用 content script 來處理選單項目上的點擊. 當使用者點擊選單項目時,一個名為 "click" 的事件在選單項目的 content script 內被觸發.

-

因此, 欲處理選單項目上的點擊, 可以藉由偵聽選單項目 content script 內的 "click" 事件, 如下:

-
require("sdk/context-menu").Item({
-  label: "My Item",
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  console.log("Item clicked!");' +
-                 '});'
-});
-

注意:偵聽函數有兩參數 nodedata.

-

"node" 參數

-

node 是使用者右鍵點擊所觸發選單的節點.

- -

例如, 假設你的附加元件看起來像這樣:

-
var script = "self.on('click', function (node, data) {" +
-             "  console.log('clicked: ' + node.nodeName);" +
-             "});";
-
-var cm = require("sdk/context-menu");
-
-cm.Item({
-  label: "body context",
-  context: cm.SelectorContext("body"),
-  contentScript: script
-});
-

這個附加元件建立了一個右鍵選單項目,該項目使用 SelectorContext 來顯示項目,顯示時機為:右鍵選單觸發於 <BODY> 元素的任何後代元素之上時. 點擊時, 項目記錄了 nodeName 屬性(觸發選單的節點名稱)傳給點擊事件處理器.

-

如果你執行這個附加元件,你將看到它總是記錄 "BODY", 即使你點擊的是頁面上的段落元素<P>:

-
info: contextmenu-example: clicked: BODY
-

與上面對比, 底下的附加元件使用了 PageContext:

-
var script = "self.on('click', function (node, data) {" +
-             "  console.log('clicked: ' + node.nodeName);" +
-             "});";
-
-var cm = require("sdk/context-menu");
-
-cm.Item({
-  label: "body context",
-  context: cm.PageContext(),
-  contentScript: script
-});
-

它將記錄實際點擊的節點名稱:

-
info: contextmenu-example: clicked: P
-

"data" 參數

-

data 是使用者所點擊選單項目的 data屬性. 注意: 當你有一個多層的選單(項目)時,點擊事件會被傳給被點擊的項目的所有祖先(項目),所以一定要驗證 data 值傳給你所期待的項目. 你可以使用 "data" 參數來簡化點擊事件處理 by providing just a single click listener on a Menu that reacts to clicks for any child items.:

-
var cm = require("sdk/context-menu");
-cm.Menu({
-  label: "My Menu",
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  console.log("You clicked " + data);' +
-                 '});',
-  items: [
-    cm.Item({ label: "Item 1", data: "item1" }),
-    cm.Item({ label: "Item 2", data: "item2" }),
-    cm.Item({ label: "Item 3", data: "item3" })
-  ]
-});
-
-

和附加元件通訊

-

時常,你需要收集一些訊息,在點擊偵聽函數內和執行一個無關於頁面動作. 為了與關聯於 content script 的選單項目通訊, content script 可以呼叫附屬於全域 self 物件的 postMessage 函數, 傳給它一些 JSON-able 資料. 選單項目的 "message" 事件偵聽函數將被呼叫(前述的 JSON-able 資料作為參數傳入).

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "Edit Image",
-  context: cm.SelectorContext("img"),
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  self.postMessage(node.src);' +
-                 '});',
-  onMessage: function (imgSrc) {
-    openImageEditor(imgSrc);
-  }
-});
-

更新選單項目的文字標籤

-

Each menu item must be created with a label, but you can change its label later using a couple of methods.

-

最簡單的方法是設定選單項目的 label 屬性. 下面的例子更新選單項目的文字標籤為它被點擊的次數:

-
var numClicks = 0;
-var myItem = require("sdk/context-menu").Item({
-  label: "Click Me: " + numClicks,
-  contentScript: 'self.on("click", self.postMessage);',
-  onMessage: function () {
-    numClicks++;
-    this.label = "Click Me: " + numClicks;
-    // Setting myItem.label is equivalent.
-  }
-});
-

Sometimes you might want to update the label based on the context. For instance, if your item performs a search with the user's selected text, it would be nice to display the text in the item to provide feedback to the user. 在這些情況下,你可以使用第二種方法 . 回想一下,你的 content scripts 可以偵聽 "context" 事件,如果你的偵聽函數傳回真值, 與 content scripts 關聯的選單項目會顯示在選單中. 除了傳回真值, 你的 "context" 偵聽函數也可以傳回字串. 當 "context" 偵聽函數傳回字串, 字串成為選單項目的新文字標籤.

-

This item implements the aforementioned search example:

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "Search Google",
-  context: cm.SelectionContext(),
-  contentScript: 'self.on("context", function () {' +
-                 '  var text = window.getSelection().toString();' +
-                 '  if (text.length > 20)' +             // 若太長
-                 '    text = text.substr(0, 20) + "...";' + // 則截短
-                 '  return "Search Google for " + text;' +  // 後綴到固定字串上傳回
-                 '});'
-});
-

"context" 偵聽函數取得使用者所選取的文字, 如果字串太長則截短它, 並後綴到固定字串上傳回. 當選單項目顯示, 它的文字標籤將是 "Search Google for text", 此處的 text 是被截短的 使用者所選取的文字.

-

隱私視窗

-

If your add-on has not opted into private browsing, then any menus or menu items that you add will not appear in context menus belonging to private browser windows.

-

To learn more about private windows, how to opt into private browsing, and how to support private browsing, refer to the documentation for the private-browsing module.

-

更多例子

-

For conciseness, these examples create their content scripts as strings and use the contentScript property. In your own add-on, you will probably want to create your content scripts in separate files and pass their URLs using the contentScriptFile property. See Working with Content Scripts for more information.

-
-

Unless your content script is extremely simple and consists only of a static string, don't use contentScript: if you do, you may have problems getting your add-on approved on AMO.

-

Instead, keep the script in a separate file and load it using contentScriptFile. This makes your code easier to maintain, secure, debug and review.

-
-

Show an "Edit Page Source" item when the user right-clicks a non-interactive part of the page:

-
require("sdk/context-menu").Item({
-  label: "Edit Page Source",
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  self.postMessage(document.URL);' +
-                 '});',
-  onMessage: function (pageURL) {
-    editSource(pageURL);
-  }
-});
-

Show an "Edit Image" item when the menu is invoked on an image:

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "Edit Image",
-  context: cm.SelectorContext("img"),
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  self.postMessage(node.src);' +
-                 '});',
-  onMessage: function (imgSrc) {
-    openImageEditor(imgSrc);
-  }
-});
-

Show an "Edit Mozilla Image" item when the menu is invoked on an image in a mozilla.org or mozilla.com page:

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "Edit Mozilla Image",
-  context: [
-    cm.URLContext(["*.mozilla.org", "*.mozilla.com"]),
-    cm.SelectorContext("img")
-  ],
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  self.postMessage(node.src);' +
-                 '});',
-  onMessage: function (imgSrc) {
-    openImageEditor(imgSrc);
-  }
-});
-

Show an "Edit Page Images" item when the page contains at least one image:

-
var cm = require("sdk/context-menu");
-cm.Item({
-  label: "Edit Page Images",
-  // This ensures the item only appears during the page context.
-  context: cm.PageContext(),
-  contentScript: 'self.on("context", function (node) {' +
-                 '  var pageHasImgs = !!document.querySelector("img");' +
-                 '  return pageHasImgs;' +
-                 '});' +
-                 'self.on("click", function (node, data) {' +
-                 '  var imgs = document.querySelectorAll("img");' +
-                 '  var imgSrcs = [];' +
-                 '  for (var i = 0 ; i < imgs.length; i++)' +
-                 '    imgSrcs.push(imgs[i].src);' +
-                 '  self.postMessage(imgSrcs);' +
-                 '});',
-  onMessage: function (imgSrcs) {
-    openImageEditor(imgSrcs);
-  }
-});
-

Show a "Search With" menu when the user right-clicks an anchor that searches Google or Wikipedia with the text contained in the anchor:

-
var cm = require("sdk/context-menu");
-var googleItem = cm.Item({
-  label: "Google",
-  data: "http://www.google.com/search?q="
-});
-var wikipediaItem = cm.Item({
-  label: "Wikipedia",
-  data: "http://en.wikipedia.org/wiki/Special:Search?search="
-});
-var searchMenu = cm.Menu({
-  label: "Search With",
-  context: cm.SelectorContext("a[href]"),
-  contentScript: 'self.on("click", function (node, data) {' +
-                 '  var searchURL = data + node.textContent;' +
-                 '  window.location.href = searchURL;' +
-                 '});',
-  items: [googleItem, wikipediaItem]
-});
-

Globals

-

Constructors

-

Item(options)

-

建立一個有文字標籤的選單項目,當點擊它時,可以執行一些動作.

-
參數
-

options : 物件
- options 物件的必要屬性:

- - - - - - - - - - - - - - - -
名稱型別 
label字串 -

選單項目的文字標籤. It must either be a string or an object that implements toString().

-
-

options 物件的可選屬性:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
名稱型別 
image字串 -

選單項目的圖示, a string URL. The URL can be remote, a reference to an image in the add-on's data directory, or a data URI.

-
data字串 -

An optional arbitrary value to associate with the item. It must be either a string or an object that implements toString(). It will be passed to click listeners.

-
accessKey只有單一字元的字串 -
-

New in Firefox 35.

-
-

選單項目的快捷鍵. Pressing this key selects the item when the context menu is open.

-
contextvalue -

If the item is contained in the top-level context menu, this declaratively specifies the context under which the item will appear; see Specifying Contexts above.

-
contentScript字串, 陣列 -

If the item is contained in the top-level context menu, this is the content script or an array of content scripts that the item can use to interact with the page.

-
contentScriptFile字串, 陣列 -

If the item is contained in the top-level context menu, this is the local file URL of the content script or an array of such URLs that the item can use to interact with the page.

-
onMessage函數 -

If the item is contained in the top-level context menu, this function will be called when the content script calls self.postMessage. It will be passed the data that was passed to postMessage.

-
- -

建立一個有文字標籤的選單項目,用以展開子選單.

-
參數
-

options : 物件
- options 物件的必要屬性:

- - - - - - - - - - - - - - - - - - - - -
名稱型別 
label字串 -

選單項目的文字標籤. It must either be a string or an object that implements toString().

-
items陣列 -

選單項目構成的陣列,這些選單項目會被子選單所包含. 陣列中的元素須為 Item, Menu, 或 Separator.

-
-

options 物件的可選屬性:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
名稱型別 
image字串 -

The menu's icon, a string URL. The URL can be remote, a reference to an image in the add-on's data directory, or a data URI.

-
contextvalue -

If the menu is contained in the top-level context menu, this declaratively specifies the context under which the menu will appear; see Specifying Contexts above.

-
contentScript字串, 陣列 -

If the menu is contained in the top-level context menu, this is the content script or an array of content scripts that the menu can use to interact with the page.

-
contentScriptFile字串, 陣列 -

If the menu is contained in the top-level context menu, this is the local file URL of the content script or an array of such URLs that the menu can use to interact with the page.

-
onMessage函數 -

If the menu is contained in the top-level context menu, this function will be called when the content script calls self.postMessage. It will be passed the data that was passed to postMessage.

-
-

Separator()

-

Creates a menu separator.

-

PageContext()

-

Creates a page context. See Specifying Contexts above.

-

SelectionContext()

-

Creates a context that occurs when a page contains a selection. See Specifying Contexts above.

-

SelectorContext(selector)

-

Creates a context that matches a given CSS selector. See Specifying Contexts above.

-
Parameters
-

selector : string
- A CSS selector.

-

URLContext(matchPattern)

-

Creates a context that matches pages with particular URLs. See Specifying Contexts above.

-
Parameters
-

matchPattern : string,array
- A match pattern string, regexp or an array of match pattern strings or regexps.

-

PredicateContext(predicateFunction)

-
-

New in Firefox 29

-
-

Creates a context that occurs when predicateFunction returns a true value. See Specifying Contexts above.

-
Parameters
-

predicateFunction : function(context)
- A function which will be called with an object argument that provide information about the invocation context. context object properties:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PropertyDescription
documentTypeThe MIME type of the document the menu was invoked in. E.g. text/html for HTML pages, application/xhtml+xml for XHTML, or image/jpeg if viewing an image directly.
documentURLThe URL of the document the menu was invoked in.
targetNameThe name of the DOM element that the menu was invoked on, in lower-case.
targetIDThe id attribute of the element that the menu was invoked on, or null if not set.
isEditabletrue if the menu was invoked in an editable element, and that element isn't disabled or read-only.  This includes non-input elements with the contenteditable attribute set to true.
selectionTextThe current selection as a text string, or null. If the menu was invoked in an input text box or area, this is the selection of that element, otherwise the selection in the contents of the window.
srcURLThe src URL of the element that the menu was invoked on, or null if it doesn't have one.
linkURLThe href URL of the element that the menu was invoked on, or null if it doesn't have one.
valueThe current contents of a input text box or area if the menu was invoked in one, null otherwise.
-

Item

-

A labeled menu item that can perform an action when clicked.

-

Methods

-

destroy()

-

Permanently removes the item from its parent menu and frees its resources. The item must not be used afterward. If you need to remove the item from its parent menu but use it afterward, call removeItem() on the parent menu instead.

-

Properties

-

label

-

The menu item's label. You can set this after creating the item to update its label later.

-

image

-

The item's icon, a string URL. The URL can be remote, a reference to an image in the add-on's data directory, or a data URI. You can set this after creating the item to update its image later. To remove the item's image, set it to null.

-

data

-

An optional arbitrary value to associate with the item. It must be either a string or an object that implements toString(). It will be passed to click listeners. You can set this after creating the item to update its data later.

-

context

-

A list of declarative contexts for which the menu item will appear in the context menu. Contexts can be added by calling context.add() and removed by called context.remove().

-

parentMenu

-

The item's parent Menu, or null if the item is contained in the top-level context menu. This property is read-only. To add the item to a new menu, call that menu's addItem() method.

-

contentScript

-

The content script or the array of content scripts associated with the menu item during creation.

-

contentScriptFile

-

The URL of a content script or the array of such URLs associated with the menu item during creation.

-

Events

-

message

-

If you listen to this event you can receive message events from content scripts associated with this menu item. When a content script posts a message using self.postMessage(), the message is delivered to the add-on code in the menu item's message event.

-
Arguments
-

value : Listeners are passed a single argument which is the message posted from the content script. The message can be any JSON-serializable value.

- -

A labeled menu item that expands into a submenu.

-

Methods

-

addItem(item)

-

Appends a menu item to the end of the menu. If the item is already contained in another menu or in the top-level context menu, it's automatically removed first. If the item is already contained in this menu it will just be moved to the end of the menu.

-
Parameters
-

item : Item,Menu,Separator
- The Item, Menu, or Separator to add to the menu.

-

removeItem(item)

-

Removes the given menu item from the menu. If the menu does not contain the item, this method does nothing.

-
Parameters
-

item : Item,Menu,Separator
- The menu item to remove from the menu.

-

destroy()

-

Permanently removes the menu from its parent menu and frees its resources. The menu must not be used afterward. If you need to remove the menu from its parent menu but use it afterward, call removeItem() on the parent menu instead.

-

Properties

-

label

-

The menu's label. You can set this after creating the menu to update its label later.

-

items

-

An array containing the items in the menu. The array is read-only, meaning that modifications to it will not affect the menu. However, setting this property to a new array will replace all the items currently in the menu with the items in the new array.

-

image

-

The menu's icon, a string URL. The URL can be remote, a reference to an image in the add-on's data directory, or a data URI. You can set this after creating the menu to update its image later. To remove the menu's image, set it to null.

-

context

-

A list of declarative contexts for which the menu will appear in the context menu. Contexts can be added by calling context.add() and removed by called context.remove().

-

parentMenu

-

The menu's parent Menu, or null if the menu is contained in the top-level context menu. This property is read-only. To add the menu to a new menu, call that menu's addItem() method.

-

contentScript

-

The content script or the array of content scripts associated with the menu during creation.

-

contentScriptFile

-

The URL of a content script or the array of such URLs associated with the menu during creation.

-

Events

-

message

-

If you listen to this event you can receive message events from content scripts associated with this menu item. When a content script posts a message using self.postMessage(), the message is delivered to the add-on code in the menu item's message event.

-
Arguments
-

value : Listeners are passed a single argument which is the message posted from the content script. The message can be any JSON-serializable value.

-

Separator

-

A menu separator. Separators can be contained only in Menus, not in the top-level context menu.

-

Methods

-

destroy()

-

Permanently removes the separator from its parent menu and frees its resources. The separator must not be used afterward. If you need to remove the separator from its parent menu but use it afterward, call removeItem() on the parent menu instead.

-

Properties

-

parentMenu

-

The separator's parent Menu. This property is read-only. To add the separator to a new menu, call that menu's addItem() method.

diff --git a/files/zh-tw/mozilla/add-ons/sdk/high-level_apis/index.html b/files/zh-tw/mozilla/add-ons/sdk/high-level_apis/index.html deleted file mode 100644 index 32b39d045b..0000000000 --- a/files/zh-tw/mozilla/add-ons/sdk/high-level_apis/index.html +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: High-Level APIs -slug: Mozilla/Add-ons/SDK/High-Level_APIs -tags: - - NeedsTranslation - - TopicStub -translation_of: Archive/Add-ons/Add-on_SDK/High-Level_APIs ---- -

Modules listed on this page implement high-level APIs for building add-ons: creating user interfaces, interacting with the web, and interacting with the browser.

-

Unless the documentation explicitly says otherwise, all these modules are "Stable": we'll avoid making incompatible changes to them. {{ LandingPageListSubpages ("/en-US/Add-ons/SDK/High-Level_APIs", 5) }}

diff --git a/files/zh-tw/mozilla/add-ons/sdk/index.html b/files/zh-tw/mozilla/add-ons/sdk/index.html deleted file mode 100644 index 2937b883d7..0000000000 --- a/files/zh-tw/mozilla/add-ons/sdk/index.html +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: Add-on SDK -slug: Mozilla/Add-ons/SDK -tags: - - NeedsTranslation - - TopicStub -translation_of: Archive/Add-ons/Add-on_SDK ---- -

有了附加元件開發套件(Add-on SDK),您可以使用標準的JavaScript、HTML、CSS等語法來建立Firefox的附加元件。SDK包含用來製作附加元件的JavaScript API,及建立、測試、運行或包裝附加元件的相關工具。

- -
-

入門

- -
-
-
-
從此開始
-
如何安裝 SDK 使用 cfx tool 來建立、測試或包裝附加元件。
-
和瀏覽器互動
-
開啟網頁監測頁面載入以及列出已開啟頁面
-
開發技巧
-
學習常用開發技術,如單元測試紀錄建立可重用模組在地化流動裝置
-
-
- -
-
-
建立使用者介面的元件
-
工具列按鈕內文選單選單項目對話框等等。
-
修改網頁
-
修改符合網址模式的頁面或動態修改特定分頁
-
整合各項
-
以 Annotator(一個顯示註解的附加元件)為例顯示製作流程。
-
-
-
- -
-

指引

- -
- - - -
- -
-

參考資料

- -
-
-
-
高階 API
-
高階 SDK API 的參考文件。
-
工具參考
-
Reference documentation for the cfx tool used to develop, test, and package add-ons, the console global used for logging, and the package.json file.
-
-
- -
-
-
低階 API
-
低階 SDK API 的參考文件。
-
-
-
diff --git a/files/zh-tw/mozilla/add-ons/sdk/low-level_apis/index.html b/files/zh-tw/mozilla/add-ons/sdk/low-level_apis/index.html deleted file mode 100644 index 2108d30783..0000000000 --- a/files/zh-tw/mozilla/add-ons/sdk/low-level_apis/index.html +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: Low-Level APIs -slug: Mozilla/Add-ons/SDK/Low-Level_APIs -translation_of: Archive/Add-ons/Add-on_SDK/Low-Level_APIs ---- -

Modules in this section implement low-level APIs. These modules fall roughly into three categories:

- -

These modules are still in active development, and we expect to make incompatible changes to them in future releases.

-

{{ LandingPageListSubpages ("/en-US/Add-ons/SDK/Low-Level_APIs", 5) }}

-

 

diff --git a/files/zh-tw/mozilla/add-ons/themes/obsolete/index.html b/files/zh-tw/mozilla/add-ons/themes/obsolete/index.html deleted file mode 100644 index d420b6ebf0..0000000000 --- a/files/zh-tw/mozilla/add-ons/themes/obsolete/index.html +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: Obsolete -slug: Mozilla/Add-ons/Themes/Obsolete -tags: - - NeedsTranslation - - TopicStub -translation_of: Mozilla/Add-ons/Themes/Obsolete ---- -

This page collects theme docs that we don't expect will ever be updated, but which we're keeping for the time being as potential source material for updated docs.

-

{{ ListSubPages ("/en-US/Add-ons/Themes/Obsolete", 5) }}

-- cgit v1.2.3-54-g00ecf