mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-08 20:47:11 +03:00
Made player controls work
This commit is contained in:
@@ -30,9 +30,39 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
||||
if (previousVideoID != request.videoID) {
|
||||
videoIDChange(request.videoID);
|
||||
}
|
||||
} else if(request.message == "addSponsorTime") {
|
||||
addSponsorTime(request.time);
|
||||
}
|
||||
});
|
||||
|
||||
function addSponsorTime(time) {
|
||||
//get sponsor times
|
||||
let sponsorTimes = [];
|
||||
let sponsorTimeKey = "sponsorTimes" + previousVideoID;
|
||||
chrome.storage.local.get([sponsorTimeKey], function(result) {
|
||||
let sponsorTimesStorage = result[sponsorTimeKey];
|
||||
console.log(sponsorTimesStorage)
|
||||
if (sponsorTimesStorage != undefined && sponsorTimesStorage.length > 0) {
|
||||
sponsorTimes = sponsorTimesStorage;
|
||||
}
|
||||
|
||||
//add to sponsorTimes
|
||||
if (sponsorTimes.length > 0 && sponsorTimes[sponsorTimes.length - 1].length < 2) {
|
||||
//it is an end time
|
||||
sponsorTimes[sponsorTimes.length - 1][1] = parseInt(time);
|
||||
} else {
|
||||
//it is a start time
|
||||
let sponsorTimesIndex = sponsorTimes.length;
|
||||
sponsorTimes[sponsorTimesIndex] = [];
|
||||
|
||||
sponsorTimes[sponsorTimesIndex][0] = parseInt(time);
|
||||
}
|
||||
|
||||
//save this info
|
||||
chrome.storage.local.set({[sponsorTimeKey]: sponsorTimes});
|
||||
});
|
||||
}
|
||||
|
||||
function submitTimes(videoID) {
|
||||
//get the video times from storage
|
||||
let sponsorTimeKey = 'sponsorTimes' + videoID;
|
||||
|
||||
14
content.js
14
content.js
@@ -125,11 +125,11 @@ function goBackToPreviousTime() {
|
||||
}
|
||||
|
||||
//Adds a sponsorship starts button to the player controls
|
||||
function addPlayerControlsButton(){
|
||||
function addPlayerControlsButton() {
|
||||
let startSponsorButton = document.createElement("button");
|
||||
startSponsorButton.className = "ytp-button";
|
||||
startSponsorButton.setAttribute("title", "Sponsor Starts Now");
|
||||
startSponsorButton.addEventListener("click", console.log);
|
||||
startSponsorButton.addEventListener("click", startSponsorClicked);
|
||||
|
||||
let startSponsorImage = document.createElement("img");
|
||||
startSponsorImage.style.height = "60%";
|
||||
@@ -149,6 +149,14 @@ function addPlayerControlsButton(){
|
||||
|
||||
addPlayerControlsButton();
|
||||
|
||||
function startSponsorClicked() {
|
||||
//send back current time witj message
|
||||
chrome.runtime.sendMessage({
|
||||
message: "addSponsorTime",
|
||||
time: v.currentTime
|
||||
});
|
||||
}
|
||||
|
||||
//Opens the notice that tells the user that a sponsor was just skipped
|
||||
function openSkipNotice(){
|
||||
if (dontShowNotice) {
|
||||
@@ -233,8 +241,6 @@ function dontShowNoticeAgain() {
|
||||
function sponsorMessageStarted() {
|
||||
let v = document.querySelector('video');
|
||||
|
||||
console.log(v.currentTime)
|
||||
|
||||
//send back current time
|
||||
chrome.runtime.sendMessage({
|
||||
message: "time",
|
||||
|
||||
Reference in New Issue
Block a user