Fix merge error

This commit is contained in:
OfficialNoob
2019-08-13 22:14:45 +01:00
7 changed files with 290 additions and 38 deletions

View File

@@ -7,18 +7,27 @@ var UUIDs = null;
//what video id are these sponsors for
var sponsorVideoID = null;
//these are sponsors that have been downvoted
var hiddenSponsorTimes = [];
//the time this video is starting at when first played, if not zero
var youtubeVideoStartTime = null;
//the video
var v;
var listenerAdded;
//the channel this video is about
var channelURL;
//is this channel whitelised from getting sponsors skipped
var channelWhitelisted = false;
// create preview bar
let progressBar = document.getElementsByClassName("ytp-progress-bar-container")[0] || document.getElementsByClassName("no-model cue-range-markers")[0];
var previewBar = new PreviewBar(progressBar);
if(id = getYouTubeVideoID(document.URL)){ // Direct Links
videoIDChange(id);
}
@@ -102,6 +111,7 @@ function messageListener(request, sender, sendResponse) {
sendResponse({
found: sponsorDataFound,
sponsorTimes: sponsorTimes,
hiddenSponsorTimes: hiddenSponsorTimes,
UUIDs: UUIDs
});
@@ -233,6 +243,9 @@ function videoIDChange(id) {
sponsorVideoID = id;
sponsorLookupRetries = 0;
//empty the preview bar
previewBar.set([], [], 0);
//see if there is a video start time
youtubeVideoStartTime = getYouTubeVideoStartTime(document.URL);
@@ -310,6 +323,17 @@ function sponsorsLookup(id) {
sponsorTimes = JSON.parse(xmlhttp.responseText).sponsorTimes;
UUIDs = JSON.parse(xmlhttp.responseText).UUIDs;
//update the preview bar
//leave the type blank for now until categories are added
console.log(v.duration)
if (isNaN(v.duration)) {
//wait until it is loaded
v.addEventListener('durationchange', updatePreviewBar);
} else {
//set it now
updatePreviewBar();
}
getChannelID();
sponsorLookupRetries = 0;
@@ -330,7 +354,7 @@ function sponsorsLookup(id) {
});
sponsorLookupRetries = 0;
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 15) {
} else if (xmlhttp.readyState == 4 && sponsorLookupRetries < 90) {
//some error occurred, try again in a second
setTimeout(() => sponsorsLookup(id), 1000);
@@ -344,6 +368,13 @@ function sponsorsLookup(id) {
};
}
function updatePreviewBar() {
previewBar.set(sponsorTimes, [], v.duration);
//the listener is only needed once
v.removeEventListener('durationchange', updatePreviewBar);
}
function getChannelID() {
//get channel id
let channelContainers = document.querySelectorAll("#owner-name");
@@ -423,7 +454,7 @@ function checkSponsorTime(sponsorTimes, index, openNotice) {
lastTime = v.currentTime - 0.0001;
}
if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0])) {
if (checkIfTimeToSkip(v.currentTime, sponsorTimes[index][0]) && !hiddenSponsorTimes.includes(index)) {
//skip it
skipToTime(v, index, sponsorTimes, openNotice);
@@ -934,6 +965,26 @@ function afterDownvote(UUID) {
//add element to div
document.getElementById("sponsorTimesVoteButtonsContainer" + UUID).appendChild(thanksForVotingText);
document.getElementById("sponsorTimesVoteButtonsContainer" + UUID).appendChild(thanksForVotingInfoText);
//remove this sponsor from the sponsors looked up
//find which one it is
for (let i = 0; i < sponsorTimes.length; i++) {
if (UUIDs[i] == UUID) {
//this one is the one to hide
//add this as a hidden sponsorTime
hiddenSponsorTimes.push(i);
let sponsorTimesLeft = sponsorTimes.slice();
for (let j = 0; j < hiddenSponsorTimes.length; j++) {
//remove this sponsor time
sponsorTimesLeft.splice(hiddenSponsorTimes[j], 1);
}
//update the preview
previewBar.set(sponsorTimesLeft, [], v.duration);
}
}
}
function addLoadingInfo(message, UUID) {