From 0d1ae72dc863cd70779ec4619999978420e0d9a7 Mon Sep 17 00:00:00 2001 From: Richie77777 <92157389+Richie77777@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:29:38 +0000 Subject: [PATCH 1/5] fixed download button --- background.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/background.js b/background.js index 8df9a15..340245e 100644 --- a/background.js +++ b/background.js @@ -7,6 +7,30 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { sendResponse({result: getConfig()[request.key]}); }); + +chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) { + if (changeInfo.status == 'complete') { + if(tab.url.includes('https://raw.githubusercontent.com/')){ + console.log('Found raw content tab') + savePage(tab,tab.id); + } + } +}) +function savePage(tab,id) { + let fileName = tab.url.split('/').slice(-1).pop(0); + console.log(`Found Path ${tab.url}`) + console.log(`Found file name ${fileName}`) + console.log(`Closing tab & sending download`) + chrome.tabs.remove(id); + if(fileName.charAt(0) === '.') fileName = fileName.slice(1) + '.txt'; + chrome.downloads.download({ + url: tab.url, + filename: fileName + }); +} + + + var GitHubNotification; var notificationUrl = 'https://github.com/notifications'; var blue = [1, 128, 255, 255]; @@ -36,7 +60,6 @@ function _goToNotificationTab() { // type can be unread/participating function _extractUnreadNotifications(response) { var type = getConfig()['feature-2-type']; - if (type === 'participating') { return parseInt(response.match(/(\d+) Date: Mon, 14 Feb 2022 15:31:16 +0000 Subject: [PATCH 2/5] fixed download button --- manifest.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 65ffe3f..4adc534 100644 --- a/manifest.json +++ b/manifest.json @@ -9,8 +9,12 @@ }, "permissions" : [ "*://github.com/*", + "*://raw.githubusercontent.com/*", "tabs", - "webNavigation" + "activeTab", + "webNavigation", + "pageCapture", + "downloads" ], "web_accessible_resources": ["page.js"], "content_scripts": [ From 9a4b43f9f56f1c5a30818623fe5204e0e120b11e Mon Sep 17 00:00:00 2001 From: Richie77777 <92157389+Richie77777@users.noreply.github.com> Date: Mon, 14 Feb 2022 15:32:27 +0000 Subject: [PATCH 3/5] fixed download button --- script.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/script.js b/script.js index 8205b90..c746784 100644 --- a/script.js +++ b/script.js @@ -7,15 +7,14 @@ var s = document.createElement('script'); (document.head||document.documentElement).appendChild(s); // page.js injection end - var FileDownloader = { init: function() { FileDownloader.addDownloadTooltip(); FileDownloader.bindPopState(); - chrome.runtime.sendMessage({key: "feature-1-enable"}, function(response) { if(typeof(response.result) === 'undefined' || response.result === true) { - $(document).on('click', '.octicon-file-text', function(e) { + // Changed .octicon-file-text to .download-btn + $(document).on('click', '.download-btn', function(e) { FileDownloader.eventHandler(e); }); } else { @@ -25,7 +24,7 @@ var FileDownloader = { }, addDownloadTooltip: function() { - Array.prototype.slice.call(document.querySelectorAll('.octicon-file-text')).map(function(icon) { + Array.prototype.slice.call(document.querySelectorAll('.octicon-file')).map(function(icon) { var td = icon.parentNode; td.classList.add('tooltipped', 'tooltipped-se'); td.setAttribute('aria-label', 'Click to download'); @@ -36,8 +35,10 @@ var FileDownloader = { var fileName = document.querySelector('.breadcrumb .final-path').textContent; let btn = document.createElement('a'); btn.setAttribute('class', 'btn btn-sm btn-primary tooltipped tooltipped-n download-btn'); - btn.setAttribute('href', rawUrlNode.href); - btn.setAttribute('download', fileName); + btn.setAttribute('target','_blank'); + btn.setAttribute('rel','noreferrer'); + // btn.setAttribute('href', rawUrlNode.href); + btn.setAttribute('download',fileName); btn.setAttribute('aria-label', 'Click to download ' + fileName); btn.textContent = 'Download'; rawUrlNode.parentNode.parentNode.prepend(btn); @@ -57,26 +58,34 @@ var FileDownloader = { eventHandler: function(event) { if (this.isFromListPage(event.currentTarget)) { - var linkNode = event.currentTarget.parentNode.nextElementSibling.querySelector('a'); - var href = linkNode.href.replace('\/blob\/', '\/raw\/'); - this.downloadIt(href, linkNode.textContent); + var linkNode = event.currentTarget.parentNode.nextElementSibling.querySelectorAll('a:not(.tooltipped)')[0]; + // var href = linkNode.href.replace('\/blob\/', '\/raw\/'); + let href = linkNode.href.replace('/raw/','/'); + href = href.replace('https://github.com/','https://raw.githubusercontent.com/'); + // Change linkNode.textContent to event.target.download + this.downloadIt(href, event.target.download); } }, downloadIt: function(href, fileName) { var downloadNode = document.createElement('a'); downloadNode.setAttribute('href', href); + downloadNode.setAttribute('rel','noopener noreferrer'); + downloadNode.setAttribute('target','_blank'); downloadNode.setAttribute('download', fileName); downloadNode.click(); downloadNode = null; }, isFromListPage: function(node) { - return node.classList.contains('octicon-file-text') && - document.querySelector('.files') && - document.querySelector('.files').contains(node) && - document.querySelector('.file') === null; + return node.classList.contains('download-btn') //&& // octicon-file // octicon-file-text + // document.querySelector('.files') && + // document.querySelector('.files').contains(node) && + // document.querySelector('.file') === null; }, } FileDownloader.init(); + + + From 349d36b1401a9a6a25549d375b0351278bf8cc0e Mon Sep 17 00:00:00 2001 From: Richie77777 <92157389+Richie77777@users.noreply.github.com> Date: Mon, 14 Feb 2022 17:27:43 +0000 Subject: [PATCH 4/5] Added tab detection for raw.githubusercontent.com This will automatically download the raw content on page load and then closes the tab. --- background.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index 340245e..046e7fa 100644 --- a/background.js +++ b/background.js @@ -11,16 +11,16 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) { if (changeInfo.status == 'complete') { if(tab.url.includes('https://raw.githubusercontent.com/')){ - console.log('Found raw content tab') + console.log('Found raw content tab'); savePage(tab,tab.id); } } }) function savePage(tab,id) { let fileName = tab.url.split('/').slice(-1).pop(0); - console.log(`Found Path ${tab.url}`) - console.log(`Found file name ${fileName}`) - console.log(`Closing tab & sending download`) + console.log(`Found Path ${tab.url}`); + console.log(`Found file name ${fileName}`); + console.log(`Closing tab & sending download`); chrome.tabs.remove(id); if(fileName.charAt(0) === '.') fileName = fileName.slice(1) + '.txt'; chrome.downloads.download({ From 5a407297f190ee9f901d2bba3a790df9c10750a2 Mon Sep 17 00:00:00 2001 From: Richie77777 <92157389+Richie77777@users.noreply.github.com> Date: Mon, 14 Feb 2022 17:30:09 +0000 Subject: [PATCH 5/5] Added more permissions "*://raw.githubusercontent.com/*", "activeTab", "pageCapture", "downloads" --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4adc534..282431b 100644 --- a/manifest.json +++ b/manifest.json @@ -11,8 +11,8 @@ "*://github.com/*", "*://raw.githubusercontent.com/*", "tabs", - "activeTab", "webNavigation", + "activeTab", "pageCapture", "downloads" ],