Added support for hotkeys to submit data.

This commit is contained in:
Ajay Ramachandran
2019-07-26 16:20:07 -04:00
parent 7a17cc2b0a
commit 33fe63084b
4 changed files with 29 additions and 10 deletions

View File

@@ -36,7 +36,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
//this allows the callback to be called later by the submitTimes function //this allows the callback to be called later by the submitTimes function
return true; return true;
} else if (request.message == "addSponsorTime") { } else if (request.message == "addSponsorTime") {
addSponsorTime(request.time); addSponsorTime(request.time, request.videoID);
} else if (request.message == "getSponsorTimes") { } else if (request.message == "getSponsorTimes") {
getSponsorTimes(request.videoID, function(sponsorTimes) { getSponsorTimes(request.videoID, function(sponsorTimes) {
callback({ callback({
@@ -69,8 +69,8 @@ function getSponsorTimes(videoID, callback) {
}); });
} }
function addSponsorTime(time) { function addSponsorTime(time, videoID) {
getSponsorTimes(previousVideoID, function(sponsorTimes) { getSponsorTimes(videoID, function(sponsorTimes) {
//add to sponsorTimes //add to sponsorTimes
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) { if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
//it is an end time //it is an end time
@@ -84,7 +84,7 @@ function addSponsorTime(time) {
} }
//save this info //save this info
let sponsorTimeKey = "sponsorTimes" + previousVideoID; let sponsorTimeKey = "sponsorTimes" + videoID;
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes}); chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
}); });
} }

View File

@@ -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) { function videoIDChange(id) {
//reset last sponsor times //reset last sponsor times
lastTime = -1; lastTime = -1;
@@ -250,11 +269,10 @@ function removePlayerControlsButton() {
//adds or removes the player controls button to what it should be //adds or removes the player controls button to what it should be
function updateVisibilityOfPlayerControlsButton() { function updateVisibilityOfPlayerControlsButton() {
addPlayerControlsButton();
addSubmitButton();
if (hideVideoPlayerControls) { if (hideVideoPlayerControls) {
removePlayerControlsButton(); removePlayerControlsButton();
} else {
addPlayerControlsButton();
addSubmitButton();
} }
} }
@@ -264,7 +282,8 @@ function startSponsorClicked() {
//send back current time with message //send back current time with message
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
message: "addSponsorTime", message: "addSponsorTime",
time: v.currentTime time: v.currentTime,
videoID: getYouTubeVideoID(document.URL)
}); });
} }

View File

@@ -1,7 +1,7 @@
{ {
"name": "SponsorBlock - YouTube Sponsorship Blocker", "name": "SponsorBlock - YouTube Sponsorship Blocker",
"short_name": "SponsorBlock", "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.", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"content_scripts": [ "content_scripts": [
{ {

View File

@@ -1,7 +1,7 @@
{ {
"name": "SponsorBlock - YouTube Sponsorship Blocker", "name": "SponsorBlock - YouTube Sponsorship Blocker",
"short_name": "SponsorBlock", "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.", "description": "Skip over sponsorship on YouTube videos. Report sponsors on videos you watch to save the time of others.",
"content_scripts": [ "content_scripts": [
{ {