diff --git a/ContentScript.js b/ContentScript.js index 4de796d5..7cb2ac9a 100644 --- a/ContentScript.js +++ b/ContentScript.js @@ -8,6 +8,11 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes if (request.message === 'ytvideoid') { // Message from background script SponsorsLookup(request.id); } + + //message from popup script + if (request.message === 'sponsorStart') { + sponsorMessageStarted(); + } }); function SponsorsLookup(id) { @@ -38,3 +43,15 @@ function youtube_parser(url) { // Returns with video id else returns false var match = url.match(regExp); return (match && match[7].length == 11) ? match[7] : false; } + +function sponsorMessageStarted() { + let v = document.querySelector('video'); + + console.log(v.currentTime) + + //send back current time + chrome.runtime.sendMessage({ + message: "time", + time: v.currentTime + }); +} \ No newline at end of file diff --git a/background.js b/background.js index 21199ed1..20ed74c3 100644 --- a/background.js +++ b/background.js @@ -1,15 +1,20 @@ chrome.tabs.onUpdated.addListener( // On tab update function(tabId, changeInfo, tab) { - if (changeInfo.url && id = youtube_parser(changeInfo.url)) { // If URL changed and is youtube video message ContentScript the video id - chrome.tabs.sendMessage( tabId, { - message: 'ytvideoid', - id: id - }) + if (changeInfo != undefined && changeInfo.url != undefined) { + console.log(changeInfo) + let id = youtube_parser(changeInfo.url); + if (changeInfo.url && id) { // If URL changed and is youtube video message contentScript the video id + chrome.tabs.sendMessage( tabId, { + message: 'ytvideoid', + id: id + }) + } } } ); + function youtube_parser(url) { // Return video id or false var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/; var match = url.match(regExp); return (match && match[7].length == 11) ? match[7] : false; -} +} \ No newline at end of file diff --git a/manifest.json b/manifest.json index 6f52b86a..b9de834f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,20 +1,25 @@ { "name": "YTSponsorSkip", "version": "1.0", - "description": "Skip youtube video sponsors", + "description": "Skip youtube video sponsors.", "content_scripts": [ { "matches": [ "https://*.youtube.com/*" ], "js": [ - "ContentScript.js" + "contentScript.js" ] } ], "permissions": [ - "tabs" + "tabs", + "storage" ], + "browser_action": { + "default_title": "SponsorBlock", + "default_popup": "popup.html" + }, "background": { "scripts":["background.js"] }, diff --git a/popup.css b/popup.css new file mode 100644 index 00000000..2c0193cd --- /dev/null +++ b/popup.css @@ -0,0 +1,7 @@ +* { + font-family: 'Arial'; +} + +body { + width: 300px; +} \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 00000000..ebeea867 --- /dev/null +++ b/popup.html @@ -0,0 +1,27 @@ + +
+