-
Notifications
You must be signed in to change notification settings - Fork 18
/
sob.js
343 lines (306 loc) · 11.9 KB
/
sob.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/*
sob.js - sobnik.chrome module to work with sob.ru
Copyright (c) 2014 Artem Palchevsky.
Copyright other contributors as noted in the AUTHORS file.
This file is part of sobnik.chrome, Sobnik plugin for Chrome:
http://sobnik.com.
This is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 3 of the License, or (at
your option) any later version.
This software is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
;(function () {
console.log ("Loading sob.ru");
var sobnik = window.sobnik;
console.assert (sobnik, "Sobnik required");
var cmn = sobnik.require ("cmn");
var boards = sobnik.require ("boards");
var sob = {
name: "sob.ru",
// FIXME add abuse reasons
urls: [
"http[s]?://.*\\.?sob.ru/card/.*",
],
trigger: [
"div.card_wrap_rent",
"div.card_wrap"
],
untrigger: [
//FIXME: fill it in
],
capture: {
photoImage: {
dynamic: function () {
var data = {
dropImage: true,
attr: "src",
}
if ($("div.wrapper h1").text ().indexOf ("Аренда") == 0)
{
// settings are returned
data.selector = "div.wrapper div.photos img";
console.log ("Capture settings", data);
return data;
}
else
{
// promise that waits for selector is returned
data.selector = "div.card_photos li.photo img";
// start loading of photos
var link = "div.big_photo a.card_image_box";
// any photos?
if (!$(link).length)
return {selector: link}; // empty selector
cmn.click (link);
// wait until photo card is created
return cmn.waitCond (function () {
return $(data.selector).length;
}).then (function () {
// lets wait a bit to make sure
return cmn.wait (1000);
}).then (function () {
// now capture settings are ready
console.log ("Capture settings", data);
return data;
});
}
},
},
},
list: {
// the row in the list
rowSelector: "table.main_table tr[id^='tr_']",
// container for the link to an ad (relative to rowSelector)
hrefSelector: "td.address a",
// links matching this pattern will be marked in the list
pattern: "/card/",
// matching urls will be treated as a list of ads
urls: [
"http[s]?://.*\\.?sob.ru/prodazha.*",
"http[s]?://.*\\.?sob.ru/arenda/.*"
],
mark: function (row, ad) {
var el = $("<span style='display:block;"
+"float:left; margin: 1em 0; padding: 0'>"
+boards.marker (ad)+"</span>");
$(row).find("td.address").prepend(el);
return el;
},
},
page: {
marks: [
{
selector: "div.wrapper h1",
mark: function (parent, ad) {
var el = $("<span style='display:block;"
+"float:left; margin: 6px 3px; padding: 0'>"
+boards.marker (ad)+"</span>");
$(parent).prepend(el);
return el;
},
},
{
selector: "div.contact",
mark: function (parent, ad) {
var el = $("<span style='display:block;"
+"float:left; margin: 2em 5px; padding: 0'>"
+boards.marker (ad)+"</span>");
$(parent).prepend(el);
return el;
},
},
{
selector: ".phones.icon",
mark: function (parent, ad) {
var el = $("<span style='display:block;"
+"float:left; margin: 1px 3px; padding: 0'>"
+boards.marker (ad)+"</span>");
$(parent).prepend(el);
return el;
},
}
],
},
url2id: function (url) {
var id = url.match (".*\\/\\d+-(\\d+)");
// console.log ("Url "+url);
// console.log (id);
if (!id)
return "";
return "sob:"+id[1];
},
fields: {
script: {
selector: "script",
data: {
script: {
rx: "var current_object = eval\\(({.*?})\\);",
rxi: 1,
conv: function (s) {
if (s.length)
{
// console.log (s);
this.current_object = JSON.parse(s);
console.log(this.current_object);
}
}
},
}
},
info: {
selector: "div.wrapper h1",
data: {
name: {
conv: function () {
var r = [];
if (this.current_object.owner_name)
r.push (unescape(this.current_object.owner_name));
if (this.current_object.company_name)
r.push (unescape(this.current_object.company_name));
return r;
}
},
street: {
conv: function () {
return unescape(this.current_object.info.address);
}
},
type: {
conv: function (s) {
if (s.indexOf ("Аренда") == 0) return "sdam";
if (s.indexOf ("Продажа") == 0) return "prodam";
return "unknown";
},
},
rooms: {
conv: function (s) {
if (s.indexOf ("однокомн")) return "1";
if (s.indexOf ("двухкомн")) return "2";
if (s.indexOf ("трёхкомн")) return "3";
//if (s.indexOf ("многокомн") == 0) return 4;
return null;
},
},
area: {
conv: function () {
return (parseInt(this.current_object.info.sqtl) / 10).toString();
}
},
floor: {
conv: function () {
return this.current_object.info.bldflr;
}
},
floors: {
conv: function () {
return this.current_object.info.bldht;
}
},
phone: {
conv: function () {
return this.current_object
.phones.map (function (p) {
return p.replace (/^7/, "+7");
});
}
},
phoneOff: {
conv: function () {
return this.current_object
.phones.map (function (p) {
return p.replace (/^7/, "+7");
});
}
},
notes: {
conv : function () {
return this.current_object.info.cm;
}
},
created: {
conv: function () {
var d = this.current_object.info.crdt;
var m = d.match(/^\S+/);
if (m)
{
return boards.dts(new Date(m[0]));
}
}
},
lat:
{
conv: function () {
return this.current_object.info.yandex_y;
}
},
lon:
{
conv: function () {
return this.current_object.info.yandex_x;
}
},
photo:
{
conv: function () {
return this.current_object.photos;
}
},
author:
{
conv: function () {
if (Number (this.current_object.info.commission_agency) > 0
|| Number (this.current_object.info.commission_client) > 0
|| this.current_object.company_name
|| this.current_object.company_logo
|| this.current_object.company_link)
return "agent";
}
},
}
},
city: {
selector: "div.region span.caption",
data: {
city: {}
}
},
// FIXME check cities w/o metro
metro: {
selector: "span.subway_name",
data: {
district: {},
}
},
daily: {
selector: "span.period",
data: {
daily: {
rx: "сутки",
conv: function (s) {
return s ? "daily" : "";
},
}
},
},
price: {
selector: "div.price",
data: {
price: {
conv: function (s) {
return s.replace(/([^\d]|\s)+/ig, "");
}
}
}
},
}
};
window.sobnik.boards.sob = sob;
window.sobnik.boards.current = sob;
} ());