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+ */
320
4- var enableExtension = true ;
21+ var interruptDownloads = true ;
522var ugetWrapperNotFound = true ;
623var interruptDownload = false ;
724var disposition = '' ;
825var hostName = 'com.javahelps.ugetchromewrapper' ;
926var chromeVersion ;
1027var filter = [ ] ;
28+ var keywords = [ ] ;
1129var requestList = [ {
1230 cookies : '' ,
1331 postdata : '' ,
2846 chromeVersion = 33 ;
2947}
3048chromeVersion = 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+ }
3256
3357
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" ] ) ;
3465// Message format to send the download information to the uget-chrome-wrapper
3566var message = {
3667 url : '' ,
@@ -44,10 +75,17 @@ var message = {
4475
4576// Listen to the key press
4677chrome . 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+ }
5189} ) ;
5290
5391// Send message to the uget-chrome-wrapper
@@ -95,7 +133,7 @@ chrome.contextMenus.onClicked.addListener(function(info, tab) {
95133// Interrupt Google Chrome download
96134chrome . downloads . onCreated . addListener ( function ( downloadItem ) {
97135
98- if ( ugetWrapperNotFound ) { // uget-chrome-wrapper not installed
136+ if ( ugetWrapperNotFound || ! interruptDownloads ) { // uget-chrome-wrapper not installed
99137 return ;
100138 }
101139
@@ -116,7 +154,7 @@ chrome.downloads.onCreated.addListener(function(downloadItem) {
116154 return ;
117155 }
118156
119- if ( url . includes ( "//docs.google.com/" ) || url . includes ( "googleusercontent.com/docs" ) ) { // Cannot download from Google Docs
157+ if ( isBlackListed ( url ) ) {
120158 return ;
121159 }
122160
@@ -195,7 +233,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
195233 } ;
196234 }
197235
198- if ( details . url . includes ( "//docs.google.com/" ) || details . url . includes ( "googleusercontent.com/docs" ) ) { // Cannot download from Google Docs
236+ if ( isBlackListed ( details . url ) ) {
199237 return {
200238 responseHeaders : details . responseHeaders
201239 } ;
@@ -237,7 +275,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
237275 }
238276 }
239277 }
240- if ( interruptDownload == true && enableExtension == true ) {
278+ if ( interruptDownload == true && interruptDownloads == true ) {
241279 for ( var i = 0 ; i < filter . length ; i ++ ) {
242280 if ( filter [ i ] != "" && contentType . lastIndexOf ( filter [ i ] ) != - 1 ) {
243281 return {
@@ -284,7 +322,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
284322 cancel : true
285323 } ;
286324 }
287- enableExtension == true ;
325+ interruptDownloads == true ;
288326 clearMessage ( ) ;
289327 return {
290328 responseHeaders : details . responseHeaders
@@ -301,3 +339,32 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) {
301339 'responseHeaders' ,
302340 'blocking'
303341] ) ;
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