こんにちは,
まず,
そして,
それでは,
Browser Actions API
Browser Actions APIはツールバーにボタンを追加するAPIです。
最初に,
このようにOmniBox
Browser Actionsの使い方
では,
なお,
manifest.
{
"name": "Print this page browser action extension",
"description": "This extension adds a print button to the toolstrip",
"version": "1.0",
"background_page": "background.html",
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"browser_action": {
"default_icon": "images/icon19.png",
"default_title": "Browser Action"
}
}
browser_
Background Pageでのbrowser_
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "javascript:window.print();";
chrome.tabs.update(tab.id, {url: action_url});
});
このように,
Badgeの使い方
Browser ActionsにはBadgeと呼ばれるボタン上にテキストを表示する機能があります。このBadgeの使い方を見てみます。
Badgeの操作
chrome.browserAction.setBadgeText({text:"111", tabId:tab.id});
chrome.browserAction.setBadgeBackgroundColor({color:[190, 190, 190, 230], tabId:tab.id});
chrome.browserAction.setIcon({path:'icon.png', tabId:tab.id});
chrome.browserAction.setTitle({title:'MyButton', tabId:tab.id});
このように,
setBadgeTextは4文字以内のテキストを指定します
ssetIconはアイコン画像のパス,
Popupの使い方
Popupは図2のモックのように,
図2 Popupのモック
こちらもmanifest.
Popupの定義
"browser_action": {
"default_icon": "icon.png",
"default_title": "Popup Sample",
"popup": "popup.html"
}