diff --git a/public/index.html b/public/index.html index 800064a..75fcf2e 100644 --- a/public/index.html +++ b/public/index.html @@ -60,5 +60,6 @@

{{ names[section] }}

+ diff --git a/public/js/frontend.js b/public/js/frontend.js index db8f2fd..2c7c084 100644 --- a/public/js/frontend.js +++ b/public/js/frontend.js @@ -79,7 +79,10 @@ $("#searchbar").keyup(function(e){ if(e.keyCode == 13){ term = this.value console.log(term) - doAjax("/search", "POST", searchHandler, {term: term}); + if (isValidURL(term)) + doAjax("/download", "POST", null, {url: term}); + else + doAjax("/search", "POST", searchHandler, {term: term}); } }) diff --git a/public/js/utils.js b/public/js/utils.js new file mode 100644 index 0000000..821a458 --- /dev/null +++ b/public/js/utils.js @@ -0,0 +1,8 @@ +function isValidURL(text){ + if (text.toLowerCase().startsWith("http")) + if (text.toLowerCase().indexOf("deezer.com") >= 0 || text.toLowerCase().indexOf("open.spotify.com") >= 0) + return true + else if (text.toLowerCase().startsWith("spotify:")) + return true + return false +}