From 3efb696e9be940cf119c906966c3448849d1795e Mon Sep 17 00:00:00 2001 From: Gobinath Date: Wed, 9 Nov 2016 20:27:14 +0530 Subject: [PATCH] Add UI to chrome extension --- chrome-extension/background.js | 93 +++++++++++-- chrome-extension/content.js | 37 ++++-- chrome-extension/icon_disabled_32.png | Bin 0 -> 1437 bytes chrome-extension/manifest.json | 8 +- chrome-extension/popup.css | 180 ++++++++++++++++++++++++++ chrome-extension/popup.html | 51 ++++++++ chrome-extension/popup.js | 43 ++++++ 7 files changed, 387 insertions(+), 25 deletions(-) create mode 100644 chrome-extension/icon_disabled_32.png create mode 100644 chrome-extension/popup.css create mode 100644 chrome-extension/popup.html create mode 100644 chrome-extension/popup.js diff --git a/chrome-extension/background.js b/chrome-extension/background.js index 080ad29..39d556c 100644 --- a/chrome-extension/background.js +++ b/chrome-extension/background.js @@ -1,13 +1,31 @@ -// uget-chrome-wrapper is an extension to integrate uGet Download manager -// with Google Chrome in Linux systems. +/* +* uget-chrome-wrapper is an extension to integrate uGet Download manager +* with Google Chrome, Chromium and Vivaldi in Linux and Windows. +* +* Copyright (C) 2016 Gobinath +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ -var enableExtension = true; +var interruptDownloads = true; var ugetWrapperNotFound = true; var interruptDownload = false; var disposition = ''; var hostName = 'com.javahelps.ugetchromewrapper'; var chromeVersion; var filter = []; +var keywords = []; var requestList = [{ cookies: '', postdata: '', @@ -28,9 +46,22 @@ try { chromeVersion = 33; } chromeVersion = parseInt(chromeVersion); -sendMessageToHost({ version: "1.1.4" }); +sendMessageToHost({ version: "1.1.6" }); + +if (localStorage["uget-keywords"]) { + keywords = localStorage["uget-keywords"].split(/[\s,]+/); +} else { + localStorage["uget-keywords"] = ''; +} +if (!localStorage["uget-interrupt"]) { + localStorage["uget-interrupt"] = 'true'; +} else { + var interrupt = (localStorage["uget-interrupt"] == "true"); + setInterruptDownload(interrupt); +} +console.log(localStorage["uget-interrupt"]); // Message format to send the download information to the uget-chrome-wrapper var message = { url: '', @@ -44,10 +75,17 @@ var message = { // Listen to the key press chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { - if (request.enableEXT == 'false') - enableExtension = false; - else - enableExtension = true; + var msg = request.message; + if(msg === 'enable') { + // Temporarily enable + setInterruptDownload(true); + } else if(msg == 'disable') { + // Temporarily disable + setInterruptDownload(false); + } else { + // Toggle + setInterruptDownload(!interruptDownloads, true); + } }); // Send message to the uget-chrome-wrapper @@ -95,7 +133,7 @@ chrome.contextMenus.onClicked.addListener(function(info, tab) { // Interrupt Google Chrome download chrome.downloads.onCreated.addListener(function(downloadItem) { - if (ugetWrapperNotFound) { // uget-chrome-wrapper not installed + if (ugetWrapperNotFound || !interruptDownloads) { // uget-chrome-wrapper not installed return; } @@ -116,7 +154,7 @@ chrome.downloads.onCreated.addListener(function(downloadItem) { return; } - if (url.includes("//docs.google.com/") || url.includes("googleusercontent.com/docs")) { // Cannot download from Google Docs + if (isBlackListed(url)) { return; } @@ -195,7 +233,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) { }; } - if (details.url.includes("//docs.google.com/") || details.url.includes("googleusercontent.com/docs")) { // Cannot download from Google Docs + if (isBlackListed(details.url)) { return { responseHeaders: details.responseHeaders }; @@ -237,7 +275,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) { } } } - if (interruptDownload == true && enableExtension == true) { + if (interruptDownload == true && interruptDownloads == true) { for (var i = 0; i < filter.length; i++) { if (filter[i] != "" && contentType.lastIndexOf(filter[i]) != -1) { return { @@ -284,7 +322,7 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) { cancel: true }; } - enableExtension == true; + interruptDownloads == true; clearMessage(); return { responseHeaders: details.responseHeaders @@ -301,3 +339,32 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) { 'responseHeaders', 'blocking' ]); + +function updateKeywords(data) { + keywords = data.split(/[\s,]+/); +}; + +function isBlackListed(url) { + if (url.includes("//docs.google.com/") || url.includes("googleusercontent.com/docs")) { // Cannot download from Google Docs + return true; + } + for (keyword of keywords) { + if (url.includes(keyword)) { + return true; + } + } + return false; +} + + +function setInterruptDownload(interrupt, writeToStorage) { + interruptDownloads = interrupt; + if (interrupt) { + chrome.browserAction.setIcon({ path: "./icon_32.png" }); + } else { + chrome.browserAction.setIcon({ path: "./icon_disabled_32.png" }); + } + if(writeToStorage) { + localStorage["uget-interrupt"] = interrupt.toString(); + } +} \ No newline at end of file diff --git a/chrome-extension/content.js b/chrome-extension/content.js index a26220a..6136dd8 100644 --- a/chrome-extension/content.js +++ b/chrome-extension/content.js @@ -1,14 +1,33 @@ -var value = "true"; +/* +* uget-chrome-wrapper is an extension to integrate uGet Download manager +* with Google Chrome, Chromium and Vivaldi in Linux and Windows. +* +* Copyright (C) 2016 Gobinath +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + window.onkeydown = function(event) { - if (event.keyCode == 45) { - value = "false"; - chrome.extension.sendRequest({ enableEXT: value }); + if (event.keyCode == 45) { // Insert + chrome.extension.sendRequest({ message: 'disable' }); } - }; + window.onkeyup = function(event) { - if (event.keyCode == 45) { - value = "true"; - chrome.extension.sendRequest({ enableEXT: value }); + if (event.keyCode == 45) { // Insert + chrome.extension.sendRequest({ message: 'enable' }); + } else if (event.keyCode == 85 && event.ctrlKey && event.shiftKey) { // Ctrl + Shift + U + chrome.extension.sendRequest({ message: 'toggle' }); } -}; +}; \ No newline at end of file diff --git a/chrome-extension/icon_disabled_32.png b/chrome-extension/icon_disabled_32.png new file mode 100644 index 0000000000000000000000000000000000000000..bfcd69d6e00d1c6d6dcc437ce01d5db8200e0ef5 GIT binary patch literal 1437 zcmV;O1!DS%P)u-r4lHNG}@JCcFuRcbG~!N)ai6UM5xtj zEJ+e`baVt`3_iqQjA3SG#@n*iLJ$#>B*FLJ{a`-*Y;m^R?bfx{mWW`jJr%?5EY3My zzI=K3*PnkMe*Mi?sMTr^oO4=RyJK(P{^HA(m6dOA-n{uS5fK17Wdf|V)=DXlkB^V< zt*zbp@#mj^BHm~;aB%RldH3$!U+VSxC)U~u=R9VNeTZ3^nwt7(adGkU$B+N`RVnpS zwA&pJ(WTL7RMlFWG3^vm_nMIRav6nC+B8j}l&TWZrFOg1X6x(g0KiGWhw$|6zAu4eU0A!3IYi%y^iis$t#PjFR(eL+>rm6qk7&D<9##n9|W3aHW zfcg1(7-I+kRpJ=J;tk~vfTKKoKRG$UqeqXRwMHDrV2nX)jnQZXrBu$a5CTF7aLyrw z@Boq|2^}H}3o$lC)>;^2;GRU}88F6R94b_+RdCL|N6lt)BKG(1-=AOu0E7_U#yA|W z0gOWc&Uub<_rANki@{)kdcE#L!x)27s+JV}RUZ@lYwHr_nu&EQKS>GQXE|?wJijOaTM0_qxSiuZLc*2O$Ks z)>vI#_1-$KLJ(yDmX?-ES*cd59*C2pXTU8aNdl!57-JX?hdD}}q{=7`$I;PI4p`i5-K-3osOrUF@`9LV6BCe5@*hwc{_k&wh~beKrySe)};Vk z{a}nCj$=eo1Y?Y^2RQ&VR)MPp|JPF8f#=ShgS8e@Q&XjTuU@_C9ogUC_iAy;=*lw{ zR1hXejsa_}r!>nl2qAF({Q0*g;r#qO0O0AleO2@5z%VzV8ze zwANmh-EJ2bE?mID!2v3jO0Mz&fKm!Xgz4$&$%{)-hM`p4(-?zhvxzLrkftfJEQ6HN zhlz-=v$F#sgfCD^DP&oO;c$pFO|h`BP%1+aP~y>*X*-G{+_-TAJ3BiV3CBq9fx;DcagKF~akN5G18k07gs8OJI%W6#(dLY-~L2 z_xoB($+9dXH>H%Ml=9OU<8Dv6>3$FQN-3#u7VG!>dShebA%IS!c?Du+c@^9L{M&l= z?Ag6;xBI&gVg`T#K*bz*-!TrQ1;CV2M*x1ie*JoDWqB2}xw(lXN$}vo1HQMnS8ugi r0v~W(yLL^@&CLyO-MXb~wHp2ds5oR85%X)J00000NkvXXu0mjf#9ExC literal 0 HcmV?d00001 diff --git a/chrome-extension/manifest.json b/chrome-extension/manifest.json index d7e4bcf..7c4978c 100644 --- a/chrome-extension/manifest.json +++ b/chrome-extension/manifest.json @@ -5,7 +5,8 @@ ] }, "browser_action": { - "default_icon": "icon_32.png" + "default_icon": "icon_32.png", + "default_popup": "popup.html" }, "content_scripts": [ { @@ -38,7 +39,8 @@ "webRequestBlocking", "nativeMessaging", "contextMenus", - "downloads" + "downloads", + "storage" ], - "version": "1.1.4" + "version": "1.1.6" } \ No newline at end of file diff --git a/chrome-extension/popup.css b/chrome-extension/popup.css new file mode 100644 index 0000000..9759871 --- /dev/null +++ b/chrome-extension/popup.css @@ -0,0 +1,180 @@ +/* +* uget-chrome-wrapper is an extension to integrate uGet Download manager +* with Google Chrome, Chromium and Vivaldi in Linux and Windows. +* +* Copyright (C) 2016 Gobinath +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +body { + overflow-x: hidden; + background: #EFEFEF; +} + +input#save { + font-weight: bold; + width: auto; + right: 0; +} + +#img-icon { + width: 24px; + height: 24px; + vertical-align: middle; +} + +#title-container { + display: table; + text-align: center; + margin: 0 auto; +} + +span { + display: table-cell; + vertical-align: middle; + font-weight: bold; + font-size: 11pt; + padding-left: 5px; + color: #474747; +} + +hr { + display: block; + height: 1px; + border: 0; + border-top: 1px solid #ccc; + margin: 1em 0; + padding: 0; +} + +label { + font-weight: bold; + color: #4A4A4A; +} + +#keywords { + border: 1px solid #c4c4c4; + font-size: 13px; + padding: 4px 4px 4px 4px; + border-radius: 4px; + -moz-border-radius: 4px; + -webkit-border-radius: 4px; + /*box-shadow: 0px 0px 8px #d9d9d9;*/ + /*-moz-box-shadow: 0px 0px 8px #d9d9d9;*/ + /*-webkit-box-shadow: 0px 0px 8px #d9d9d9;*/ + margin-top: 5px; + margin-bottom: 5px; +} + +#keywords:focus { + outline: none; + border: 1px solid #7bc1f7; + box-shadow: 0px 0px 5px #7bc1f7; + -moz-box-shadow: 0px 0px 5px #7bc1f7; + -webkit-box-shadow: 0px 0px 5px #7bc1f7; +} + +#button-container { + float: right; + margin-top: 5px; + margin-bottom: 5px; + background: inherit; +} + +#controls-container.inline { + display: table; +} + +#save { + background-color: #2196F3; + -moz-border-radius: 20px; + -webkit-border-radius: 20px; + border-radius: 20px; + color: #fff; + text-decoration: none; + cursor: pointer; + border: none; + padding-top: 5px; + padding-bottom: 5px; + padding-left: 10px; + padding-right: 10px; +} + +#save:hover { + border: none; + background: #005DA6; +} + +.switch { + position: relative; + display: inline-block; + width: 30px; + height: 17px; + display: table-cell; + vertical-align: middle; + font-weight: bold; + font-size: 11pt; + color: #474747; +} + +.switch input { + display: none; +} + +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #ccc; + -webkit-transition: .4s; + transition: .4s; +} + +.slider:before { + position: absolute; + content: ""; + height: 13px; + width: 13px; + left: 2px; + bottom: 2px; + background-color: white; + -webkit-transition: .4s; + transition: .4s; +} + +input:checked + .slider { + background-color: #2196F3; +} + +input:focus + .slider { + box-shadow: 0 0 1px #2196F3; +} + +input:checked + .slider:before { + -webkit-transform: translateX(13px); + -ms-transform: translateX(13px); + transform: translateX(13px); +} + +.slider.round { + border-radius: 17px; +} + +.slider.round:before { + border-radius: 50%; +} diff --git a/chrome-extension/popup.html b/chrome-extension/popup.html new file mode 100644 index 0000000..78cb1f8 --- /dev/null +++ b/chrome-extension/popup.html @@ -0,0 +1,51 @@ + + + + + + + + + + + +
+
+ uGet Chrome Integration +
+
+
+ + +
+
+
+ + +
+
+ +
+
+ + + diff --git a/chrome-extension/popup.js b/chrome-extension/popup.js new file mode 100644 index 0000000..9945513 --- /dev/null +++ b/chrome-extension/popup.js @@ -0,0 +1,43 @@ +/* +* uget-chrome-wrapper is an extension to integrate uGet Download manager +* with Google Chrome, Chromium and Vivaldi in Linux and Windows. +* +* Copyright (C) 2016 Gobinath +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +function addBookmark() { + var keywords = document.getElementById("keywords").value; + var interrupt = document.getElementById('chk-interrupt').checked; + + localStorage["uget-keywords"] = keywords; + + chrome.runtime.getBackgroundPage(function(backgroundPage) { + backgroundPage.updateKeywords(keywords); + backgroundPage.setInterruptDownload(interrupt, true); + }); + + window.close(); +} + +// When the popup HTML has loaded +window.addEventListener('load', function(evt) { + // alert(localStorage["uget-interrupt"]); + // alert(typeof localStorage["uget-interrupt"]); + var interrupt = (localStorage["uget-interrupt"] == "true"); + document.getElementById('save').addEventListener('click', addBookmark); + document.getElementById('keywords').value = localStorage["uget-keywords"]; + document.getElementById('chk-interrupt').checked = interrupt; +});