|
28 | 28 | chromeVersion = 33; |
29 | 29 | } |
30 | 30 | chromeVersion = parseInt(chromeVersion); |
31 | | -sendMessageToHost({ version: "1.1.3" }); |
| 31 | +sendMessageToHost({ version: "1.1.4" }); |
32 | 32 |
|
33 | 33 |
|
34 | 34 | // Message format to send the download information to the uget-chrome-wrapper |
@@ -75,23 +75,60 @@ function postParams(source) { |
75 | 75 | } |
76 | 76 |
|
77 | 77 | // Add to Chrome context menu |
78 | | -chrome.contextMenus.create( |
79 | | - { |
80 | | - title: 'Download with uGet', |
81 | | - id: "download_with_uget", |
82 | | - contexts: ['link'] |
83 | | - } |
84 | | -); |
| 78 | +chrome.contextMenus.create({ |
| 79 | + title: 'Download with uGet', |
| 80 | + id: "download_with_uget", |
| 81 | + contexts: ['link'] |
| 82 | +}); |
85 | 83 |
|
86 | | -chrome.contextMenus.onClicked.addListener(function (info, tab) { |
| 84 | +chrome.contextMenus.onClicked.addListener(function(info, tab) { |
87 | 85 | "use strict"; |
88 | 86 | if (info.menuItemId === "download_with_uget") { |
89 | | - clearMessage(); |
90 | | - message.url = info['linkUrl']; |
91 | | - message.referrer = info['pageUrl']; |
92 | | - sendMessageToHost(message); |
93 | | - clearMessage(); |
| 87 | + clearMessage(); |
| 88 | + message.url = info['linkUrl']; |
| 89 | + message.referrer = info['pageUrl']; |
| 90 | + sendMessageToHost(message); |
| 91 | + clearMessage(); |
| 92 | + } |
| 93 | +}); |
| 94 | + |
| 95 | +// Interrupt Google Chrome download |
| 96 | +chrome.downloads.onCreated.addListener(function(downloadItem) { |
| 97 | + |
| 98 | + if (ugetWrapperNotFound) { // uget-chrome-wrapper not installed |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + var fileSize = downloadItem['fileSize']; |
| 103 | + |
| 104 | + if (fileSize != -1 && fileSize < 300000) { // 300 kb |
| 105 | + return; |
94 | 106 | } |
| 107 | + |
| 108 | + var url = ''; |
| 109 | + if (chromeVersion >= 54) { |
| 110 | + url = downloadItem['finalUrl']; |
| 111 | + } else { |
| 112 | + url = downloadItem['url']; |
| 113 | + } |
| 114 | + |
| 115 | + if (!url) { |
| 116 | + return; |
| 117 | + } |
| 118 | + |
| 119 | + if (url.includes("//docs.google.com/") || url.includes("googleusercontent.com/docs")) { // Cannot download from Google Docs |
| 120 | + return; |
| 121 | + } |
| 122 | + |
| 123 | + chrome.downloads.cancel(downloadItem.id); // Cancel the download |
| 124 | + chrome.downloads.erase({ id: downloadItem.id }); // Erase the download from list |
| 125 | + |
| 126 | + clearMessage(); |
| 127 | + message.url = url; |
| 128 | + message.filename = downloadItem['filename']; |
| 129 | + message.filesize = fileSize; |
| 130 | + message.referrer = downloadItem['referrer']; |
| 131 | + sendMessageToHost(message); |
95 | 132 | }); |
96 | 133 |
|
97 | 134 | chrome.webRequest.onBeforeRequest.addListener(function(details) { |
@@ -146,19 +183,19 @@ chrome.webRequest.onBeforeSendHeaders.addListener(function(details) { |
146 | 183 | ]); |
147 | 184 | chrome.webRequest.onHeadersReceived.addListener(function(details) { |
148 | 185 |
|
149 | | - if (ugetWrapperNotFound) { // uget-chrome-wrapper not installed |
| 186 | + if (ugetWrapperNotFound) { // uget-chrome-wrapper not installed |
150 | 187 | return { |
151 | 188 | responseHeaders: details.responseHeaders |
152 | 189 | }; |
153 | 190 | } |
154 | 191 |
|
155 | | - if (!details.statusLine.includes("200")) { // HTTP response is not OK |
| 192 | + if (!details.statusLine.includes("200")) { // HTTP response is not OK |
156 | 193 | return { |
157 | 194 | responseHeaders: details.responseHeaders |
158 | 195 | }; |
159 | 196 | } |
160 | 197 |
|
161 | | - if (details.url.includes("//docs.google.com/") || details.url.includes("googleusercontent.com/docs")) { // Cannot download from Google Docs |
| 198 | + if (details.url.includes("//docs.google.com/") || details.url.includes("googleusercontent.com/docs")) { // Cannot download from Google Docs |
162 | 199 | return { |
163 | 200 | responseHeaders: details.responseHeaders |
164 | 201 | }; |
|
0 commit comments