mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-07 12:07:11 +03:00
Added channel whitelisting.
Known issue: Does not work with 0 second sponsors. Resolves https://github.com/ajayyy/SponsorBlock/issues/38
This commit is contained in:
125
popup.js
125
popup.js
@@ -25,6 +25,8 @@ function runThePopup() {
|
||||
var SB = {};
|
||||
|
||||
["sponsorStart",
|
||||
"whitelistChannel",
|
||||
"unwhitelistChannel",
|
||||
"clearTimes",
|
||||
"submitTimes",
|
||||
"showNoticeAgain",
|
||||
@@ -63,6 +65,8 @@ function runThePopup() {
|
||||
|
||||
//setup click listeners
|
||||
SB.sponsorStart.addEventListener("click", sendSponsorStartMessage);
|
||||
SB.whitelistChannel.addEventListener("click", whitelistChannel);
|
||||
SB.unwhitelistChannel.addEventListener("click", unwhitelistChannel);
|
||||
SB.clearTimes.addEventListener("click", clearTimes);
|
||||
SB.submitTimes.addEventListener("click", submitTimes);
|
||||
SB.showNoticeAgain.addEventListener("click", showNoticeAgain);
|
||||
@@ -118,6 +122,26 @@ function runThePopup() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
//see if whitelist button should be swapped
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
chrome.tabs.sendMessage(
|
||||
tabs[0].id,
|
||||
{message: 'isChannelWhitelisted'},
|
||||
function(response) {
|
||||
if (response.value) {
|
||||
SB.whitelistChannel.style.display = "none";
|
||||
SB.unwhitelistChannel.style.display = "unset";
|
||||
|
||||
SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
|
||||
SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
//if the don't show notice again letiable is true, an option to
|
||||
// disable should be available
|
||||
@@ -343,7 +367,9 @@ function runThePopup() {
|
||||
function displayDownloadedSponsorTimes(request) {
|
||||
if (request.sponsorTimes != undefined) {
|
||||
//set it to the message
|
||||
SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
|
||||
if (SB.downloadedSponsorMessageTimes.innerText != "Channel Whitelisted!") {
|
||||
SB.downloadedSponsorMessageTimes.innerText = getSponsorTimesMessage(request.sponsorTimes);
|
||||
}
|
||||
|
||||
//add them as buttons to the issue reporting container
|
||||
let container = document.getElementById("issueReporterTimeButtons");
|
||||
@@ -966,6 +992,103 @@ function runThePopup() {
|
||||
|
||||
return formatted;
|
||||
}
|
||||
|
||||
function whitelistChannel() {
|
||||
//get the channel url
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
chrome.tabs.sendMessage(
|
||||
tabs[0].id,
|
||||
{message: 'getChannelURL'},
|
||||
function(response) {
|
||||
//get whitelisted channels
|
||||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
if (whitelistedChannels == undefined) {
|
||||
whitelistedChannels = [];
|
||||
}
|
||||
|
||||
//add on this channel
|
||||
whitelistedChannels.push(response.channelURL);
|
||||
|
||||
//change button
|
||||
SB.whitelistChannel.style.display = "none";
|
||||
SB.unwhitelistChannel.style.display = "unset";
|
||||
|
||||
SB.downloadedSponsorMessageTimes.innerText = "Channel Whitelisted!";
|
||||
SB.downloadedSponsorMessageTimes.style.fontWeight = "bold";
|
||||
|
||||
//save this
|
||||
chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
|
||||
|
||||
//send a message to the client
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
chrome.tabs.sendMessage(
|
||||
tabs[0].id, {
|
||||
message: 'whitelistChange',
|
||||
value: true
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function unwhitelistChannel() {
|
||||
//get the channel url
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
chrome.tabs.sendMessage(
|
||||
tabs[0].id,
|
||||
{message: 'getChannelURL'},
|
||||
function(response) {
|
||||
//get whitelisted channels
|
||||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
if (whitelistedChannels == undefined) {
|
||||
whitelistedChannels = [];
|
||||
}
|
||||
|
||||
//remove this channel
|
||||
let index = whitelistedChannels.indexOf(response.channelURL);
|
||||
whitelistedChannels.splice(index, 1);
|
||||
|
||||
//change button
|
||||
SB.whitelistChannel.style.display = "unset";
|
||||
SB.unwhitelistChannel.style.display = "none";
|
||||
|
||||
SB.downloadedSponsorMessageTimes.innerText = "";
|
||||
SB.downloadedSponsorMessageTimes.style.fontWeight = "unset";
|
||||
|
||||
//save this
|
||||
chrome.storage.sync.set({whitelistedChannels: whitelistedChannels});
|
||||
|
||||
//send a message to the client
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
}, tabs => {
|
||||
chrome.tabs.sendMessage(
|
||||
tabs[0].id, {
|
||||
message: 'whitelistChange',
|
||||
value: false
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
//converts time in seconds to minutes
|
||||
function getTimeInMinutes(seconds) {
|
||||
|
||||
Reference in New Issue
Block a user