1
- // uget-chrome-wrapper is an extension to integrate uGet Download manager
2
- // with Google Chrome in Linux systems.
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
+ */
3
20
4
- var enableExtension = true ;
21
+ var interruptDownloads = true ;
5
22
var ugetWrapperNotFound = true ;
6
23
var interruptDownload = false ;
7
24
var disposition = '' ;
8
25
var hostName = 'com.javahelps.ugetchromewrapper' ;
9
26
var chromeVersion ;
10
27
var filter = [ ] ;
28
+ var keywords = [ ] ;
11
29
var requestList = [ {
12
30
cookies : '' ,
13
31
postdata : '' ,
28
46
chromeVersion = 33 ;
29
47
}
30
48
chromeVersion = parseInt ( chromeVersion ) ;
31
- sendMessageToHost ( { version : "1.1.4" } ) ;
49
+ sendMessageToHost ( { version : "1.1.6" } ) ;
50
+
51
+ if ( localStorage [ "uget-keywords" ] ) {
52
+ keywords = localStorage [ "uget-keywords" ] . split ( / [ \s , ] + / ) ;
53
+ } else {
54
+ localStorage [ "uget-keywords" ] = '' ;
55
+ }
32
56
33
57
58
+ if ( ! localStorage [ "uget-interrupt" ] ) {
59
+ localStorage [ "uget-interrupt" ] = 'true' ;
60
+ } else {
61
+ var interrupt = ( localStorage [ "uget-interrupt" ] == "true" ) ;
62
+ setInterruptDownload ( interrupt ) ;
63
+ }
64
+ console . log ( localStorage [ "uget-interrupt" ] ) ;
34
65
// Message format to send the download information to the uget-chrome-wrapper
35
66
var message = {
36
67
url : '' ,
@@ -44,10 +75,17 @@ var message = {
44
75
45
76
// Listen to the key press
46
77
chrome . extension . onRequest . addListener ( function ( request , sender , sendResponse ) {
47
- if ( request . enableEXT == 'false' )
48
- enableExtension = false ;
49
- else
50
- enableExtension = true ;
78
+ var msg = request . message ;
79
+ if ( msg === 'enable' ) {
80
+ // Temporarily enable
81
+ setInterruptDownload ( true ) ;
82
+ } else if ( msg == 'disable' ) {
83
+ // Temporarily disable
84
+ setInterruptDownload ( false ) ;
85
+ } else {
86
+ // Toggle
87
+ setInterruptDownload ( ! interruptDownloads , true ) ;
88
+ }
51
89
} ) ;
52
90
53
91
// Send message to the uget-chrome-wrapper
@@ -95,7 +133,7 @@ chrome.contextMenus.onClicked.addListener(function(info, tab) {
95
133
// Interrupt Google Chrome download
96
134
chrome . downloads . onCreated . addListener ( function ( downloadItem ) {
97
135
98
- if ( ugetWrapperNotFound ) { // uget-chrome-wrapper not installed
136
+ if ( ugetWrapperNotFound || ! interruptDownloads ) { // uget-chrome-wrapper not installed
99
137
return ;
100
138
}
101
139
@@ -116,7 +154,7 @@ chrome.downloads.onCreated.addListener(function(downloadItem) {
116
154
return ;
117
155
}
118
156
119
- if ( url . includes ( "//docs.google.com/" ) || url . includes ( "googleusercontent.com/docs" ) ) { // Cannot download from Google Docs
157
+ if ( isBlackListed ( url ) ) {
120
158
return ;
121
159
}
122
160
@@ -195,7 +233,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
195
233
} ;
196
234
}
197
235
198
- if ( details . url . includes ( "//docs.google.com/" ) || details . url . includes ( "googleusercontent.com/docs" ) ) { // Cannot download from Google Docs
236
+ if ( isBlackListed ( details . url ) ) {
199
237
return {
200
238
responseHeaders : details . responseHeaders
201
239
} ;
@@ -237,7 +275,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
237
275
}
238
276
}
239
277
}
240
- if ( interruptDownload == true && enableExtension == true ) {
278
+ if ( interruptDownload == true && interruptDownloads == true ) {
241
279
for ( var i = 0 ; i < filter . length ; i ++ ) {
242
280
if ( filter [ i ] != "" && contentType . lastIndexOf ( filter [ i ] ) != - 1 ) {
243
281
return {
@@ -284,7 +322,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
284
322
cancel : true
285
323
} ;
286
324
}
287
- enableExtension == true ;
325
+ interruptDownloads == true ;
288
326
clearMessage ( ) ;
289
327
return {
290
328
responseHeaders : details . responseHeaders
@@ -301,3 +339,32 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
301
339
'responseHeaders' ,
302
340
'blocking'
303
341
] ) ;
342
+
343
+ function updateKeywords ( data ) {
344
+ keywords = data . split ( / [ \s , ] + / ) ;
345
+ } ;
346
+
347
+ function isBlackListed ( url ) {
348
+ if ( url . includes ( "//docs.google.com/" ) || url . includes ( "googleusercontent.com/docs" ) ) { // Cannot download from Google Docs
349
+ return true ;
350
+ }
351
+ for ( keyword of keywords ) {
352
+ if ( url . includes ( keyword ) ) {
353
+ return true ;
354
+ }
355
+ }
356
+ return false ;
357
+ }
358
+
359
+
360
+ function setInterruptDownload ( interrupt , writeToStorage ) {
361
+ interruptDownloads = interrupt ;
362
+ if ( interrupt ) {
363
+ chrome . browserAction . setIcon ( { path : "./icon_32.png" } ) ;
364
+ } else {
365
+ chrome . browserAction . setIcon ( { path : "./icon_disabled_32.png" } ) ;
366
+ }
367
+ if ( writeToStorage ) {
368
+ localStorage [ "uget-interrupt" ] = interrupt . toString ( ) ;
369
+ }
370
+ }
0 commit comments