-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbostad.user.js
68 lines (58 loc) · 1.66 KB
/
bostad.user.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
// ==UserScript==
// @name Bostad Stockholm
// @namespace http://danieleliasson.com/
// @description Show queue time for flats in search results
// @include https://bokabostad.stockholm.se/LagenhetSok.aspx*
// @exclude
// ==/UserScript==
var jq;
// Add jQuery
(function(){
if (typeof unsafeWindow.jQuery == 'undefined') {
var GM_Head = document.getElementsByTagName('head')[0] || document.documentElement,
GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
GM_JQ.type = 'text/javascript';
GM_JQ.async = true;
GM_Head.insertBefore(GM_JQ, GM_Head.firstChild);
}
GM_wait();
})();
// Check if jQuery's loaded
function GM_wait() {
if (typeof unsafeWindow.jQuery == 'undefined') {
window.setTimeout(GM_wait, 100);
} else {
jq = unsafeWindow.jQuery;
letsJQuery();
}
}
// All your GM code must be inside this function
function letsJQuery() {
var links = jq("table#uiGridViewIntresseanmalan.boslist1 tr td:nth-child(3) a");
jq(links).each(function(i, a) { handleLink(a); });
}
function handleLink(a) {
var url = jq(a).attr('href');
var c = parseAndInsertPlace(a);
getPlaceInLine(url, c);
}
function parseAndInsertPlace(a) {
return function(raw) {
var exp = /\d+/g;
var match = raw.match(exp);
var dateCell = jq(a).parent().parent().children()[7];
jq(dateCell).html(match[0] + '/' + match[1]);
};
}
function getPlaceInLine(url, c) {
jq.ajax({
url: url,
data: {},
success: function(result) {
var context = jq(result);
var place = jq("div.status + div > p:nth-child(2)", context).html();
c(place);
}
});
}