diff --git a/background.js b/background.js index 0ee37ab..29ba7b2 100644 --- a/background.js +++ b/background.js @@ -1,5 +1,5 @@ //Only make extension icon visible on YouTube.com -const youtubeBaseUrl = 'youtube.com' //lowercase matters +const youtubeDomainMatch = 'youtube.com' //lowercase matters chrome.runtime.onInstalled.addListener(function() { // Replace all rules ... chrome.declarativeContent.onPageChanged.removeRules(undefined, () => { @@ -7,7 +7,7 @@ chrome.runtime.onInstalled.addListener(function() { chrome.declarativeContent.onPageChanged.addRules([{ conditions: [ new chrome.declarativeContent.PageStateMatcher({ - pageUrl: { hostContains: youtubeBaseUrl }, + pageUrl: { hostContains: youtubeDomainMatch }, }) ], // And shows the extension's page action @@ -19,22 +19,22 @@ chrome.runtime.onInstalled.addListener(function() { const MAGIC_URL_POSTFIX = '&list=ULcxqQ59vzyTk' //thing to append to make it play chronlogically const YOUTUBE_VIDEO_URL_START = 'https://www.youtube.com/watch?v=' //a youtube url without the videoID -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 +const regexToExtractVideoId = /youtube.com\/watch\?v=([^&\?]*)/i //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 +//Run code on page action instead of popup chrome.pageAction.onClicked.addListener(tab=>{ appendToUrl() }) function appendToUrl(){ - chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, tabs=>{ + chrome.tabs.query({'active': true, 'lastFocusedWindow': true}, tabs=>{ //Get current tab let currentTab = tabs[0] let oldURL = currentTab.url - let regexMatch = oldURL.match(regexMatchVideoId) + let regexMatch = oldURL.match(regexToExtractVideoId) if(!regexMatch){ //not a valid youtube video URL (prevents keyboard shotcut override) return } - let videoId = regexMatch[1] //get video id + let videoId = regexMatch[1] //get video id from regex match let newUrl = YOUTUBE_VIDEO_URL_START + videoId + MAGIC_URL_POSTFIX chrome.tabs.update(currentTab.id, {url: newUrl}) //update tab/reloads page with new location }) diff --git a/manifest.json b/manifest.json index 9195cab..fe53c90 100644 --- a/manifest.json +++ b/manifest.json @@ -3,8 +3,8 @@ "name": "YouTube Chronological Order", "description": "Watch all videos from a channel in chronological order", - "version": "1.0.0", - "version_name": "1.0.0", + "version": "1.0.1", + "version_name": "1.0.1", "page_action": { "default_icon" : "assets/icons/chronological-icon-16.png",