Skip to content

Commit

Permalink
Error handling to make sure it's a valid VIDEO url
Browse files Browse the repository at this point in the history
  • Loading branch information
SleekPanther committed Jul 10, 2018
1 parent 615691d commit 4bf654b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ function appendToUrl(){
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, tabs=>{
let currentTab = tabs[0]
let oldURL = currentTab.url
let videoId = oldURL.match(regexMatchVideoId)[1] //get video id
let regexMatch = oldURL.match(regexMatchVideoId)
if(!regexMatch){ //not a valid youtube video URL (prevents keyboard shotcut override)
return
}
let videoId = regexMatch[1] //get video id
let newUrl = YOUTUBE_VIDEO_URL_START + videoId + MAGIC_URL_POSTFIX
chrome.tabs.update(currentTab.id, {url: newUrl}) //update tab/reloads page with new location
})
Expand Down

0 comments on commit 4bf654b

Please sign in to comment.