Added option to force a whitelist check before allowing skipping.

This commit is contained in:
Ajay Ramachandran
2020-04-26 23:14:18 -04:00
parent 797fbf563b
commit fbafb723cb
5 changed files with 57 additions and 27 deletions

View File

@@ -8,6 +8,7 @@ interface SBConfig {
userID: string,
sponsorTimes: SBMap<string, any>,
whitelistedChannels: string[],
forceChannelCheck: boolean,
startSponsorKeybind: string,
submitKeybind: string,
minutesSaved: number,
@@ -107,6 +108,7 @@ var Config: SBObject = {
userID: null,
sponsorTimes: new SBMap("sponsorTimes"),
whitelistedChannels: [],
forceChannelCheck: false,
startSponsorKeybind: ";",
submitKeybind: "'",
minutesSaved: 0,

View File

@@ -463,7 +463,7 @@ function startSponsorSchedule(includeIntersectingSegments: boolean = false, curr
cancelSponsorSchedule();
if (video.paused) return;
if (Config.config.disableSkipping || channelWhitelisted){
if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){
return;
}
@@ -637,30 +637,7 @@ function sponsorsLookup(id: string) {
}
}
if (!switchingVideos) {
// See if there are any starting sponsors
let startingSponsor: number = -1;
for (const time of sponsorTimes) {
if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) {
startingSponsor = time.segment[0];
break;
}
}
if (startingSponsor === -1) {
for (const time of sponsorTimesSubmitting) {
if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) {
startingSponsor = time.segment[0];
break;
}
}
}
if (startingSponsor !== -1) {
startSponsorSchedule(false, startingSponsor);
} else {
startSponsorSchedule();
}
}
startSkipScheduleCheckingForStartSponsors();
// Reset skip save
sponsorSkipped = [];
@@ -701,6 +678,38 @@ function sponsorsLookup(id: string) {
});
}
/**
* Only should be used when it is okay to skip a sponsor when in the middle of it
*
* Ex. When segments are first loaded
*/
function startSkipScheduleCheckingForStartSponsors() {
if (!switchingVideos) {
// See if there are any starting sponsors
let startingSponsor: number = -1;
for (const time of sponsorTimes) {
if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) {
startingSponsor = time.segment[0];
break;
}
}
if (startingSponsor === -1) {
for (const time of sponsorTimesSubmitting) {
if (time.segment[0] <= video.currentTime && time.segment[0] > startingSponsor && time.segment[1] > video.currentTime) {
startingSponsor = time.segment[0];
break;
}
}
}
if (startingSponsor !== -1) {
startSponsorSchedule(false, startingSponsor);
} else {
startSponsorSchedule();
}
}
}
/**
* Get the video info for the current tab from YouTube
*/
@@ -807,6 +816,9 @@ function whitelistCheck() {
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelID)) {
channelWhitelisted = true;
}
// check if the start of segments were missed
if (sponsorTimes && sponsorTimes.length > 0) startSkipScheduleCheckingForStartSponsors();
}
/**

View File

@@ -51,6 +51,7 @@ async function runThePopup(messageListener?: MessageListener) {
// Top toggles
"whitelistChannel",
"unwhitelistChannel",
"whitelistForceCheck",
"disableSkipping",
"enableSkipping",
// Options
@@ -102,6 +103,7 @@ async function runThePopup(messageListener?: MessageListener) {
//setup click listeners
PageElements.sponsorStart.addEventListener("click", sendSponsorStartMessage);
PageElements.whitelistChannel.addEventListener("click", whitelistChannel);
PageElements.whitelistForceCheck.addEventListener("click", openOptions);
PageElements.unwhitelistChannel.addEventListener("click", unwhitelistChannel);
PageElements.disableSkipping.addEventListener("click", () => toggleSkipping(true));
PageElements.enableSkipping.addEventListener("click", () => toggleSkipping(false));
@@ -939,6 +941,7 @@ async function runThePopup(messageListener?: MessageListener) {
//change button
PageElements.whitelistChannel.style.display = "none";
PageElements.unwhitelistChannel.style.display = "unset";
if (!Config.config.forceChannelCheck) PageElements.whitelistForceCheck.style.display = "unset";
PageElements.downloadedSponsorMessageTimes.innerText = chrome.i18n.getMessage("channelWhitelisted");
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold";
@@ -971,7 +974,7 @@ async function runThePopup(messageListener?: MessageListener) {
}, tabs => {
messageHandler.sendMessage(
tabs[0].id,
{message: 'getChannelURL'},
{message: 'getChannelID'},
function(response) {
//get whitelisted channels
let whitelistedChannels = Config.config.whitelistedChannels;
@@ -980,7 +983,7 @@ async function runThePopup(messageListener?: MessageListener) {
}
//remove this channel
let index = whitelistedChannels.indexOf(response.channelURL);
let index = whitelistedChannels.indexOf(response.channelID);
whitelistedChannels.splice(index, 1);
//change button