From 55163fac3c978cd0ebcf28e1bff6f16044fcd153 Mon Sep 17 00:00:00 2001 From: Andrew Bananos Date: Sat, 27 Aug 2011 14:16:10 +0300 Subject: [PATCH] Added mock calls to external API + notifications --- _locales/en/messages.json | 8 +--- api.js | 28 ++++++++++++ background.html | 1 + content_script.js | 89 +++++++++++++++++---------------------- manifest.json | 1 + 5 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 api.js diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 9237b88..72d2729 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1,9 +1,5 @@ { "extName": {"message": "Online-Convert.com", "description": "Extension name"}, "extDesc": {"message": "Online-Convert extension", "description": "Extension description"}, - "convert_image": {"message": "Convert image", "description": "image"}, - "convert_doc": {"message": "Convert to document", "description": "doc"}, - "convert_video": {"message": "Convert video", "description": "video"}, - "convert_audio": {"message": "Convert audio", "description": "audio"}, - "convert_ebook": {"message": "Convert page to ebook", "description": "ebook"} -} \ No newline at end of file + "download_video": {"message": "Download video from this page", "description": "video"} + } \ No newline at end of file diff --git a/api.js b/api.js new file mode 100644 index 0000000..21035f7 --- /dev/null +++ b/api.js @@ -0,0 +1,28 @@ +/** +This will contain methods for API calls to + +http://api.online-convert.com/queue-insert + +**/ + + +ocapi = { + + + // This will submit specified URL to queue & return queue hashcode + "submitVideo" : function(url, callback) { + console.log("We are here!"); + + var hashCode = "Myhashccode" + // todo: receive hashcode from remote service & pass it to callback + callback(hashCode); + }, + + // This will check the status of specified conversion process in OC queue by hashCode + "checkStatus" : function(hashCode, callback) { + + return "Blyaaa!" + } + + +} \ No newline at end of file diff --git a/background.html b/background.html index 4dc2b02..f554392 100644 --- a/background.html +++ b/background.html @@ -1 +1,2 @@ + \ No newline at end of file diff --git a/content_script.js b/content_script.js index 85ca473..07bd37a 100644 --- a/content_script.js +++ b/content_script.js @@ -1,55 +1,49 @@ -var conversion_page='?external_url=' -var links = { - // image: 'http://image-conversion.online-convert.com/', - // ebook: 'http://ebook-conversion.online-convert.com/', -// doc: 'http://document-conversion.online-convert.com/', - video: 'http://video-conversion.online-convert.com/' -// audio: 'http://audio-conversion.online-convert.com/' -} -// -// function convert_image(info, tab) { -// var img_url = info.linkUrl || info.srcUrl; -// var url = links.image+conversion_page+img_url; -// window.open(url); -// } -// -// function convert_ebook(info, tab) { -// var url = links.ebook+conversion_page+info.pageUrl; -// window.open(url); -// } -// -// function convert_doc(info, tab) { -// chrome.tabs.sendRequest(tab.id, {"msg": "findImages"}, function(r){ -// images = ""; -// for (img in r.images) -// images += r.images[img].url; -// alert(images); -// }); -// -// var url = links.doc+conversion_page+(info.linkUrl || info.pageUrl); -// } + + +/** +Submits current page URL into OC queue +**/ function convert_video(info, tab) { - var url = links.video+conversion_page+info.pageUrl; - console.log("Info:" + info); - console.log("Tab:" + tab) + var pageUrl = info.pageUrl; + + // console.log(info); + // console.log(tab) // window.open(url); + + // submit URL to OC queue + ocapi.submitVideo(pageUrl, function(hashCode) { + // alert("Hashcode:" + hashCode) + + // Create a simple text notification: + var notification = webkitNotifications.createNotification( + 'logo.png', // icon url - can be relative + 'Hello!', // notification title + 'Lorem ipsum...' // notification body text + ); + + // // Or create an HTML notification: + // var notification = webkitNotifications.createHTMLNotification( + // 'notification.html' // html url - can be relative + // ); + + // Then show the notification. + notification.show(); + }); + + + + + + } -// var image_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("convert_image"), -// "contexts": ["image"], -// "onclick": convert_image}); -// -// var ebook_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("convert_ebook"), -// "contexts": ["page"], -// "onclick": convert_ebook}); -// -// var doc_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("convert_doc"), -// "contexts": ["page", "link"], -// "onclick": convert_doc}); -var video_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("convert_video"), + +/* inject "Download" link into page/link context menus */ + +var video_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("download_video"), "contexts": ["page", "link"], "onclick": convert_video // "documentUrlPatterns": ['*://*.youtube.com/watch*', @@ -57,8 +51,3 @@ var video_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("co // '*://5min.com/*', // ] }); - -// -// var audio_menu = chrome.contextMenus.create({"title": chrome.i18n.getMessage("convert_audio"), -// "contexts": ["link"], -// "onclick": convert_audio}); diff --git a/manifest.json b/manifest.json index e81c805..cc20ba0 100644 --- a/manifest.json +++ b/manifest.json @@ -6,6 +6,7 @@ "description": "__MSG_extDesc__", "version": "0.1", "permissions": ["contextMenus", + "notifications", "http://*/*", "https://*/*"], "background_page": "background.html",