forked from antimatter15/cloudsave
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloudsave.html
171 lines (142 loc) · 4.32 KB
/
cloudsave.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
<script src="background.js"></script>
<script>
var root = chrome.contextMenus.create({
"title" : "Cloud Save YG",
"type" : "normal",
"contexts" : ["page", "image", "link"]
});
var asroot = chrome.contextMenus.create({
"title" : "Save As...",
"type" : "normal",
"parentId": root,
"contexts" : ["page", "image", "link"]
});
chrome.contextMenus.create({
"type" : "separator",
"contexts": ["all"],
"parentId": root
});
var Hosts = {};
var hosts = {
/*
"gdocs": ["Google Docs", "link", "page"],
"dropbox": ["Dropbox", "link", "image", "page"],
"cloudapp": ["CloudApp", "link", "image", "page"],
"box": ["Box.net", "link", "image", "page"],
"minus": ["Min.us", "link", "image", "page"],
"droplr": ["Droplr", "link", "image", "page"],
"picasa": ["Picasa", "image"],
"flickr": ["Flickr", "image"],
"posterous": ["Posterous", "image"],
"twitpic": ["Twitpic", "image"],
*/
"vdisk": [chrome.i18n.getMessage("vdisk"), "link", "image", "page"]
}, menus = {};
function contextClick2(info, tab){
var url = info.linkUrl || info.srcUrl;
var name = prompt("What would you like to save the file as?",unescape(unescape(unescape(url))).replace(/^.*\/|\?.*$|\#.*$|\&.*$/g,''));
if(name){
upload(menus[info.menuItemId], url, name);
}
}
function contextClick(info, tab){
var url = info.linkUrl || info.srcUrl;
var name = unescape(unescape(unescape(url))).replace(/^.*\/|\?.*$|\#.*$|\&.*$/g,'');
upload(menus[info.menuItemId], url, name);
}
function upload(host, url, name){
Hosts[host]({
url: url,
name: name
}, function(e){
console.log('uploaded file yay', e);
if(e && e.indexOf('error:') != -1){
var notification = webkitNotifications.createNotification(
'icon/64sad.png', // icon url - can be relative
"Aww Snap!", // notification title
"The file '"+name+"' could not be uploaded to "+hosts[host][0]+". "+e.substr(6) // notification body text
);
notification.show();
}else{
var notification = webkitNotifications.createNotification(
'icon/64.png', // icon url - can be relative
"Uploading Complete", // notification title
"The file '"+name+"' has been uploaded to "+hosts[host][0]+"." // notification body text
);
notification.show();
}
})
}
for(var i in hosts){
menus[chrome.contextMenus.create({
title: hosts[i][0],
type: "normal",
contexts: hosts[i].slice(1),
parentId: root,
onclick: contextClick
})] = i;
menus[chrome.contextMenus.create({
title: hosts[i][0],
type: "normal",
contexts: hosts[i].slice(1),
parentId: asroot,
onclick: contextClick2
})] = i;
}
chrome.contextMenus.create({
"type" : "separator",
"contexts": ["all"],
"parentId": root
});
chrome.contextMenus.create({
"title" : chrome.i18n.getMessage("clearLocalStorage"),
"type" : "normal",
"parentId": root,
"onclick": function(){
localStorage.clear();
},
"contexts" : ["all"]
});
/*
chrome.contextMenus.create({
"title" : "Add/Remove",
"type" : "normal",
"parentId": root,
"onclick": function(){
chrome.tabs.create({
url: "settings.html"
})
},
"contexts" : ["all"]
});
*/
</script>
<script src="hosts/js/sha1.js"></script>
<script src="hosts/js/md5.js"></script>
<script src="hosts/js/crypto-sha256.js"></script>
<script src="hosts/js/hmac-min.js"></script>
<script src="files.js"></script>
<script src="hosts/keys.js"></script>
<!--
<script src="hosts/box.js"></script>
<script src="hosts/minus.js"></script>
<script src="hosts/cloudapp.js"></script>
<script src="hosts/flickr.js"></script>
<script src="hosts/google/chrome_ex_oauthsimple.js"></script>
<script src="hosts/google/chrome_ex_oauth.js"></script>
<script src="hosts/google/google.js"></script>
<script src="hosts/google/picasa.js"></script>
<script src="hosts/google/docs.js"></script>
<script src="hosts/dropbox/oauth.js"></script>
<script src="hosts/dropbox/modern_dropbox.js"></script>
<script src="hosts/dropbox/dropbox.js"></script>
<script src="hosts/twitter.js"></script>
<script src="hosts/twitpic.js"></script>
<script src="hosts/twitgoo.js"></script>
<script src="hosts/posterous.js"></script>
<script src="hosts/twitrpix.js"></script>
<script src="hosts/imgly.js"></script>
<script src="hosts/droplr.js"></script>
-->
<script src="hosts/sina/url.js"></script>
<script src="hosts/sina/vdisk.js"></script>