var noun_downloadem_method = new CmdUtils.NounType( "Method", ["StopTazmo", "xx", "yy"]);

CmdUtils.CreateCommand({
  name: "drain-manga",
  author: {name: "Vashira Ravipanich", email: "r.vashira@gmail.com"},
  homepage: "http://www.vashira.com/",
  description: "Drain free manga to your desk",
  help: "Download manga from selected source (currently only stoptazmo), given name of serie and chapter number.",
  icon: "http://code.vashira.com/favicon.ico",
  takes: {"name":noun_arb_text},
  modifiers: {
    "from": noun_downloadem_method,
    "chap": noun_arb_text,
  },
  preview: function(pblock, name, mods) {
    // args contains .with and .in, both of which are input objects.
    var msg = 'Download "${nameText}" from${fromText} chapter ${chapText}.';
    var subs = {nameText: name.text, fromText: mods["from"].text, chapText: mods["chap"].text};
    
    pblock.innerHTML = CmdUtils.renderTemplate( msg, subs );
  },
  execute: function(name, mods) {
    var link = "http://stoptazmo.com/downloads/get_file.php?file_category=" + name.text + "&mirror=1&file_name=" + name.text + "_" + mods["chap"].text + ".zip";
    Utils.openUrlInBrowser(link);
    displayMessage("Enqueue: " + name.text + " chapter " + mods["chap"].text);
  }
})

