Permalink
Browse files

code done

  • Loading branch information...
1 parent a9b1556 commit c6ce31ef9612ef8e963ae5ac21a6cae5150647e2 @scottcheng committed Jun 12, 2012
View
@@ -0,0 +1,2 @@
+*.swp
+*~
View
@@ -1,2 +1,3 @@
-save2drive
-==========
+Save2Drive
+====
+
View
@@ -0,0 +1,83 @@
+{
+ "extName": {
+ "message": "Save2Drive",
+ "description": "Extension name"
+ },
+ "extDesc": {
+ "message": "",
+ "description": "Extension description"
+ },
+
+ "menuItemTextLink": {
+ "message": "Save link to Drive",
+ "description": "Text to display on the context menu item of a link"
+ },
+ "menuItemTextImage": {
+ "message": "Save image to Drive",
+ "description": "Text to display on the context menu item of an image"
+ },
+ "menuItemTextAudio": {
+ "message": "Save audio to Drive",
+ "description": "Text to display on the context menu item of an audio"
+ },
+ "menuItemTextVideo": {
+ "message": "Save video to Drive",
+ "description": "Text to display on the context menu item of a video"
+ },
+
+ "notifSavingLink": {
+ "message": "Saving link to Drive...",
+ "description": "Text to display on the desktop notification when saving a link"
+ },
+ "notifSavingImage": {
+ "message": "Saving image to Drive...",
+ "description": "Text to display on the desktop notification when saving an image"
+ },
+ "notifSavingAudio": {
+ "message": "Saving audio to Drive...",
+ "description": "Text to display on the desktop notification when saving an audio"
+ },
+ "notifSavingVideo": {
+ "message": "Saving video to Drive...",
+ "description": "Text to display on the desktop notification when saving a video"
+ },
+
+ "notifSucLink": {
+ "message": "Link saved to Drive",
+ "description": "Text to display on the desktop notification on successfully saving a link"
+ },
+ "notifSucImage": {
+ "message": "Image saved to Drive",
+ "description": "Text to display on the desktop notification on successfully saving an image"
+ },
+ "notifSucAudio": {
+ "message": "Audio saved to Drive",
+ "description": "Text to display on the desktop notification on successfully saving an audio"
+ },
+ "notifSucVideo": {
+ "message": "Video saved to Drive",
+ "description": "Text to display on the desktop notification on successfully saving a video"
+ },
+
+ "notifErrLink": {
+ "message": "Failed to save link to Drive",
+ "description": "Text to display on the desktop notification on failing to saving a link"
+ },
+ "notifErrImage": {
+ "message": "Failed to save image to Drive",
+ "description": "Text to display on the desktop notification on failing to saving an image"
+ },
+ "notifErrAudio": {
+ "message": "Failed to save audio to Drive",
+ "description": "Text to display on the desktop notification on failing to saving an audio"
+ },
+ "notifErrVideo": {
+ "message": "Failed to save video to Drive",
+ "description": "Text to display on the desktop notification on failing to saving a video"
+ },
+
+ "notifLinkText": {
+ "message": "Visit Google Drive",
+ "description": "Text to display on the notification body"
+ }
+}
@@ -0,0 +1,2 @@
+{
+}
View
@@ -0,0 +1,83 @@
+// Save2Drive by Scott Cheng
+// Background script
+
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-32579564-1']);
+_gaq.push(['_trackPageview']);
+
+(function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = 'https://ssl.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+
+var capitalise = function(s) {
+ return s.charAt(0).toUpperCase() + s.slice(1);
+};
+
+
+// Add context menu
+(function(){
+ var contexts = ['link', 'image', 'audio', 'video'];
+ for (var i in contexts) {
+ (function() {
+ var context = contexts[i];
+ chrome.contextMenus.create({
+ title: chrome.i18n.getMessage('menuItemText' + capitalise(context)),
+ contexts: [context],
+ onclick: function(info, tab) {
+ if (context === 'link') {
+ saveToDrive(info.linkUrl, context);
+ } else {
+ saveToDrive(info.srcUrl, context);
+ }
+ }
+ });
+ })();
+ }
+})();
+
+var saveToDrive = function(url, context) {
+ _gaq.push(['_trackEvent', 'Save', 'clickSave', context]);
+
+ // Indicate saving in progress
+ showNotif(context);
+
+ var target = 'https://docs.google.com/viewer?a=sv&url=' + encodeURIComponent(url);
+ $.get(target, function(data, textStatus, jqXHR) {
+ onSaveSuccess(context, data, textStatus, jqXHR);
+ }, 'html').error(function(jqXHR, textStatus, errorThrown) {
+ onSaveError(context, jqXHR, textStatus, errorThrown);
+ });
+};
+
+var onSaveSuccess = function(context) {
+ _gaq.push(['_trackEvent', 'Save', 'succeed']);
+
+ chrome.extension.getViews({type:"notification"}).forEach(function(win) {
+ win.onSaveSuccess();
+ });
+};
+
+var onSaveError = function(context, textStatus) {
+ _gaq.push(['_trackEvent', 'Save', 'fail', textStatus]);
+
+ chrome.extension.getViews({type:"notification"}).forEach(function(win) {
+ win.onSaveError();
+ });
+};
+
+var showNotif = (function() {
+ var notif;
+ return function(context) {
+ notif && notif.cancel();
+ notif = window.webkitNotifications.createHTMLNotification(
+ 'notif.html?context=' + context
+ );
+ notif.show();
+ };
+})();
+
+var onVisitDrive = function() {
+ _gaq.push(['_trackEvent', 'Notification', 'visitDrive']);
+};
View
Oops, something went wrong.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,26 @@
+{
+ "name": "__MSG_extName__",
+ "version": "0.0.6",
+ "description": "__MSG_extDesc__",
+ "permissions": [
+ "contextMenus",
+ "notifications",
+ "https://docs.google.com/viewer"
+ ],
+ "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
+ "background": {
+ "scripts": [
+ "lib/jquery.min.js",
+ "background.js"
+ ]
+ },
+ "default_locale": "en",
+ "icons": {
+ "48": "ui/logo_48.png"
+ },
+ "web_accessible_resources": [
+ "ui/logo_48.png",
+ "ui/logo2_48.png"
+ ],
+ "manifest_version": 2
+}
View
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <style type="text/css">
+#notifIcon {
+ float: left;
+ margin-right: 9px;
+ margin-bottom: 9px;
+ height: 48px;
+ width: 48px;
+ background-image: url(ui/logo_48.png);
+ background-repeat: no-repeat;
+}
+
+#textWrapper {
+ padding-top: 9px;
+}
+#notifMsg,
+#link2Drive {
+ font-family: Tahoma, Sans-Serif;
+ font-size: 12px;
+}
+#notifMsg {
+ color: #444;
+ font-weight: bold;
+}
+#link2Drive {
+
+}
+ </style>
+ </head>
+ <body>
+ <div id="notifIcon"></div>
+ <div id="textWrapper">
+ <div id="notifMsg"></div>
+ <div><a id="link2Drive" href="https://drive.google.com/" target="_blank"></a></div>
+ </div>
+
+ <script type="text/javascript" src="lib/jquery.min.js"></script>
+ <script type="text/javascript" src="notif.js"></script>
+ </body>
+</html>
View
@@ -0,0 +1,32 @@
+var capitalise = function(s) {
+ return s.charAt(0).toUpperCase() + s.slice(1);
+};
+
+var context = window.location.search.split('=')[1];
+
+var $msg = $('#notifMsg');
+var $link = $('#link2Drive');
+
+$msg.html(chrome.i18n.getMessage('notifSaving' + capitalise(context)));
+$link.html(chrome.i18n.getMessage('notifLinkText'));
+
+$link.click(function() {
+ chrome.extension.getBackgroundPage().onVisitDrive();
+ window.close();
+});
+
+var onSaveSuccess = function() {
+ $msg.html(chrome.i18n.getMessage('notifSuc' + capitalise(context)));
+ startTimeout();
+};
+
+var onSaveError = function() {
+ $msg.html(chrome.i18n.getMessage('notifErr' + capitalise(context)));
+ startTimeout();
+};
+
+var startTimeout = function() {
+ window.setTimeout(function() {
+ window.close();
+ }, 3000);
+};
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c6ce31e

Please sign in to comment.