This repository has been archived by the owner on Sep 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from nero2009/feature/firefox-version
Feature/firefox version
- Loading branch information
Showing
6 changed files
with
4,939 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,70 @@ | ||
//Send version request to background page | ||
chrome.extension.sendMessage({ get_version: 'true' }, function(response) { | ||
browser.runtime.sendMessage({ get_version: 'true' }, function(response) { | ||
// console.log('popupjs sendMessage received', { response }); | ||
}); | ||
|
||
//Update panel with version information | ||
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { | ||
browser.runtime.sendMessage({ method:'getHost'}, function(response) { | ||
var host = response; | ||
const ghbutton = document.getElementById('ghbutton'); | ||
const ghspan = document.getElementById('ghspan'); | ||
const dpbutton = document.getElementById('dpbutton'); | ||
const slug = request.url.host.split('.')[0]; | ||
if (request.hiFrom === 'contentscript') { | ||
console.log( | ||
'[netlify chrome extension] checking if netlify site is open source...' | ||
); | ||
fetch('https://api.netlify.com/api/v1/sites/' + request.url.host) | ||
.then(res => res.json()) | ||
.then(res => { | ||
console.log('[netlify chrome extension] Yes!', { res }); | ||
document | ||
.getElementById('label') | ||
.appendChild(document.createTextNode('by ' + res.account_name)); | ||
document | ||
.getElementById('version') | ||
.appendChild( | ||
document.createTextNode( | ||
'Last published ' + | ||
new Date(res.published_deploy.published_at).toLocaleDateString() | ||
) | ||
); // may also want commit_url and deploy_ssl_url and title | ||
const slug = host.split('.')[0]; | ||
console.log( | ||
'[netlify firefox extension] checking if netlify site is open source...' | ||
); | ||
fetch('https://api.netlify.com/api/v1/sites/' + host) | ||
.then(res => res.json()) | ||
.then(res => { | ||
console.log('[netlify firefox extension] Yes!', { res }); | ||
document | ||
.getElementById('label') | ||
.appendChild(document.createTextNode('by ' + res.account_name)); | ||
document | ||
.getElementById('version') | ||
.appendChild( | ||
document.createTextNode( | ||
'Last published ' + | ||
new Date(res.published_deploy.published_at).toLocaleDateString() | ||
) | ||
); // may also want commit_url and deploy_ssl_url and title | ||
|
||
// const img = document.getElementById('img'); | ||
// img.src = res.screenshot_url; | ||
ghbutton.href = res.repo_url; | ||
dpbutton.href = res.admin_url; | ||
dpbutton.innerText = 'Deploy Logs'; | ||
ghspan.hidden = false; | ||
// const img = document.getElementById('img'); | ||
// img.src = res.screenshot_url; | ||
ghbutton.href = res.repo_url; | ||
dpbutton.href = res.admin_url; | ||
dpbutton.innerText = 'Deploy Logs'; | ||
ghspan.hidden = false; | ||
dpspan.hidden = false; | ||
dpbutton.hidden = false; | ||
}) | ||
.catch(err => { | ||
console.log('[netlify firefox extension] Nope :(', { err }); | ||
document | ||
.getElementById('label') | ||
.appendChild(document.createTextNode('but it is not open source')); | ||
if (host.includes('netlify.com')) { | ||
// attempt to show deploys | ||
ghspan.hidden = true; | ||
dpspan.hidden = false; | ||
dpbutton.hidden = false; | ||
}) | ||
.catch(err => { | ||
console.log('[netlify chrome extension] Nope :(', { err }); | ||
document | ||
.getElementById('label') | ||
.appendChild(document.createTextNode('but it is not open source')); | ||
if (request.url.host.includes('netlify.com')) { | ||
// attempt to show deploys | ||
ghspan.hidden = true; | ||
dpspan.hidden = false; | ||
dpbutton.hidden = false; | ||
dpbutton.innerText = 'If its yours, you can still see deploy log'; | ||
dpbutton.href = 'https://app.netlify.com/sites/' + slug; | ||
} else { | ||
// nothing at all | ||
ghspan.hidden = true; | ||
dpspan.hidden = true; | ||
} | ||
}); | ||
} | ||
dpbutton.innerText = 'If its yours, you can still see deploy log'; | ||
dpbutton.href = 'https://app.netlify.com/sites/' + slug; | ||
} else { | ||
// nothing at all | ||
ghspan.hidden = true; | ||
dpspan.hidden = true; | ||
} | ||
}); | ||
|
||
|
||
}); | ||
|
||
|
||
// Honestly its probably more complicated than needs to be but i based it off of other extensions that do the same thing. | ||
|
||
// inject content-script into every page | ||
// script pings background.js that there is a new page | ||
// background.js activates the "browser action" (the little logo on the browser bar) if its a Netlify site by sniffing the Server field in the response header. | ||
// if it is a Netlify site and you click the "browser action": | ||
// if it is on .netlify.com host, popup.js checks if it is open source and manipulates popup.html accordingly. | ||
|
Oops, something went wrong.