Chrome拡張のサンプル(QRCode生成)

文字列を選択して、右クリックのコンテキストメニューから、選択された文字列(日本語も可)のQRコードを生成して、新しいタブに表示するサンプル。QRCodeの生成にはGoogle Chart APIを使用。グラフだけじゃなくQRCodeも表示できる。けど、ドキュメント見たらdeprecatedになってるから、いつまで使えるのか分からない感じか。恒久的には使えないかもしれないけど、サンプルと言う事で。
manifest.json{
  "manifest_version": 2,
  "name": "QRCode",
  "version": "0.0.1",
  "background": {
    "scripts": ["background.js"]
  },
  "permissions": [
    "contextMenus",
    "tabs"
  ]
}
background.jschrome.contextMenus.create({
  "title": "QRCode生成",
  "type": "normal",
  "contexts": ["selection"],
  "onclick": function(info) {
    var parm = encodeURIComponent(info.selectionText);
    chrome.tabs.create({url: 'http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=M|4&choe=UTF-8&chl=' + parm});
  }
});