From 33fe63084b2c3d414854d577f242a2eac8b74b1a Mon Sep 17 00:00:00 2001 From: Ajay Ramachandran Date: Fri, 26 Jul 2019 16:20:07 -0400 Subject: [PATCH] Added support for hotkeys to submit data. --- background.js | 8 ++++---- content.js | 27 +++++++++++++++++++++++---- firefox_manifest.json | 2 +- manifest.json | 2 +- 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/background.js b/background.js index e76d7daf8a..f391175a99 100644 --- a/background.js +++ b/background.js @@ -36,7 +36,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { //this allows the callback to be called later by the submitTimes function return true; } else if (request.message == "addSponsorTime") { - addSponsorTime(request.time); + addSponsorTime(request.time, request.videoID); } else if (request.message == "getSponsorTimes") { getSponsorTimes(request.videoID, function(sponsorTimes) { callback({ @@ -69,8 +69,8 @@ function getSponsorTimes(videoID, callback) { }); } -function addSponsorTime(time) { - getSponsorTimes(previousVideoID, function(sponsorTimes) { +function addSponsorTime(time, videoID) { + getSponsorTimes(videoID, function(sponsorTimes) { //add to sponsorTimes if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { //it is an end time @@ -84,7 +84,7 @@ function addSponsorTime(time) { } //save this info - let sponsorTimeKey = "sponsorTimes" + previousVideoID; + let sponsorTimeKey = "sponsorTimes" + videoID; chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); }); } diff --git a/content.js b/content.js index adb0bddefb..9bf9005a94 100644 --- a/content.js +++ b/content.js @@ -97,6 +97,25 @@ chrome.runtime.onMessage.addListener( // Detect URL Changes } }); +//check for hotkey pressed +document.onkeydown = function(e){ + e = e || window.event; + var key = e.which || e.keyCode; + + let video = document.getElementById("movie_player"); + + //is the video in focus, otherwise they could be typing a comment + if (document.activeElement === video) { + if(key == 186){ + //semicolon + startSponsorClicked(); + } else if (key == 222) { + //single quote + submitSponsorTimes(); + } + } +} + function videoIDChange(id) { //reset last sponsor times lastTime = -1; @@ -250,11 +269,10 @@ function removePlayerControlsButton() { //adds or removes the player controls button to what it should be function updateVisibilityOfPlayerControlsButton() { + addPlayerControlsButton(); + addSubmitButton(); if (hideVideoPlayerControls) { removePlayerControlsButton(); - } else { - addPlayerControlsButton(); - addSubmitButton(); } } @@ -264,7 +282,8 @@ function startSponsorClicked() { //send back current time with message chrome.runtime.sendMessage({ message: "addSponsorTime", - time: v.currentTime + time: v.currentTime, + videoID: getYouTubeVideoID(document.URL) }); } diff --git a/firefox_manifest.json b/firefox_manifest.json index 8b8f939eab..8020aa36e4 100644 --- a/firefox_manifest.json +++ b/firefox_manifest.json @@ -1,7 +1,7 @@ { "name": "SponsorBlock - YouTube Sponsorship Blocker", "short_name": "SponsorBlock", - "version": "1.0.5", + "version": "1.0.6", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.", "content_scripts": [ { diff --git a/manifest.json b/manifest.json index b365cedd80..bfecefba1c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "SponsorBlock - YouTube Sponsorship Blocker", "short_name": "SponsorBlock", - "version": "1.0.5", + "version": "1.0.6", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.", "content_scripts": [ {