-
Notifications
You must be signed in to change notification settings - Fork 3
/
sync.html
180 lines (161 loc) · 6.12 KB
/
sync.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<!--///////////////////////////////////////////////////////////////////////
// //
// Switchy! Chrome Proxy Manager and Switcher //
// Copyright (c) 2009 Mohammad Hejazi (mohammadhi at gmail d0t com) //
// Dual licensed under the MIT and GPL licenses. //
// //
////////////////////////////////////////////////////////////////////////-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Switchy! Sync</title>
<link rel="stylesheet" href="assets/styles/options.css" type="text/css">
<link rel="stylesheet" href="assets/styles/infoTip.css" type="text/css">
<link rel="stylesheet" href="assets/styles/helpToolTip.css" type="text/css">
<script src="assets/libs/jquery-1.4.min.js" type="text/javascript"></script>
<script src="assets/scripts/options.js" type="text/javascript"></script>
<script src="assets/scripts/infoTip.js" type="text/javascript"></script>
<script src="assets/scripts/helpToolTip.js" type="text/javascript"></script>
<body>
<div class="title">
xxxxxxx
</div>
<script type="text/javascript" src="http://www.google.com/jsapi?key=YOUR_KEY_HERE"></script>
<script type="text/javascript">
<!--
/* Loads the Google data JavaScript client library */
google.load("gdata", "2.x");
function init() {
// init the Google data JS client library with an error handler
google.gdata.client.init(handleGDError);
// load the code.google.com developer calendar
loadDeveloperCalendar();
}
function loadDeveloperCalendar() {
loadCalendarByAddress('mohammadhi@gmail.com');
}
function padNumber(num) {
if (num <= 9) {
return "0" + num;
}
return num;
}
function loadCalendarByAddress(calendarAddress) {
var calendarUrl = 'http://www.google.com/calendar/feeds/' +
calendarAddress +
'/public/full';
loadCalendar(calendarUrl);
}
/**
* Uses Google data JS client library to retrieve a calendar feed from the specified
* URL. The feed is controlled by several query parameters and a callback
* function is called to process the feed results.
*
* @param {string} calendarUrl is the URL for a public calendar feed
*/
function loadCalendar(calendarUrl) {
var service = new
google.gdata.calendar.CalendarService('gdata-js-client-samples-simple');
var query = new google.gdata.calendar.CalendarEventQuery(calendarUrl);
query.setOrderBy('starttime');
query.setSortOrder('ascending');
query.setFutureEvents(true);
query.setSingleEvents(true);
query.setMaxResults(10);
service.getEventsFeed(query, listEvents, handleGDError);
}
/**
* Callback function for the Google data JS client library to call when an error
* occurs during the retrieval of the feed. Details available depend partly
* on the web browser, but this shows a few basic examples. In the case of
* a privileged environment using ClientLogin authentication, there may also
* be an e.type attribute in some cases.
*
* @param {Error} e is an instance of an Error
*/
function handleGDError(e) {
document.getElementById('jsSourceFinal').setAttribute('style',
'display:none');
if (e instanceof Error) {
/* alert with the error line number, file and message */
alert('Error at line ' + e.lineNumber +
' in ' + e.fileName + '\n' +
'Message: ' + e.message);
/* if available, output HTTP error code and status text */
if (e.cause) {
var status = e.cause.status;
var statusText = e.cause.statusText;
alert('Root cause: HTTP error ' + status + ' with status text of: ' +
statusText);
}
} else {
alert(e.toString());
}
}
/**
* Callback function for the Google data JS client library to call with a feed
* of events retrieved.
*
* Creates an unordered list of events in a human-readable form. This list of
* events is added into a div called 'events'. The title for the calendar is
* placed in a div called 'calendarTitle'
*
* @param {json} feedRoot is the root of the feed, containing all entries
*/
function listEvents(feedRoot) {
var entries = feedRoot.feed.getEntries();
var eventDiv = document.getElementById('events');
if (eventDiv.childNodes.length > 0) {
eventDiv.removeChild(eventDiv.childNodes[0]);
}
/* create a new unordered list */
var ul = document.createElement('ul');
/* set the calendarTitle div with the name of the calendar */
document.getElementById('calendarTitle').innerHTML =
"Calendar: " + feedRoot.feed.title.$t;
/* loop through each event in the feed */
var len = entries.length;
for (var i = 0; i < len; i++) {
var entry = entries[i];
var title = entry.getTitle().getText();
var startDateTime = null;
var startJSDate = null;
var times = entry.getTimes();
if (times.length > 0) {
startDateTime = times[0].getStartTime();
startJSDate = startDateTime.getDate();
}
var entryLinkHref = null;
if (entry.getHtmlLink() != null) {
entryLinkHref = entry.getHtmlLink().getHref();
}
var dateString = (startJSDate.getMonth() + 1) + "/" + startJSDate.getDate();
if (!startDateTime.isDateOnly()) {
dateString += " " + startJSDate.getHours() + ":" +
padNumber(startJSDate.getMinutes());
}
var li = document.createElement('li');
/* if we have a link to the event, create an 'a' element */
if (entryLinkHref != null) {
entryLink = document.createElement('a');
entryLink.setAttribute('href', entryLinkHref);
entryLink.appendChild(document.createTextNode(title));
li.appendChild(entryLink);
li.appendChild(document.createTextNode(' - ' + dateString));
} else {
li.appendChild(document.createTextNode(title + ' - ' + dateString));
}
/* append the list item onto the unordered list */
ul.appendChild(li);
}
eventDiv.appendChild(ul);
}
//google.setOnLoadCallback(init);
//-->
</script>
<div id="calendarTitle"></div>
<div id="events"></div>
<script type="text/javascript">
loadCalendar('http://www.google.com/calendar/feeds/developer-calendar@google.com/public/full');
</script>
</body>
</html>