Skip to content

Commit

Permalink
Regex to just get videoId & sanitize url
Browse files Browse the repository at this point in the history
  • Loading branch information
SleekPanther committed Jul 10, 2018
1 parent a75651d commit 9b0b3a5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@

const MAGIC_URL_POSTFIX = '&list=ULcxqQ59vzyTk'
const YOUTUBE_VIDEO_URL_START = 'https://www.youtube.com/watch?v='
const regexMatchVideoId = /youtube.com\/watch\?v=([^&\?]*)/ //regular expression matches youtube.com/watch?v=[VIDEO_ID] & captures the video ID since the ID is either the end of the string or ends at a question mark or ampersand

//Browser action instead of popup
chrome.browserAction.onClicked.addListener(tab=>{
appendToUrl()
appendToUrl()
})

function appendToUrl(){
chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, tabs=>{
let currentTab = tabs[0]
let oldURL = currentTab.url
console.log('old url=', oldURL)


let newUrl = oldURL + MAGIC_URL_POSTFIX
let videoId = oldURL.match(regexMatchVideoId)[1] //get video id
let newUrl = YOUTUBE_VIDEO_URL_START + videoId + MAGIC_URL_POSTFIX
chrome.tabs.update(currentTab.id, {url: newUrl})
})
}
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

"name": "YouTube Chronological Order",
"description": "Watch YouTube videos in chronological order from any channel",
"version": "0.2.0",
"version_name": "0.2.0",
"version": "0.3.0",
"version_name": "0.3.0",

"browser_action": {
// "default_icon": "assets/icons/icon.png",
Expand Down

0 comments on commit 9b0b3a5

Please sign in to comment.