Skip to content

Instantly share code, notes, and snippets.

@aoikishu
Created April 4, 2009 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aoikishu/90237 to your computer and use it in GitHub Desktop.
Save aoikishu/90237 to your computer and use it in GitHub Desktop.
// anime and character searches for MyAnimeList.net
//Advanced anime search is incomplete for Parser2. Code for parser1 should still work if you still have the older version.
if (CmdUtils.parserVersion == 2) {
//parser 2 code: ----------------------------------------------------------------
CmdUtils.CreateCommand({
names: ['anime search'],
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'Title'} ],
preview: function(pblock, args) {
var msg = 'Searching for: "${titleText}".';
var subs = {titleText: args.object.text};
var details = 'Please type in lowercase'
pblock.innerHTML = CmdUtils.renderTemplate(msg, subs, details);
},
execute: function(args) {
var url = "http://myanimelist.net/anime.php?q=" + args.object.text;
Utils.openUrlInBrowser(url);
}
});
CmdUtils.CreateCommand({
names: ['character search'],
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'Name'} ],
preview: function(pblock, args) {
pblock.innerHTML = "Searches Characters in MAL";
},
execute: function(args) {
var url = "http://myanimelist.net/character.php?q=" + args.object.text;
Utils.openUrlInBrowser(url);
}
})
} else {
//parser 1 code: ----------------------------------------------------------------
// Finished testing, still adding to it
// An advanced search command for MyAnimeList.net
/* I noticed that now it doesn't allow searching for both Score and Type ( don't know why )
I'm hoping Parser2 will fix it
*/
CmdUtils.CreateCommand({
name: "anime-search",
takes: {"name": noun_arb_text},
modifiers: {"type": noun_arb_text, "score": noun_arb_text},
preview: function( pblock, name, mods ) {
// args contains .with and .in, both of which are input objects.
var msg = 'Searching for: "${nameText}" Type: ${typeText} Score: ${scoreText}.';
var subs = {nameText: name.text, typeText: mods["type"].text, scoreText: mods["score"].text};
var details = 'Please type in lowercase'
pblock.innerHTML = CmdUtils.renderTemplate( msg, subs, details );
},
execute: function( name, mods ) {
if (mods["type"].text == "tv") {
var type = "1";
};
if (mods["type"].text == "ova") {
var type = "2";
};
if (mods["type"].text == "movie") {
var type = "3";
};
if (mods["type"].text == "special") {
var type = "4";
};
if (mods["type"].text == "ona") {
var type = "5";
};
var name = name.text;
var score = mods["score"].text;
var url = "http://myanimelist.net/anime.php?q=" + name + "&type=" + type + "&score=" + score;
Utils.openUrlInBrowser( url );
}
});
CmdUtils.CreateCommand({
name: "character-search",
takes: {"Character": noun_arb_text},
preview: function( pblock, theSearch ) {
pblock.innerHTML = "Searches Characters in MAL";
},
execute: function( theSearch ) {
var url = "http://myanimelist.net/character.php?q=" + theSearch.text;
Utils.openUrlInBrowser( url );
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment