-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
executable file
·151 lines (128 loc) · 5.14 KB
/
background.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
/* background.js
* author: Liam Horne, Shane Creighton-Young
* project: fbplus
*
*/
/* This is for after they press ENTER. 'text' is the string they send */
chrome.omnibox.onInputEntered.addListener(
function(text) {
// Function to update a Chrome tab
function updateChromeTab (address) {
chrome.tabs.getSelected( undefined, function(tab) {
chrome.tabs.update(tab.id, {url: address}, undefined);
window.close(); });
}
// cmd : The variable that stores the first word in user input
var cmd;
// data : The variable that stores the rest of the input
var data = "";
// singleCmd : Boolean to determine if the input is just one command
var singleCmd = new Boolean();
// Determines if there is a space character in the input and sets singleCmd
// search() produces -1 when there is no space
if (text.search(" ") == -1) {
singleCmd = true;
} else {
singleCmd = false;
}
// Sets the value for cmd and possibly data
if (singleCmd) {
cmd = text;
} else {
cmd = text.substr(0, text.indexOf(" ")); // otherwise cmd is the first word up to a space character
data = text.substr(text.indexOf(" ") + 1);
}
userData = JSON.parse(localStorage['userData']);
// If data is a name (i.e., FirstName LastName, convert to ID ########)
function ensureId (name) {
if (data.search(" ") != - 1) {
for (var i = 0; i < userData.length; i++) {
if (name == userData[i].name) {
return userData[i].username;
break;
}
}
} else {
return name;
}
}
data = ensureId(data);
var commands = new Array();
var numCommands = 0;
function makeCommand (command, fun) {
commands[numCommands] = new Array(2);
commands[numCommands][0] = command;
commands[numCommands][1] = fun;
numCommands++;
}
function redirect (link, alternate) {
if(singleCmd) {
updateChromeTab (link);
} else {
updateChromeTab (alternate)
}
}
function findField(info, name) {
for(var i = 0; i < userData.length; i++) {
if (name == userData[i].name || name == userData[i].username) {
return userData[i][info];
break;
}
}
}
function findHometown(name) {
for(var i = 0; i < userData.length; i++) {
if (name == userData[i].name || name == userData[i].username) {
return userData[i].hometown.name;
break;
}
}
}
var helpMessage = "Commands in FB Plus \n For commands with a <name> parameter, \
use the Facebook name of a specific friend! If no name is inputted, \
it will redirect to your own page. \
\n help - Display This Alert! \
\n home - News Feed \
\n pics <name> - Photos \
\n home - News Feed \
\n pics <ID> - Photos \
\n timelines <ID> - Timeline \
\n events - Events \
\n msg <name> - Messages \
\n groups - Groups \
\n apps - Applications \
\n friends <name> - Friends \
\n gender <name> - Alert with gender \
\n id <name> - Alert with id \
\n username <name> - Alert with name";
// Database for redirect commands
makeCommand("home", function() {redirect("http://www.facebook.com", undefined)});
makeCommand("search", function() {redirect("https://www.facebook.com/search/results.php?q=", "https://www.facebook.com/search/results.php?q=" + data)});
makeCommand("pics", function() {redirect("http://www.facebook.com/me/photos", "http://www.facebook.com/"+data+"/photos")});
makeCommand("events", function() {redirect("https://www.facebook.com/events/list", undefined)});
makeCommand("msg", function() {redirect("https://www.facebook.com/messages/", "https://www.facebook.com/messages/"+data)});
makeCommand("groups", function() {redirect("https://www.facebook.com/bookmarks/groups", undefined)});
makeCommand("apps", function() {redirect("https://www.facebook.com/bookmarks/apps", undefined)});
makeCommand("timeline", function() {redirect("https://www.facebook.com/me/friends", "https://www.facebook.com/"+data)});
makeCommand("friends", function() {redirect("https://www.facebook.com/me/friends", "https://www.facebook.com/"+data+"/friends")});
makeCommand("gender", function() {alert(findField('gender',data))});
makeCommand("id", function() {alert(findField('id',data))});
makeCommand("username", function() {alert(findField('username',data))});
/*
makeCommand("birthday", function() {alert(findField('birthday',data))});
makeCommand("hometown", function() {alert(findHometown(data))});
*/
makeCommand("help", function() {alert(helpMessage)});
// The main function we use to check for redirect commands
// It goes through each entry in redirects and checks if the input command is the
// 'command' value of the redirect, if it is then applies 'link' or 'alternate'
function checkCommands () {
for (var j = 0; j < numCommands; j++) {
if (cmd == commands[j][0]) {
commands[j][1]();
break;
}
}
}
checkCommands();
});