Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into add-invidious

This commit is contained in:
Ajay Ramachandran
2019-12-19 00:40:32 -05:00
11 changed files with 420 additions and 105 deletions

View File

@@ -493,7 +493,12 @@ function updatePreviewBar() {
//create an array of the sponsor types
let types = [];
for (let i = 0; i < localSponsorTimes.length; i++) {
types.push("sponsor");
if (!hiddenSponsorTimes.includes(i)) {
types.push("sponsor");
} else {
// Don't show this sponsor
types.push(null);
}
}
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
types.push("previewSponsor");
@@ -507,19 +512,18 @@ function updatePreviewBar() {
function getChannelID() {
//get channel id
let channelContainers = document.querySelectorAll(".ytd-channel-name#text");
let channelURLContainer = null;
let channelNameContainer = document.getElementById("channel-name");
for (let i = 0; i < channelContainers.length; i++) {
let child = channelContainers[i].firstElementChild;
if (child != null && child.getAttribute("href") != "") {
channelURLContainer = child;
}
if (channelNameContainer === null) {
//try later
return false;
}
if (channelContainers.length == 0) {
let channelURLContainer = channelNameContainer.querySelector("#container").querySelector("#text-container").querySelector("#text").firstElementChild;
if (channelURLContainer === null) {
//old YouTube theme
channelContainers = document.getElementsByClassName("yt-user-info");
let channelContainers = document.getElementsByClassName("yt-user-info");
if (channelContainers.length != 0) {
channelURLContainer = channelContainers[0].firstElementChild;
} else if (onInvidious) {
@@ -531,7 +535,7 @@ function getChannelID() {
}
}
if (channelURLContainer == null) {
if (channelURLContainer === null) {
//try later
return false;
}
@@ -568,11 +572,9 @@ function whitelistCheck() {
chrome.storage.sync.get(["whitelistedChannels"], function(result) {
let whitelistedChannels = result.whitelistedChannels;
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
//reset sponsor times to nothing
sponsorTimes = [];
UUIDs = [];
console.log(channelURL)
if (whitelistedChannels != undefined && whitelistedChannels.includes(channelURL)) {
channelWhitelisted = true;
}
});
@@ -584,6 +586,8 @@ function sponsorCheck() {
// Make sure this isn't called again
v.ontimeupdate = null;
return;
} else if (channelWhitelisted) {
return;
}
let skipHappened = false;
@@ -1013,14 +1017,8 @@ function vote(type, UUID, skipNotice) {
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("voteFail"))
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
} else if (response.successType == -1) {
if (response.statusCode == 502) {
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("serverDown"))
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
} else {
//failure: unknown error
skipNotice.addNoticeInfoMessage.bind(skipNotice)(chrome.i18n.getMessage("connectionError") + response.statusCode);
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
}
skipNotice.addNoticeInfoMessage.bind(skipNotice)(getErrorMessage(response.statusCode))
skipNotice.resetVoteButtonInfo.bind(skipNotice)();
}
}
}
@@ -1080,8 +1078,11 @@ function submitSponsorTimes() {
//update sponsorTimes
chrome.storage.sync.set({[sponsorTimeKey]: sponsorTimes});
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes);
confirmMessage += "\n\n" + chrome.i18n.getMessage("confirmMSG");
//update sponsorTimesSubmitting
sponsorTimesSubmitting = sponsorTimes;
let confirmMessage = chrome.i18n.getMessage("submitCheck") + "\n\n" + getSponsorTimesMessage(sponsorTimes)
+ "\n\n" + chrome.i18n.getMessage("confirmMSG") + "\n\n" + chrome.i18n.getMessage("guildlinesSummary");
if(!confirm(confirmMessage)) return;
sendSubmitMessage();
@@ -1099,8 +1100,6 @@ function sendSubmitMessage(){
let currentVideoID = sponsorVideoID;
let currentSponsorTimes = submitSponsorTimes;
chrome.runtime.sendMessage({
message: "submitTimes",
videoID: currentVideoID
@@ -1124,24 +1123,25 @@ function sendSubmitMessage(){
//clear the sponsor times
let sponsorTimeKey = "sponsorTimes" + currentVideoID;
chrome.storage.sync.set({[sponsorTimeKey]: []}, () => void updatePreviewBar());
chrome.storage.sync.set({[sponsorTimeKey]: []});
//add submissions to current sponsors list
sponsorTimes = sponsorTimes.concat(sponsorTimesSubmitting);
for (let i = 0; i < sponsorTimesSubmitting.length; i++) {
// Add some random IDs
UUIDs.push(generateUserID());
}
// Empty the submitting times
sponsorTimesSubmitting = [];
updatePreviewBar();
} else {
//show that the upload failed
document.getElementById("submitButton").style.animation = "unset";
document.getElementById("submitImage").src = chrome.extension.getURL("icons/PlayerUploadFailedIconSponsorBlocker256px.png");
if([400, 429, 409, 502, 0].includes(response.statusCode)) {
//treat them the same
if (response.statusCode == 503) response.statusCode = 502;
alert(chrome.i18n.getMessage(response.statusCode + "") + " " + chrome.i18n.getMessage("errorCode") + response.statusCode);
} else {
alert(chrome.i18n.getMessage("connectionError") + response.statusCode);
}
alert(getErrorMessage(response.statusCode));
}
}
});