-
Notifications
You must be signed in to change notification settings - Fork 42
/
get_fb_id.js
68 lines (54 loc) · 1.33 KB
/
get_fb_id.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
/**
* SearchBook
*
* @author sowdust<[email protected]>
* @url https://github.com/sowdust/searchbook
*
* License: free
*
*/
// needs some fixing. sometimes the html is not updated
//var html = '';
function get_html() {
var html = document.documentElement.innerHTML;
get_fb_id(html);
}
window.addEventListener("load", get_html(), false);
function get_fb_id(html) {
//var html = document.documentElement.innerHTML;
//var html = DOMtoString(document);
var regex = new RegExp('fb\:\/\/(page|profile|group)\/([0-9]+)');
var regexUID = new RegExp('\"uid\"\:([0-9]+)');
var regexTitle = new RegExp('<title id=\"pageTitle\">(.*?)<\/title>');
// getting profile id and profile type
try {
pieces = html.match(regex);
profileType = pieces[1];
profileID = pieces[2];
} catch(err) {
console.log(err);
profileType = "None";
profileID = "-1";
}
if(profileID == "-1") {
try {
pieces = html.match(regexUID);
profileID = pieces[1];
profileType = "unknown";
} catch(err) {
console.log(err);
profileType = "None";
profileID = "-1";
}
if(profileID == "-1") {
console.log("Error while getting Facebook id");
}
}
console.log(profileID);
html = '';
browser.runtime.sendMessage({
command: "set_facebook_id",
facebook_id: profileID,
facebook_type: profileType
});
}