11/*
2- * uget-chrome-wrapper is an extension to integrate uGet Download manager
3- * with Google Chrome, Chromium and Vivaldi in Linux and Windows.
4- *
5- * Copyright (C) 2016 Gobinath
6- *
7- * This program is free software: you can redistribute it and/or modify
8- * it under the terms of the GNU General Public License as published by
9- * the Free Software Foundation, either version 3 of the License, or
10- * (at your option) any later version.
11- *
12- * This program is distributed in the hope that it will be useful,
13- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15- * GNU General Public License for more details.
16- *
17- * You should have received a copy of the GNU General Public License
18- * along with this program. If not, see <http://www.gnu.org/licenses/>.
19- */
2+ * uget-chrome-wrapper is an extension to integrate uGet Download manager
3+ * with Google Chrome, Chromium, Vivaldi and Opera in Linux and Windows.
4+ *
5+ * Copyright (C) 2016 Gobinath
6+ *
7+ * This program is free software: you can redistribute it and/or modify
8+ * it under the terms of the GNU General Public License as published by
9+ * the Free Software Foundation, either version 3 of the License, or
10+ * (at your option) any later version.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ */
2020
2121var interruptDownloads = true ;
2222var ugetWrapperNotFound = true ;
2323var interruptDownload = false ;
2424var disposition = '' ;
2525var hostName = 'com.javahelps.ugetchromewrapper' ;
26+ var ugetChromeWrapperVersion ;
27+ var ugetVersion ;
2628var chromeVersion ;
2729var filter = [ ] ;
2830var keywords = [ ] ;
@@ -46,12 +48,14 @@ try {
4648 chromeVersion = 33 ;
4749}
4850chromeVersion = parseInt ( chromeVersion ) ;
49- sendMessageToHost ( { version : "1.1.6" } ) ;
51+ sendMessageToHost ( {
52+ version : "2.0.0"
53+ } ) ;
5054
5155if ( localStorage [ "uget-keywords" ] ) {
5256 keywords = localStorage [ "uget-keywords" ] . split ( / [ \s , ] + / ) ;
5357} else {
54- localStorage [ "uget-keywords" ] = '' ;
58+ localStorage [ "uget-keywords" ] = '' ;
5559}
5660
5761
@@ -61,7 +65,6 @@ if (!localStorage["uget-interrupt"]) {
6165 var interrupt = ( localStorage [ "uget-interrupt" ] == "true" ) ;
6266 setInterruptDownload ( interrupt ) ;
6367}
64- console . log ( localStorage [ "uget-interrupt" ] ) ;
6568// Message format to send the download information to the uget-chrome-wrapper
6669var message = {
6770 url : '' ,
@@ -76,10 +79,10 @@ var message = {
7679// Listen to the key press
7780chrome . extension . onRequest . addListener ( function ( request , sender , sendResponse ) {
7881 var msg = request . message ;
79- if ( msg === 'enable' ) {
82+ if ( msg === 'enable' ) {
8083 // Temporarily enable
8184 setInterruptDownload ( true ) ;
82- } else if ( msg == 'disable' ) {
85+ } else if ( msg == 'disable' ) {
8386 // Temporarily disable
8487 setInterruptDownload ( false ) ;
8588 } else {
@@ -92,9 +95,23 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
9295function sendMessageToHost ( message ) {
9396 chrome . runtime . sendNativeMessage ( hostName , message , function ( response ) {
9497 ugetWrapperNotFound = ( response == null ) ;
98+ if ( ! ugetWrapperNotFound && ! ugetChromeWrapperVersion ) {
99+ ugetChromeWrapperVersion = response . version ;
100+ ugetVersion = response . uget ;
101+ }
95102 } ) ;
96103}
97104
105+ function getInfo ( ) {
106+ if ( ugetWrapperNotFound || ! ugetChromeWrapperVersion ) {
107+ return "<font color='red'>Error: Unable to connect to the uget-chrome-wrapper</font>" ;
108+ } else if ( ! ugetChromeWrapperVersion . startsWith ( "2." ) ) {
109+ return "<font color='orange'>Warning: Please update the uget-chrome-wrapper to the latest version</font>" ;
110+ } else {
111+ return "<font color='green'>Info: Found uGet: " + ugetVersion + " and uget-chrome-wrapper: " + ugetChromeWrapperVersion + "</font>" ;
112+ }
113+ }
114+
98115function clearMessage ( ) {
99116 message . url = '' ;
100117 message . cookies = '' ;
@@ -159,7 +176,9 @@ chrome.downloads.onCreated.addListener(function(downloadItem) {
159176 }
160177
161178 chrome . downloads . cancel ( downloadItem . id ) ; // Cancel the download
162- chrome . downloads . erase ( { id : downloadItem . id } ) ; // Erase the download from list
179+ chrome . downloads . erase ( {
180+ id : downloadItem . id
181+ } ) ; // Erase the download from list
163182
164183 clearMessage ( ) ;
165184 message . url = url ;
@@ -297,7 +316,9 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
297316 message . postdata = '' ;
298317 var scheme = / ^ h t t p s / . test ( details . url ) ? 'https' : 'http' ;
299318 if ( chromeVersion >= 35 ) {
300- return { redirectUrl : "javascript:" } ;
319+ return {
320+ redirectUrl : "javascript:"
321+ } ;
301322 } else if ( details . frameId === 0 ) {
302323 chrome . tabs . update ( details . tabId , {
303324 url : "javascript:"
@@ -360,11 +381,15 @@ function isBlackListed(url) {
360381function setInterruptDownload ( interrupt , writeToStorage ) {
361382 interruptDownloads = interrupt ;
362383 if ( interrupt ) {
363- chrome . browserAction . setIcon ( { path : "./icon_32.png" } ) ;
384+ chrome . browserAction . setIcon ( {
385+ path : "./icon_32.png"
386+ } ) ;
364387 } else {
365- chrome . browserAction . setIcon ( { path : "./icon_disabled_32.png" } ) ;
388+ chrome . browserAction . setIcon ( {
389+ path : "./icon_disabled_32.png"
390+ } ) ;
366391 }
367- if ( writeToStorage ) {
392+ if ( writeToStorage ) {
368393 localStorage [ "uget-interrupt" ] = interrupt . toString ( ) ;
369394 }
370395}
0 commit comments