isUnlisted now uses JSON data.

This commit is contained in:
Ajay Ramachandran
2020-04-26 20:40:11 -04:00
parent 6179278699
commit 18852d16ac
3 changed files with 18 additions and 25 deletions

View File

@@ -424,10 +424,10 @@
"message": "The video has been detected as unlisted. Click cancel if you do not want to check for sponsors." "message": "The video has been detected as unlisted. Click cancel if you do not want to check for sponsors."
}, },
"unlistedCheck": { "unlistedCheck": {
"message": "Ignore Unlisted Videos" "message": "Ignore Unlisted/Private Videos"
}, },
"whatUnlistedCheck": { "whatUnlistedCheck": {
"message": "This setting will significantly slow down SponsorBlock. Sponsor lookups require sending the video ID to the server. If you are concerned about unlisted video IDs being sent over the internet, enable this option." "message": "This setting will slightly slow down SponsorBlock. Sponsor lookups require sending the video ID to the server. If you are concerned about unlisted video IDs being sent over the internet, enable this option."
}, },
"mobileUpdateInfo": { "mobileUpdateInfo": {
"message": "m.youtube.com is now supported" "message": "m.youtube.com is now supported"
@@ -542,6 +542,12 @@
"message": "hidden: too short" "message": "hidden: too short"
}, },
"channelDataNotFound": { "channelDataNotFound": {
"message": "Channel ID not loaded yet" "message": "Channel ID not loaded yet."
},
"adblockerIssue": {
"message": "It seems that something is blocking SponsorBlock's ability to get video data. This is probably uBlock. Please check https://github.com/ajayyy/SponsorBlock/wiki/Fix-uBlock-Origin-Blocking-YouTube-Requests"
},
"itCouldBeAdblockerIssue": {
"message": "If this keeps occuring, it could be caused by uBlock. Please check https://github.com/ajayyy/SponsorBlock/wiki/Fix-uBlock-Origin-Blocking-YouTube-Requests"
} }
} }

View File

@@ -301,7 +301,11 @@ async function videoIDChange(id) {
// If enabled, it will check if this video is private or unlisted and double check with the user if the sponsors should be looked up // If enabled, it will check if this video is private or unlisted and double check with the user if the sponsors should be looked up
if (Config.config.checkForUnlistedVideos) { if (Config.config.checkForUnlistedVideos) {
await utils.wait(isPrivacyInfoAvailable); try {
await utils.wait(() => !!videoInfo, 5000, 10);
} catch (err) {
alert(chrome.i18n.getMessage("adblockerIssue"));
}
if (isUnlisted()) { if (isUnlisted()) {
let shouldContinue = confirm(chrome.i18n.getMessage("confirmPrivacy")); let shouldContinue = confirm(chrome.i18n.getMessage("confirmPrivacy"));
@@ -310,7 +314,7 @@ async function videoIDChange(id) {
} }
// Update whitelist data when the video data is loaded // Update whitelist data when the video data is loaded
utils.wait(() => !!videoInfo).then(whitelistCheck); utils.wait(() => !!videoInfo, 5000, 10).then(whitelistCheck);
//setup the preview bar //setup the preview bar
if (previewBar === null) { if (previewBar === null) {
@@ -1486,30 +1490,12 @@ function getSegmentsMessage(segments: number[][]): string {
return sponsorTimesMessage; return sponsorTimesMessage;
} }
// Privacy utils
function isPrivacyInfoAvailable(): boolean {
if(document.location.pathname.startsWith("/embed/")) return true;
return document.getElementsByClassName("style-scope ytd-badge-supported-renderer").length >= 2;
}
/**
* What privacy level is this YouTube video?
*/
function getPrivacy(): string {
if(document.location.pathname.startsWith("/embed/")) return "Public";
let privacyElement = <HTMLElement> document.getElementsByClassName("style-scope ytd-badge-supported-renderer")[2];
return privacyElement.innerText;
}
/** /**
* Is this an unlisted YouTube video. * Is this an unlisted YouTube video.
* Assumes that the the privacy info is available. * Assumes that the the privacy info is available.
*/ */
function isUnlisted(): boolean { function isUnlisted(): boolean {
let privacyElement = <HTMLElement> document.getElementsByClassName("style-scope ytd-badge-supported-renderer")[2]; return videoInfo.microformat.playerMicroformatRenderer.isUnlisted || videoInfo.videoDetails.isPrivate;
return privacyElement.innerText.toLocaleLowerCase() === "unlisted";
} }
/** /**

View File

@@ -922,7 +922,8 @@ async function runThePopup(messageListener?: MessageListener) {
{message: 'getChannelID'}, {message: 'getChannelID'},
function(response) { function(response) {
if (!response.channelID) { if (!response.channelID) {
alert(chrome.i18n.getMessage("channelDataNotFound")); alert(chrome.i18n.getMessage("channelDataNotFound") + "\n\n" +
chrome.i18n.getMessage("itCouldBeAdblockerIssue"));
return; return;
} }