Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirm on video that is not public [TESTING] #210

Closed
wants to merge 19 commits into from
Closed
3 changes: 3 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@
"statusReminder": {
"message": "Check status.sponsor.ajay.app for server status."
},
"confirmPrivacy": {
"message": "The video has been detected as not public. Click cancel if you do not want to check for sponsors."
},
"changeUserID": {
"message": "Import/Export Your UserID"
},
Expand Down
43 changes: 37 additions & 6 deletions content.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,30 @@ function resetValues() {
sponsorDataFound = false;
}

function videoIDChange(id) {

async function videoIDChange(id) {
//if the id has not changed return
if (sponsorVideoID === id) return;

//set the global videoID
sponsorVideoID = id;

resetValues();

//id is not valid
if (!id) return;


await wait(isPrivacyInfoAvailable);
if (isUnlisted()) {
let shouldContinue = confirm(chrome.i18n.getMessage("confirmPrivacy"));
if(!shouldContinue) return;
}

let channelIDPromise = wait(getChannelID);
channelIDPromise.then(() => channelIDPromise.isFulfilled = true).catch(() => channelIDPromise.isRejected = true);
channelIDPromise.then(() => {
channelIDPromise.isFulfilled = true
}).catch(() => {
channelIDPromise.isRejected = true
});

//setup the preview bar
if (previewBar == null) {
Expand Down Expand Up @@ -391,7 +401,7 @@ function sponsorsLookup(id, channelIDPromise) {
setTimeout(() => sponsorsLookup(id), 100);
return;
}

if (!durationListenerSetUp) {
durationListenerSetUp = true;

Expand All @@ -410,7 +420,7 @@ function sponsorsLookup(id, channelIDPromise) {
channelIDPromise.then(whitelistCheck);
}
}

//check database for sponsor times
//made true once a setTimeout has been created to try again after a server error
let recheckStarted = false;
Expand Down Expand Up @@ -1132,6 +1142,27 @@ function getSponsorTimesMessage(sponsorTimes) {
return sponsorTimesMessage;
}

// Privacy utils
function isPrivacyInfoAvailable() {
if(document.location.pathname.startsWith("/embed/")) return true;
return (document.getElementsByClassName("style-scope ytd-badge-supported-renderer").length >= 2);
}

function getPrivacy() {
if(document.location.pathname.startsWith("/embed/")) return "Public";
return document.getElementsByClassName("style-scope ytd-badge-supported-renderer")[2].innerText;
}

/**
* Is this a unlisted YouTube video
*
* @returns {Boolean}
*/
function isUnlisted() {
return !document.location.pathname.startsWith("/embed/") &&
(document.getElementsByClassName("style-scope ytd-badge-supported-renderer")[2].innerText === "Unlisted");
}

//converts time in seconds to minutes:seconds
function getFormattedTime(seconds) {
let minutes = Math.floor(seconds / 60);
Expand Down
2 changes: 1 addition & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ function getErrorMessage(statusCode) {
}

return errorMessage;
}
}