エントリー
この記事では、最初のOperaエクステンションを作成する基本的な手順を説明します。 パネル上にボタンを作成します。クリックすると、ポップアップウィンドウが開き、「Hello World!」というメッセージが表示されます。 Operaの拡張機能は、一般的なオープンWeb標準を使用して記述されているため、Opera 11とテキストエディタまたはIDEのみで開始できます。
拡張機能の構成。
最初に、拡張機能を説明するメタデータを含む拡張機能構成ファイルを作成する必要があります。 これには、拡張機能の名前、作成者、および拡張機能マネージャーのアイコンに関する情報が含まれています。 Operaの拡張機能はW3C Widgets形式を使用します。これはOpera Widgetsでおなじみのものかもしれません。
構成ファイルのスケルトンを作成します。
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
-
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
<? xml version ="1.0" encoding ="utf-8" ? > < widget xmlns ="http://www.w3.org/ns/widgets" > < name > Hello extensions! </ name > < description > A simple hello world example </ description > < author href ="yourURL" email ="yourEMail" > Enter your name here </ author > < icon src ="hello.png" /> </ widget > * This source code was highlighted with Source Code Highlighter .
config.xmlとして保存します。
拡張機能アイコンの作成
確かに、構成ファイルのアイコンの説明に気づきます。 示されたアイコンは、Extension ManagerおよびOperaの拡張サイトで使用されます。 64x64ピクセルのアイコンを作成することをお勧めします。
hello.pngアイコンファイルをダウンロードし、拡張フォルダーに保存します。
Operaパネルにボタンを追加する
拡張機能を構成したら、コードの記述を開始できます。 パネルに追加するボタンを作成します。 これは、次のコードを使用して実行できます。
- <! doctype html >
- < html lang = "en" >
- < 頭 >
- < スクリプト >
- window.addEventListener( "load" 、 function (){
- var theButton;
- var ToolbarUIItemProperties = {
- タイトル: "Hello World" 、
- アイコン: "hello-button.png" 、
- popup:{
- href: "popup.html" 、
- 幅:110、
- 高さ:30
- }
- }
- theButton = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
- opera.contexts.toolbar.addItem(theButton);
- }、 false );
- </ スクリプト >
- </ 頭 >
- < 本体 >
- </ body >
- </ html >
*このソースコードは、 ソースコードハイライターで強調表示されました。
このファイルを拡張フォルダーにindex.htmlとして保存します。
Operaの拡張には、index.htmlファイルが必要です。 これは、UI要素を作成するスクリプトを含むHTMLテンプレートです。 このドキュメントの本文は使用されていません。
スクリプトは、いくつかのプロパティを持つパネル要素(ボタン)を作成します。 要素は、18x18ピクセルのアイコンで作成されます。 ボタンに関連付けられたポップアップウィンドウも、指定されたサイズで作成され、インターフェイスでファイルが示されます。
hello-button.pngファイルをダウンロードして、拡張フォルダーに保存します。
ポップアップを作成する
すでにボタンを作成し、ポップアップウィンドウのサイズを指定しているので、コンテンツを作成するだけです。 これは、指定された次元を持つ単なるHTMLドキュメントです。 HTML、CSS、JavaScript、または通常Webページで使用するその他のWebテクノロジーを使用できます。 これはHello Worldの例なので、このページを作成します。
- <! doctype html >
- < html lang = "en" >
- < 頭 >
- < タイトル > Hello World! </ タイトル >
- < スタイル >
- h1 {
- フォント:14px helvetica、arial、sans-serif。
- text-align:center;
- }
- </ スタイル >
- </ 頭 >
- < 本体 >
- < h1 > Hello World! </ h1 >
- </ body >
- </ html >
*このソースコードは、 ソースコードハイライターで強調表示されました。
拡張フォルダーに、このファイルをpopup.htmlという名前で保存します。
拡張機能のパッキングとインストール
拡張機能の作成はほぼ完了です。 必要なことは、すべてのファイルをzipアーカイブにパックすることです。 その後、結果のファイルの名前をHelloExtension.oexに変更し(拡張子を.zipから.oexに変更することを忘れないでください)、完了です。
完成した
HelloExtension拡張機能をダウンロードできます。
拡張機能をブラウザウィンドウにドラッグするだけで、インストールするかどうかを尋ねられます。 指定したアイコンとメタデータが表示されます。 任意のタブに切り替えて、パネルの新しいボタンをクリックしてみてください。
プロセスに慣れるまで、ボタンのさまざまなプロパティとポップアップウィンドウの内容を試してください。