-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfb.gmaps.user.js
98 lines (75 loc) · 2.48 KB
/
fb.gmaps.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
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
// ==UserScript==
// @name Facebook with Google Maps
// @version 0.15
// @description Changes Bing Maps links on Facebook to Google Maps links.
// @match http://www.facebook.com/*
// @match https://www.facebook.com/*
// ==/UserScript==
try {
var t,
fbGmaps = {
eventMap: null,
infoMap: null,
address: '',
gmapsUrl: 'http://maps.google.com/maps?q=',
gmapsLink: '',
getPageType: function() {
this.eventMap = document.getElementById('pagelet_event_details');
this.infoMap = document.getElementById('pagelet_info') || document.getElementById('pagelet_profile_info');
// This will replace check-in based maps some day...
// this.checkInTimelineMap = document.querySelectorAll('.fbTimelineFlyoutMap .fbPlaceFlyout~a');
if (!this.eventMap && !this.infoMap) {
return;
}
this.initReplace();
},
getEventAddress: function() {
var addressFragments = document.querySelectorAll('.fbPlaceFlyout .uiCollapsedList span.fsm.fwn.fcg'),
i;
if (!addressFragments.length) {
return;
}
this.address = ''; // If some change happened earlier.
for (i = 0; i < addressFragments.length; i++) {
this.address += addressFragments[i].textContent + ' ';
}
this.address = this.address.substring(0, this.address.length - 1);
},
getInfoAddress: function() {
var addressCont = document.querySelector('.uiInfoTable.profileInfoTable a[href^="http://bing.com/maps"]');
this.address = addressCont.textContent;
},
createLink: function() {
this.gmapsLink = this.gmapsUrl + encodeURI(this.address.replace(/\s/g, '+'));
},
replaceLinks: function() {
var mapLinks = document.querySelectorAll('a[href^="http://bing.com/maps"]'),
i;
if (!mapLinks.length) {
return;
}
for(i = 0; i < mapLinks.length; i++) {
mapLinks[i].setAttribute('href', this.gmapsLink);
mapLinks[i].setAttribute('target', '_blank');
mapLinks[i].removeAttribute('rel');
}
},
initReplace: function() {
if (this.eventMap) {
this.getEventAddress();
}
else {
this.getInfoAddress();
}
this.createLink();
this.replaceLinks();
}
};
// Must poll, because of Facebook's HTML5 history API usage,
// Bing Maps links can be inserted dynamically into DOM.
t = setInterval(function() {
if (document.querySelectorAll('a[href^="http://bing.com/maps"]').length) {
fbGmaps.getPageType();
}
}, 1000);
} catch (e) {}