CmdUtils CreateCommand name filmfeed takes like or dislike noun_arb_te

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
CmdUtils.CreateCommand({
name: "filmfeed",
takes: {"like or dislike": noun_arb_text},
preview: "Adds movie to your account at filmfeed.ru.",
execute: function(userLike) {
var baseUrl = "http://filmfeed.devel.corvin.ru/api/add_movie/";
if (userLike.text == 'like' || userLike.text == 'dislike') {
var like = userLike.text == 'like' ? 1 : 0;
} else {
displayMessage('Вы должны написать like или dislike.');
return;
}
var url = CmdUtils.getWindowInsecure().location.href;
if (-1 == url.indexOf('imdb.com') || -1 == url.indexOf('/title')) {
displayMessage('Сначала зайдите на страницу фильма на imdb.com');
return;
}
var params = {like: like,
url: url,
is_profile: 0};
jQuery.ajax({
type: "POST",
url: baseUrl,
data: params,
dataType: 'json',
error: function(error) {
displayMessage("Ошибка!");
},
success: function(resp) {
if (resp.error) {
displayMessage(resp.error);
} else {
displayMessage('Фильм добавлен.');
}
}
});
}
})