Hatena::Groupkeysnail

きすねた(ん)

2010-03-25

MDC XUL Reference 検索

| 00:31 | MDC XUL Reference 検索 - きすねた(ん) を含むブックマーク はてなブックマーク - MDC XUL Reference 検索 - きすねた(ん)

Ruby API 検索 - basyura snail - keysnailグループ がかなり便利な感じだったので, 自分用に XULリファレンス検索を.

ポイントは, オプションで言語が指定可能となっているところ. literal : 0 とするとオプションが使えない (コマンドがパースされないため) というところには要注意.

f:id:mooz:20100326003007p:image

オプションの値は extra.options["-オプション名"] でとれる.

let xulTags = ["action","arrowscrollbox","assign","bbox","binding","bindings","box","broadcaster",
               "broadcasterset","button","browser","checkbox","caption","colorpicker","column",
               "columns","commandset","command","conditions","content","datepicker","deck","description",
               "dialog","dialogheader","dropmarker","editor","grid","grippy","groupbox","hbox","iframe",
               "image","key","keyset","label","listbox","listcell","listcol","listcols","listhead",
               "listheader","listitem","member","menu","menubar","menuitem","menulist","menupopup",
               "menuseparator","notification","notificationbox","observes","overlay","page","panel",
               "param","popupset","preference","preferences","prefpane","prefwindow","progressmeter",
               "query","queryset","radio","radiogroup","resizer","richlistbox","richlistitem","row",
               "rows","rule","scale","script","scrollbar","scrollbox","scrollcorner","separator","spacer",
               "spinbuttons","splitter","stack","statusbar","statusbarpanel","stringbundle","stringbundleset",
               "tab","tabbrowser","tabbox","tabpanel","tabpanels","tabs","template","textnode","textbox",
               "textbox_(Firefox_autocomplete)","textbox_(Mozilla_autocomplete)","timepicker","titlebar",
               "toolbar","toolbarbutton","toolbargrippy","toolbaritem","toolbarpalette","toolbarseparator",
               "toolbarset","toolbarspacer","toolbarspring","toolbox","tooltip","tree","treecell",
               "treechildren","treecol","treecols","treeitem","treerow","treeseparator","triple","vbox",
               "where","window","wizard","wizardpage"];

shell.add("xulref[erence]", M({ja: "MDC XUL Reference 検索", en: "MDC XUL Reference Search"}),
          function (args, extra) {
              let site = util.format("https://developer.mozilla.org/%s/", extra.options["-lang"] || "ja");
              let url;

              if (args.length === 1 && xulTags.some(function (tag) tag === args[0]))
                  url = site + "XUL:" + args[0];
              else
                  url = util.format("http://www.google.co.jp/search?q=%s&ie=utf-8&oe=utf-8",
                                    encodeURIComponent(args.join(" ") + " site:" + site));

              gBrowser.loadOneTab(url, null, null, null, extra.bang);
          },
          {
              bang      : true,
              options   : [
                  [["-lang"], shell.option.STRING, null, ["ja", "en"]]
              ],
              completer : function (args, extra) {
                  return completer.matcher.substring(xulTags)(extra.left || "");
              }
          },
          true
         );