Changed whitelisting to use channel JSON instead of page scraping.

It also only pulls data once. Uses channelID now instead of URLs.

Resolves https://github.com/ajayyy/SponsorBlock/issues/275

TODO: Add migration method to use channelID instead of channelURL
This commit is contained in:
Ajay Ramachandran
2020-04-26 15:16:00 -04:00
parent 0f9e794428
commit 16896be97f
3 changed files with 84 additions and 124 deletions

View File

@@ -919,39 +919,44 @@ async function runThePopup(messageListener?: MessageListener) {
}, tabs => {
messageHandler.sendMessage(
tabs[0].id,
{message: 'getChannelURL'},
{message: 'getChannelID'},
function(response) {
if (!response.channelID) {
alert(chrome.i18n.getMessage("channelDataNotFound"));
return;
}
//get whitelisted channels
let whitelistedChannels = Config.config.whitelistedChannels;
if (whitelistedChannels == undefined) {
whitelistedChannels = [];
let whitelistedChannels = Config.config.whitelistedChannels;
if (whitelistedChannels == undefined) {
whitelistedChannels = [];
}
//add on this channel
whitelistedChannels.push(response.channelID);
//change button
PageElements.whitelistChannel.style.display = "none";
PageElements.unwhitelistChannel.style.display = "unset";
PageElements.downloadedSponsorMessageTimes.innerText = chrome.i18n.getMessage("channelWhitelisted");
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold";
//save this
Config.config.whitelistedChannels = whitelistedChannels;
//send a message to the client
messageHandler.query({
active: true,
currentWindow: true
}, tabs => {
messageHandler.sendMessage(
tabs[0].id, {
message: 'whitelistChange',
value: true
});
}
//add on this channel
whitelistedChannels.push(response.channelURL);
//change button
PageElements.whitelistChannel.style.display = "none";
PageElements.unwhitelistChannel.style.display = "unset";
PageElements.downloadedSponsorMessageTimes.innerText = chrome.i18n.getMessage("channelWhitelisted");
PageElements.downloadedSponsorMessageTimes.style.fontWeight = "bold";
//save this
Config.config.whitelistedChannels = whitelistedChannels;
//send a message to the client
messageHandler.query({
active: true,
currentWindow: true
}, tabs => {
messageHandler.sendMessage(
tabs[0].id, {
message: 'whitelistChange',
value: true
});
}
);
);
}
);
});