diff --git a/background.js b/background.js index a01aeb5..390c235 100644 --- a/background.js +++ b/background.js @@ -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}) }) } diff --git a/manifest.json b/manifest.json index a538f1c..2ee7724 100644 --- a/manifest.json +++ b/manifest.json @@ -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",