-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapping Facebook Users.tamper.js
152 lines (123 loc) · 4.4 KB
/
Mapping Facebook Users.tamper.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
// ==UserScript==
// @name Mapping Facebook Users
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description by Lauri Takacsi-Nagy
// @include https://www.facebook.com/UCBerkeley
// @require http://code.jquery.com/jquery-latest.min.js
// @require http://d3js.org/d3.v3.min.js
// @require http://d3js.org/d3.geo.projection.v0.min.js
// @require http://d3js.org/topojson.v0.min.js
// @copyright 2012+, You
// ==/UserScript==
var width = 1500, height = 1200;
var svg = d3.select("body").insert("svg", ":first-child")
.attr("width", width)
.attr("height", height);
var projection = d3.geo.mercator()
.scale(1500)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
var alreadyMapped = ["Berkeley, California"];
var alreadyAccessed = [];
function handle_JSON(r) {
var the_JSON = r.responseText;
console.log('Received JSON');
//console.log(the_JSON);
draw_map(JSON.parse(the_JSON));
}
GM_xmlhttpRequest({ method: 'GET', url: "http://www.cs.berkeley.edu/~bodik/world.json", onload: handle_JSON });
function draw_map(world) {
console.log("Drawing Map");
var countries = topojson.object(world, world.objects.countries);
svg.selectAll(".country")
.data(countries.geometries)
.enter().insert("path", "circle")
.attr("class", function(d) { return "country " + d.id; })
.attr("d", path)
.attr("fill", "#ddc");
svg.insert("path", "circle")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return true; }))
.attr("d", path)
.attr("class", "country-boundary")
.attr("fill", "none")
.attr("stroke", "#777")
.attr("stroke-linejoin", "round");
var berkeley_coords = [-122.2727470, 37.87159260];
var screen_coords = projection(berkeley_coords);
svg.append("svg:circle")
.attr("cx", screen_coords[0])
.attr("cy", screen_coords[1])
.attr("r", 3)
.attr("fill", "red");
}
function parsePage(r) {
my_regex = RegExp('Lives in <[^<]*');
matches = r.responseText.match(my_regex);
if(matches != null) {
var result = matches[0];
the_string = result.substring(result.lastIndexOf('>') + 1);
console.log(the_string);
get_coords(the_string);
} else {
console.log('None found');
}
}
function getURL(the_url) {
if(alreadyAccessed.indexOf(the_url) == -1) {
alreadyAccessed.push(the_url);
GM_xmlhttpRequest({ method: 'GET', url: the_url, onload: parsePage});
}
}
function update() {
console.log("Updating");
var comments = document.getElementsByClassName('UFICommentContent');
var pics = document.getElementsByClassName('pic innerPic');
var recs = document.getElementsByClassName('fwb');
var posts = document.getElementsByClassName('actorDescription actorName');
var more_posts = document.getElementsByClassName("actorDesciption");
var url;
for(var i = 0; i < posts.length; i++) {
url = posts[i].getElementsByTagName("a")[0].getAttribute("href");
getURL(String(url));
}
for(var i = 0; i < comments.length; i++) {
url = comments[i].getElementsByTagName("a")[0].getAttribute("href");
getURL(String(url));
}
for(var i = 0; i < more_posts.length; i++) {
url = more_posts[i].getElementsByTagName("a")[0].getAttribute("href");
getURL(String(url));
}
for(var i = 0; i < recs.length; i++) {
url = recs[i].getAttribute("href");
getURL(String(url));
}
for(var i = 0; i < pics.length; i++) {
url = pics[i].getAttribute("href");
getURL(String(url));
}
setTimeout(update, 10000);
}
update();
function get_coords(location_str) {
if(alreadyMapped.indexOf(location_str == -1)) {
alreadyMapped.push(location_str);
var sanitized_str = location_str.trim().replace(' ', '+');
var geo_URL = "http://maps.googleapis.com/maps/api/geocode/json?address=" + sanitized_str + "&sensor=false";
new GM_xmlhttpRequest({ method: 'GET', url: geo_URL, onload: parseAndDraw});
}
}
function parseAndDraw(r) {
geo_info = JSON.parse(r.responseText);
if(geo_info == null || geo_info.status != "INVALID_REQUEST") {
var coords = [geo_info.results[0].geometry.location.lng, geo_info.results[0].geometry.location.lat];
var screen_coords = projection(coords);
}
svg.append("svg:circle")
.attr("cx", screen_coords[0])
.attr("cy", screen_coords[1])
.attr("r", 3)
.attr("fill", "red");
}