This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
forked from gazs/elvira-ubiquity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
elvira.js
115 lines (113 loc) · 3.76 KB
/
elvira.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var elvira_url = "http://elvira.mav-start.hu/elvira.dll/xslms/uf";
CmdUtils.CreateCommand({
names: ["elvira"],
description: "Check Elvira timetable",
help: "elvira (from) (to) (with via) (as student, u26, bike or bikeclub) (at [date])",
icon: "http://elvira.mav-start.hu/xslms/res/favicon.ico",
author: {name: "Gazs", email: "gazs@bergengocia.net"},
contributors: ["KTamas (ktamas@ktamas.com)"],
license: "GPL",
arguments: [
{
role: "source",
nountype: noun_arb_text,
label: "origin"
},
{
role: "goal",
nountype: noun_arb_text,
label: "destination"
},
{
role: "instrument",
nountype: noun_arb_text,
label: "via"
},
{
role: "alias",
nountype: ["student", "u26", "bike", "bikeclub"],
label: "reduction" //izé, kedvezmény.
},
{
role: "time",
nountype: noun_type_date,
label: "date of departure"
}
],
elviraurl: function(arguments) {
var source = escape(Utils.convertFromUnicode("ISO-8859-2", arguments.source.text));
var goal = escape(Utils.convertFromUnicode("ISO-8859-2", arguments.goal.text));
var via = escape(Utils.convertFromUnicode("ISO-8859-2", arguments.instrument.text));
var datum = arguments.time.data.toString("yy.MM.dd");
var u = 29;
if (source.length >0 && goal.length >0) {
switch (arguments.alias.text) {
// TODO: többi kedvezmény.
case "student":
u=1;
break;
case "u26":
u=17;
break;
case "bike":
u=35;
break;
case "bikeclub":
u=33;
break;
default:
u=29;
break;
}
return elvira_url + Utils.paramsToString({
mikor: -1,
i: source,
e: goal,
d: datum,
u: u, // nem gazs nem jo ha default a student
v: via
});
}
},
preview: function (pb, arguments) {
pb.innerHTML = this.previewDefault();
//karácsonyra igazán kérhetnétek utf8-at.
$.ajaxSetup({'beforeSend' : function(xhr) {
xhr.overrideMimeType('text/html; charset=ISO-8859-2');
}
});
CmdUtils.previewGet(pb, this.elviraurl(arguments),
function(page) {
elvi = [];
if ($("#searchtop > .box1 > .lboxbody1 > .xform > div:eq(4)", page).html() == "missing or misspelled station name") {
pb.innerHTML = "misspelled station name?";
} else {
if ($("div#timetable > table > tbody > tr > td.noprint > div.jsubmit > form.jsubmit > input[type=submit]", page).length === 0) {
pb.innerHTML = "no more trains on date.";
} else {
$("div#timetable > table > tbody > tr > td.noprint > div.jsubmit > form.jsubmit > input[type=submit]", page).each(function(i) {
var basepath = $(this).parent().parent().parent().siblings();
var honnan = basepath.filter(".l:eq(0)").text();
var indul = basepath.filter(".l:eq(1)").text().trim();
var erkezik = basepath.filter(".l:eq(2)").text().trim();
var masodosztalyar = basepath.filter(".r:eq(2)").text().trim();
var rendeleslink = "https://jegyvasarlas.mav-start.hu/eTicketV2/Jegykivalasztas?" + $(this).parent().serialize();
var reszletesdoboz = $(this).parent().parent().parent().parent().next().children().html(); // hogyan tudom ezt beformázni?
elvi.push(_('<div id="${rendeleslink}">${honnan} - ${indul}-${erkezik} ${masodosztalyar} ${reszletesdoboz}</div>', //div id?? srsly??
{rendeleslink: rendeleslink, honnan:honnan, indul:indul, erkezik:erkezik, masodosztalyar:masodosztalyar, reszletesdoboz:reszletesdoboz}));
});
CmdUtils.previewList(pb, elvi, function(id, ev) {
Utils.focusUrlInBrowser($(elvi[id]).attr('id'));
}, ".preview-list > li .more {display:none}; .preview-list > li:hover .more {display:block};.preview-list li:hover {color:red}");
}
}
},
"xml"
);
return;
},
execute: function (arguments) {
Utils.focusUrlInBrowser(this.elviraurl(arguments));
return;
}
})