1
1
/*
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
+ */
20
20
21
21
var interruptDownloads = true ;
22
22
var ugetWrapperNotFound = true ;
23
23
var interruptDownload = false ;
24
24
var disposition = '' ;
25
25
var hostName = 'com.javahelps.ugetchromewrapper' ;
26
+ var ugetChromeWrapperVersion ;
27
+ var ugetVersion ;
26
28
var chromeVersion ;
27
29
var filter = [ ] ;
28
30
var keywords = [ ] ;
@@ -46,12 +48,14 @@ try {
46
48
chromeVersion = 33 ;
47
49
}
48
50
chromeVersion = parseInt ( chromeVersion ) ;
49
- sendMessageToHost ( { version : "1.1.6" } ) ;
51
+ sendMessageToHost ( {
52
+ version : "2.0.0"
53
+ } ) ;
50
54
51
55
if ( localStorage [ "uget-keywords" ] ) {
52
56
keywords = localStorage [ "uget-keywords" ] . split ( / [ \s , ] + / ) ;
53
57
} else {
54
- localStorage [ "uget-keywords" ] = '' ;
58
+ localStorage [ "uget-keywords" ] = '' ;
55
59
}
56
60
57
61
@@ -61,7 +65,6 @@ if (!localStorage["uget-interrupt"]) {
61
65
var interrupt = ( localStorage [ "uget-interrupt" ] == "true" ) ;
62
66
setInterruptDownload ( interrupt ) ;
63
67
}
64
- console . log ( localStorage [ "uget-interrupt" ] ) ;
65
68
// Message format to send the download information to the uget-chrome-wrapper
66
69
var message = {
67
70
url : '' ,
@@ -76,10 +79,10 @@ var message = {
76
79
// Listen to the key press
77
80
chrome . extension . onRequest . addListener ( function ( request , sender , sendResponse ) {
78
81
var msg = request . message ;
79
- if ( msg === 'enable' ) {
82
+ if ( msg === 'enable' ) {
80
83
// Temporarily enable
81
84
setInterruptDownload ( true ) ;
82
- } else if ( msg == 'disable' ) {
85
+ } else if ( msg == 'disable' ) {
83
86
// Temporarily disable
84
87
setInterruptDownload ( false ) ;
85
88
} else {
@@ -92,9 +95,23 @@ chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
92
95
function sendMessageToHost ( message ) {
93
96
chrome . runtime . sendNativeMessage ( hostName , message , function ( response ) {
94
97
ugetWrapperNotFound = ( response == null ) ;
98
+ if ( ! ugetWrapperNotFound && ! ugetChromeWrapperVersion ) {
99
+ ugetChromeWrapperVersion = response . version ;
100
+ ugetVersion = response . uget ;
101
+ }
95
102
} ) ;
96
103
}
97
104
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
+
98
115
function clearMessage ( ) {
99
116
message . url = '' ;
100
117
message . cookies = '' ;
@@ -159,7 +176,9 @@ chrome.downloads.onCreated.addListener(function(downloadItem) {
159
176
}
160
177
161
178
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
163
182
164
183
clearMessage ( ) ;
165
184
message . url = url ;
@@ -297,7 +316,9 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
297
316
message . postdata = '' ;
298
317
var scheme = / ^ h t t p s / . test ( details . url ) ? 'https' : 'http' ;
299
318
if ( chromeVersion >= 35 ) {
300
- return { redirectUrl : "javascript:" } ;
319
+ return {
320
+ redirectUrl : "javascript:"
321
+ } ;
301
322
} else if ( details . frameId === 0 ) {
302
323
chrome . tabs . update ( details . tabId , {
303
324
url : "javascript:"
@@ -360,11 +381,15 @@ function isBlackListed(url) {
360
381
function setInterruptDownload ( interrupt , writeToStorage ) {
361
382
interruptDownloads = interrupt ;
362
383
if ( interrupt ) {
363
- chrome . browserAction . setIcon ( { path : "./icon_32.png" } ) ;
384
+ chrome . browserAction . setIcon ( {
385
+ path : "./icon_32.png"
386
+ } ) ;
364
387
} else {
365
- chrome . browserAction . setIcon ( { path : "./icon_disabled_32.png" } ) ;
388
+ chrome . browserAction . setIcon ( {
389
+ path : "./icon_disabled_32.png"
390
+ } ) ;
366
391
}
367
- if ( writeToStorage ) {
392
+ if ( writeToStorage ) {
368
393
localStorage [ "uget-interrupt" ] = interrupt . toString ( ) ;
369
394
}
370
395
}
0 commit comments