mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2026-01-28 21:30:56 +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:
59
content.js
59
content.js
@@ -17,6 +17,12 @@ if(id = getYouTubeVideoID(document.URL)){ // Direct Links
|
||||
//the video
|
||||
var v;
|
||||
|
||||
//the channel this video is about
|
||||
var channelURL;
|
||||
|
||||
//is this channel whitelised from getting sponsors skipped
|
||||
var channelWhitelisted = false;
|
||||
|
||||
//the last time looked at (used to see if this time is in the interval)
|
||||
var lastTime = -1;
|
||||
|
||||
@@ -109,6 +115,23 @@ function messageListener(request, sender, sendResponse) {
|
||||
})
|
||||
}
|
||||
|
||||
if (request.message == "getChannelURL") {
|
||||
sendResponse({
|
||||
channelURL: channelURL
|
||||
})
|
||||
}
|
||||
|
||||
if (request.message == "isChannelWhitelisted") {
|
||||
sendResponse({
|
||||
value: channelWhitelisted
|
||||
})
|
||||
}
|
||||
|
||||
if (request.message == "whitelistChange") {
|
||||
channelWhitelisted = request.value;
|
||||
sponsorsLookup(getYouTubeVideoID(document.URL));
|
||||
}
|
||||
|
||||
if (request.message == "showNoticeAgain") {
|
||||
dontShowNotice = false;
|
||||
}
|
||||
@@ -246,6 +269,9 @@ function sponsorsLookup(id) {
|
||||
|
||||
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
|
||||
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
|
||||
|
||||
getChannelID();
|
||||
|
||||
} else if (xmlhttp.readyState == 4) {
|
||||
sponsorDataFound = false;
|
||||
|
||||
@@ -270,6 +296,39 @@ function sponsorsLookup(id) {
|
||||
};
|
||||
}
|
||||
|
||||
function getChannelID() {
|
||||
//get channel id
|
||||
let channelContainers = document.querySelectorAll("#owner-name");
|
||||
let channelURLContainer = null;
|
||||
|
||||
for (let i = 0; i < channelContainers.length; i++) {
|
||||
if (channelContainers[i].firstElementChild != null) {
|
||||
channelURLContainer = channelContainers[i].firstElementChild;
|
||||
}
|
||||
}
|
||||
|
||||
if (channelURLContainer == null) {
|
||||
//try later
|
||||
setTimeout(getChannelID, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
channelURL = channelURLContainer.getAttribute("href");
|
||||
|
||||
//see if this is a whitelisted channel
|
||||
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
|
||||
let whitelistedChannels = result.whitelistedChannels;
|
||||
|
||||
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
|
||||
//reset sponsor times to nothing
|
||||
sponsorTimes = [];
|
||||
UUIDs = [];
|
||||
|
||||
channelWhitelisted = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//video skipping
|
||||
function sponsorCheck() {
|
||||
let skipHappened = false;
|
||||
|
||||
Reference in New Issue
Block a user