I'm just starting out with Chrome Extensions. I'm trying to build a simple extension that allows me to quickly download the mp3 of a certain Youtube video that I am currently on. The first step is detecting whether the current website is Youtube or not, and I have problems. Debugger said nothing so I really don't know what's the problem. Here's the code:
// COPYRIGHT Gofilord May 2014
// Download mp3 songs from Youtube easily and quickly
// javascript file
var url = ''; // store the url of the current youtube song
var btn_group = $('.download-btn-group'); // caching
var errors = $('.errors');
// both are dynamic elements
// they show up accordingly
btn_group.hide();
errors.hide();
// get current tab's URL
// for sending that URL to the API of the mp3 converter
chrome.tabs.getSelected(null, function(tab) {
url = tab.url;
});
// function to check if the current website is indeed Youtube
// add-on works ONLY on youtube.
function isYoutube() {
if (url.toLowerCase().indexOf('www.youtube.com') >= 0) // if Youtube's address is existing in the url
return true; // that means the user is in youtube.
return false;
}
if (isYoutube()) // if it's youtube
btn_group.show(); // show the download buttons
else
errors.show(); // show a msg saying the website isn't youtube
Thanks!