11/*
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- */
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 ;
@@ -48,12 +48,14 @@ try {
4848 chromeVersion = 33 ;
4949}
5050chromeVersion = parseInt ( chromeVersion ) ;
51- sendMessageToHost ( { version : "2.0.0" } ) ;
51+ sendMessageToHost ( {
52+ version : "2.0.0"
53+ } ) ;
5254
5355if ( localStorage [ "uget-keywords" ] ) {
5456 keywords = localStorage [ "uget-keywords" ] . split ( / [ \s , ] + / ) ;
5557} else {
56- localStorage [ "uget-keywords" ] = '' ;
58+ localStorage [ "uget-keywords" ] = '' ;
5759}
5860
5961
@@ -77,10 +79,10 @@ var message = {
7779// Listen to the key press
7880chrome . extension . onRequest . addListener ( function ( request , sender , sendResponse ) {
7981 var msg = request . message ;
80- if ( msg === 'enable' ) {
82+ if ( msg === 'enable' ) {
8183 // Temporarily enable
8284 setInterruptDownload ( true ) ;
83- } else if ( msg == 'disable' ) {
85+ } else if ( msg == 'disable' ) {
8486 // Temporarily disable
8587 setInterruptDownload ( false ) ;
8688 } else {
@@ -93,22 +95,23 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
9395function sendMessageToHost ( message ) {
9496 chrome . runtime . sendNativeMessage ( hostName , message , function ( response ) {
9597 ugetWrapperNotFound = ( response == null ) ;
96- if ( ! ugetWrapperNotFound ) {
98+ if ( ! ugetWrapperNotFound && ! ugetChromeWrapperVersion ) {
9799 ugetChromeWrapperVersion = response . version ;
98100 ugetVersion = response . uget ;
99101 }
100102 } ) ;
101103}
102104
103105function getInfo ( ) {
104- if ( ugetWrapperNotFound ) {
105- return "<font color='red'>Error: Unable to connect to the uget-chrome-wrapper</font>" ;
106- } else if ( ! ugetChromeWrapperVersion . startsWith ( "2." ) ) {
107- return "<font color='orange'>Warning: Please update the uget-chrome-wrapper to the latest version</font>" ;
108- } else {
109- return "<font color='green'>Info: Found uGet: " + ugetVersion + " and uget-chrome-wrapper: " + ugetChromeWrapperVersion + "</font>" ;
110- }
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+ }
111113}
114+
112115function clearMessage ( ) {
113116 message . url = '' ;
114117 message . cookies = '' ;
@@ -173,7 +176,9 @@ chrome.downloads.onCreated.addListener(function(downloadItem) {
173176 }
174177
175178 chrome . downloads . cancel ( downloadItem . id ) ; // Cancel the download
176- 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
177182
178183 clearMessage ( ) ;
179184 message . url = url ;
@@ -311,7 +316,9 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
311316 message . postdata = '' ;
312317 var scheme = / ^ h t t p s / . test ( details . url ) ? 'https' : 'http' ;
313318 if ( chromeVersion >= 35 ) {
314- return { redirectUrl : "javascript:" } ;
319+ return {
320+ redirectUrl : "javascript:"
321+ } ;
315322 } else if ( details . frameId === 0 ) {
316323 chrome . tabs . update ( details . tabId , {
317324 url : "javascript:"
@@ -374,11 +381,15 @@ function isBlackListed(url) {
374381function setInterruptDownload ( interrupt , writeToStorage ) {
375382 interruptDownloads = interrupt ;
376383 if ( interrupt ) {
377- chrome . browserAction . setIcon ( { path : "./icon_32.png" } ) ;
384+ chrome . browserAction . setIcon ( {
385+ path : "./icon_32.png"
386+ } ) ;
378387 } else {
379- chrome . browserAction . setIcon ( { path : "./icon_disabled_32.png" } ) ;
388+ chrome . browserAction . setIcon ( {
389+ path : "./icon_disabled_32.png"
390+ } ) ;
380391 }
381- if ( writeToStorage ) {
392+ if ( writeToStorage ) {
382393 localStorage [ "uget-interrupt" ] = interrupt . toString ( ) ;
383394 }
384395}
0 commit comments