diff --git a/_locales/en/messages.json b/_locales/en/messages.json index d5684bb040..51847faf3e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -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" }, diff --git a/content.js b/content.js index 0a829e5144..39c9d73e7c 100644 --- a/content.js +++ b/content.js @@ -275,10 +275,10 @@ 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; @@ -286,9 +286,19 @@ function videoIDChange(id) { //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) { @@ -391,7 +401,7 @@ function sponsorsLookup(id, channelIDPromise) { setTimeout(() => sponsorsLookup(id), 100); return; } - + if (!durationListenerSetUp) { durationListenerSetUp = true; @@ -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; @@ -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); diff --git a/utils.js b/utils.js index 838769a273..4885c9c7a9 100644 --- a/utils.js +++ b/utils.js @@ -104,4 +104,4 @@ function getErrorMessage(statusCode) { } return errorMessage; -} \ No newline at end of file +}