Skip to content

Commit

Permalink
Merge pull request #9 from ajayyy/experimental
Browse files Browse the repository at this point in the history
Added support for hotkeys to submit data
  • Loading branch information
ajayyy committed Jul 26, 2019
2 parents 8f47513 + 33fe630 commit 5436a16
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
8 changes: 4 additions & 4 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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
Expand All @@ -84,7 +84,7 @@ function addSponsorTime(time) {
}

//save this info
let sponsorTimeKey = "sponsorTimes" + previousVideoID;
let sponsorTimeKey = "sponsorTimes" + videoID;
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
});
}
Expand Down
27 changes: 23 additions & 4 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -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)
});
}

Expand Down
2 changes: 1 addition & 1 deletion firefox_manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
{
Expand Down

0 comments on commit 5436a16

Please sign in to comment.