-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed download button #56
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
console.log(`Found Path ${tab.url}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'template literal syntax' is only available in ES6 (use 'esversion: 6'). |
||
console.log(`Found file name ${fileName}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'template literal syntax' is only available in ES6 (use 'esversion: 6'). |
||
console.log(`Closing tab & sending download`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'template literal syntax' is only available in ES6 (use 'esversion: 6'). |
||
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(/<span class="count">(\d+)</g)[1].match(/\d+/g)[0]); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/','/'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'let' is available in ES6 (use 'esversion: 6') or Mozilla JS extensions (use moz). |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing semicolon. |
||
// document.querySelector('.files') && | ||
// document.querySelector('.files').contains(node) && | ||
// document.querySelector('.file') === null; | ||
}, | ||
} | ||
|
||
FileDownloader.init(); | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.