-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html~
166 lines (144 loc) · 5.5 KB
/
background.html~
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
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>untitled</title>
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript" src="background-init.js"></script>
<script type="text/javascript" src="schedule-scraper.js"></script>
<script type="text/javascript" src="tv_shows.js"></script>
<script type="text/javascript">
//schedule('The Amazing Race', onResults);
function onResults(episodes){
console.log(episodes);
}
var calPort = null;
// Inject javascript
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.executeScript(tab.id, {file: "content_script.js"});
chrome.tabs.create({ url: "https://www.google.com/calendar/" }, setCalTab);
if(tab.url.match(/http:\/\/www.youtube.com\/watch\?v\=([A-Za-z0-9_]|\-){11}/)) {
//var calUrl = "http://www.google.com/calendar/render?tab=mc";
var timeInfo = new Date();
var year = timeInfo.getFullYear();
var month = timeInfo.getMonth() + 1;
var day = timeInfo.getDate();
var hours = timeInfo.getHours();
var mins = timeInfo.getMinutes();
var secs = timeInfo.getSeconds();
var episode = {
year: year.toString(),
month: month.toString(),
day: day.toString(),
time: "" + hours + ":" + mins,
}
//var startTime = "" + year + "" + month + "" + day + "T" + hours + "" + mins + "" + secs;
//var endTime = "/" + year + "" + month + "" + day + "T" + hours + "" + (mins + 1) + "" + secs;
var timeStr = formatYTDate(episode);
//var desc = ripDescription(tab);
var ytPort = chrome.tabs.connect(tab.id);
ytPort.onMessage.addListener(function getResp(response) {
if(response.title) {
chrome.extension.getBackgroundPage().localStorage['title'] = response.title;
}
else {
chrome.extension.getBackgroundPage().localStorage['description'] = response.description;
}
});
ytPort.postMessage({ act: "get title" });
ytPort.postMessage({ act: "get description" });
//chrome.tabs.executeScript(tab.id, { code: "getVideoDescription()" }, null);
var eventInfo = {
sf: 'true',
output: 'js',
action: 'CREATE',
crm: 'BUSY',
icc: 'PUBLIC',
text: localStorage['title'] ? localStorage['title'] : "MediaCalendar",
location: tab.url,
details: localStorage['description'] ? localStorage['description'] : "N/A",
dates: timeStr,
scp: 'ONE'
}
var dt = new Date();
while((new Date() - dt) < 5000) {
//console.log('Waitin');
}
chrome.tabs.getAllInWindow(null, function(ts) {
for(var i = 0; i < ts.length; i++) {
if(ts[i].url.indexOf("http://www.google.com/calendar") == 0 || ts[i].url.indexOf("https://www.google.com/calendar") == 0) {
//chrome.tabs.executeScript();
chrome.tabs.executeScript(ts[i].id, {file: "content_script.js"});
calPort = chrome.tabs.connect(ts[i].id);
calPort.onMessage.addListener(function getResp(response) {
if(response.success == "success") {
console.log('SUCCESS');
}
else {
console.log('FAILURE awwwwww');
}
});
calPort.postMessage({ act: "post event", info: eventInfo });
break;
}
}
});
//localStorage.clear();
//window.close();
}
});
});
function setCalTab(tab) {
calTab = tab;
}
/*chrome.extension.onRequest.addListener(function(req, sender, resp) {
if(req.action == "add") {
console.log(sender.tab ? "Add from tab" : "Add from extern");
// get relevant info
var eventTitle = req.title;
var videoUrl = req.url;
var year = req.year;
var month = req.month;
var date = req.day;
var trueHour = req.hours;
var medHour = trueHour % 12;
var min = req.mins;
console.log(req);
// construct quick add string
var nameStr = "" + month + "/" + date + "/" + year + " ";
if(medHour == 0)
nameStr += "12"
else
nameStr += medHour;
if(trueHour > 11)
nameStr += "pm ";
else
nameStr += "am ";
nameStr += eventTitle;
// find calendar tab
var calWin = null;
var views = chrome.extension.getViews({ type: "tab" });
for(var i = 0; i < views.length; i++) {
if(views[i].location.href == req.cal.url) {
calWin = views[i];
break;
}
}
if(calWin == null) {
resp({ success: "false" });
return;
}
// lookup quickadd textbox and add button
$("textarea:contains(1r)").attr('textContent', nameStr);
$("div.qab-container.gcal-popup > div.goog-inline-block.goog-imageless-button").trigger('mouseup');
resp({ success: "true" });
}
else {
resp({});
}
});*/
</script>
</head>
</html>