-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
153 lines (145 loc) · 5.42 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
152
153
// converts a binary value to its equivlant string representation.
function binaryToString(binValue) {
return binValue.replace(/[01]{8}/g, function (matchedString) {
return String.fromCharCode(parseInt(matchedString, 2));
});
}
//What happens when you visit NFL.com
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
/*
if(info.url.){
//See if it's survey time
var d = new Date();
var m = d.getMonth();
var date = d.getDate();
var day = d.getDay();
var monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
var mDif = m - parseInt(localStorage.lastM);
var dDif = 0;
if((mDif == 1) || (mDif == -1) || (mDif == -11)){
dDif = monthDays[parseInt(localStorage.lastM)] - parseInt(localStorage.lastD) + date;
}
else if(mDif == 0){
dDif = date - parseInt(localStorage.lastD);
}
else{
dDif = 100;
}
if((day >= 2 && day - dDif < 2) || (day < 2 && day - dDif < -5)){
alert("Please click on the extension window and complete the survey in order to proceed to fantasy football.");
deny = true;
}
if(deny){
return {redirectUrl: "http://brown.edu"};
}
}*/
},
// filters
{
urls: [
"*://football.fantasysports.yahoo.com/*",
"*://*.yahoo.com/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
// extraInfoSpec
["blocking"]);
//Deals with redirect messages
chrome.extension.onRequest.addListener(function(request, sender) {
chrome.tabs.update(sender.tab.id, {url: request.redirect});
});
//Block them from the manager portal in every shape and form
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
if(localStorage.loggedin == "true"){
alert("I'm sorry but you cannot access this content. Please email [email protected] if you believe you arrived here by mistake.");
return {redirectUrl: "http://football.fantasysports.yahoo.com"};
}
},
// filters
{
//All the stuff they can't access on yahoo
urls: [
"*://football.fantasysports.yahoo.com/*deleteteams",
"*://football.fantasysports.yahoo.com/*settings",
"*://football.fantasysports.yahoo.com/*joinleague/*",
"*://football.fantasysports.yahoo.com/*createleague*",
"*://football.fantasysports.yahoo.com/*commishhome*",
"*://football.fantasysports.yahoo.com/*editleaguename",
"*://football.fantasysports.yahoo.com/*editstatcategories",
"*://football.fantasysports.yahoo.com/*editteaminfo",
"*://football.fantasysports.yahoo.com/*invitecomanager",
"*://football.fantasysports.yahoo.com/*share_medal/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
// extraInfoSpec
["blocking"]);
//Lets the content scripts access info
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == "getUsername")
sendResponse({status: localStorage['username']});// else if (request.method == "isIn") sendResponse({status: localStorage['loggedin']});
else if (request.method == "getDay"){
sendResponse({status: localStorage['lastD']});
}if (request.method == "getMonth"){
sendResponse({status: localStorage['lastM']});
}else
sendResponse({});
});
//Collect the pages that they visits
chrome.webRequest.onCompleted.addListener(
function(info){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","http://jack.cs.brown.edu/data.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("type=views&username="+localStorage.username+"&page="+info.url);
},
//filters
{
urls:["*://football.fantasysports.yahoo.com/*"],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["responseHeaders"]);
//Stop chrome from saving their password
chrome.webRequest.onCompleted.addListener(
function(info){
//alert("Start!");
var theTime = (new Date()).getTime() - 100000;
chrome.browsingData.remove({
"since": theTime
},
{
"passwords": true
},
function(){
//alert("Removed!");
});
},
//filters
{
urls:["*://football.fantasysports.yahoo.com/*",
"*://www.yahoo.com/*"],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["responseHeaders"]);
//Log them out if they disable the extension
//the goal here is to listen for chrome://extensions
//and then log them out of yahoo when they visit just in case they disable the extension
//it's less intrusive and cautious
chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
if (change.status == "complete" && tab.url == "chrome://extensions/" && localStorage.loggedin == "true") {
chrome.tabs.create({url : 'http://login.yahoo.com/?logout=1'});
}
});
chrome.tabs.onActivated.addListener(function(selectInfo){
chrome.tabs.get(selectInfo.tabId, function(tab){
if (tab.url == "chrome://extensions/" && localStorage.loggedin == "true") {
chrome.tabs.create({url : 'http://login.yahoo.com/?logout=1'});
}
});
});
//REMEMBER*************
//Plz keep me last
//Log them out of Yahoo if they uninstall
chrome.runtime.setUninstallURL("http://login.yahoo.com/?logout=1");