-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-gatherer.js
134 lines (125 loc) · 4.69 KB
/
data-gatherer.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
// ==UserScript==
// @name Transform event data from code to GeoJson
// @include http://www.kulturosnaktis.lt/lt/projects/map
// @run-at document-start
// @grant none
// @require https://gist.githubusercontent.com/BrockA/2620135/raw/83e1e5e36f130fa4e0cc2127175e293a90674d85/checkForBadJavascripts.js
// ==/UserScript==
/**
* This function creates a fake google map object,
* that intercepts API calls and creates a GeoJson structure.
*/
function init () {
events = []
var contentPlaceholder = null;
var id = 133713371337;
var timeRegexp = /\/>([0-9]+[:.][0-9]+) - ([0-9]+[:.][0-9]+) val\./;
var descAndLinkRegexp = /<strong>.*<br\/>(.*)<br\/><br\/><a href="(.*)">Daugiau/;
function toNumerical(timeString, from) {
if (timeString == '?') {
return from ? 0 : 30;
} else {
var parts = timeString.split(/[:.]/);
var hours = parseInt(parts[0]);
var minutes = parseInt(parts[1]) / 60;
return hours + minutes;
}
}
google = {
maps: {
MarkerImage: function(imageUrl) {
this.imageUrl = imageUrl;
},
LatLng: function(lat, lng) {
this.lat = lat;
this.lng = lng;
},
Marker: function(args) {
this.args = args;
this.setTitle = function(title) {
this.title = title;
}
},
MapTypeId: {
ROADMAP: 0
},
event: {
addListener: function(marker, event, func) {
func();
var time = timeRegexp.exec(contentPlaceholder) || [null, '?','?'];
var descAndLink = descAndLinkRegexp.exec(contentPlaceholder) || [null, contentPlaceholder, null];
events.push({
title: marker.title,
type: marker.args.icon.imageUrl.split('/').pop().split('.')[0],
icon: marker.args.icon.imageUrl,
from: time[1],
fromNumerical: toNumerical(time[1], true),
until: time[2],
untilNumerical: toNumerical(time[2], false),
description: descAndLink[1],
link: "http://www.kulturosnaktis.lt" + (descAndLink[2] || ""),
id: parseInt((descAndLink[2] || String(id++)).split("/").pop()),
lat: marker.args.position.lat,
lng: marker.args.position.lng
});
}
},
InfoWindow: function() {
this.setContent = function(content) {
contentPlaceholder = content
.replace(/„/g, '„')
.replace(/“/g, '“')
.replace(/’/g, '’')
.replace(/š/g, 'š')
.replace(/Š/g, 'Š')
.replace(/–/g, '–')
.replace(/</g, '<')
.replace(/…/g, '…')
.replace(/'/g, "'")
.replace(/"/g, '"')
.replace(/ý/g, 'ý');
}
this.open = function() {}
},
Size: function() {},
Point: function() {},
Map: function() {}
}
};
window.get = function() {}
eventsGeoJson = function() {
function toGeoJson(event) {
return {
"id": event.id,
"type": "Feature",
"properties": {
"title": event.title,
"from": event.from,
"fromNumerical": event.fromNumerical,
"until": event.until,
"untilNumerical": event.untilNumerical,
"description": event.description,
"link": event.link,
"type": event.type,
"icon": event.icon
},
"geometry": {
"type": "Point",
"coordinates": [
event.lng,
event.lat
]
}
};
}
var geoJson = {
type: "FeatureCollection",
features: events.map(toGeoJson)
}
return JSON.stringify(geoJson, null, 2);
}
}
// Intercept google maps script
checkForBadJavascripts ( [
[true, /google/i, function () {addJS_Node (null, null, init);} ]
] );