aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAjay Ramachandran <[email protected]>2021-05-21 17:33:48 -0400
committerAjay Ramachandran <[email protected]>2021-05-21 17:33:48 -0400
commita5189014adb78a94b1e661de8d8f341e14809dad (patch)
treed133082e591ad2cc263f80662bf3f9350a7aba0b
parente70a8c724b1f8ed8b64df07960429c8efb1462b3 (diff)
downloadSponsorBlock-a5189014adb78a94b1e661de8d8f341e14809dad.tar.gz
SponsorBlock-a5189014adb78a94b1e661de8d8f341e14809dad.zip
Make channel fetching error silent and don't wait for video info
-rw-r--r--public/_locales/en/messages.json6
-rw-r--r--src/content.ts60
-rw-r--r--src/popup.ts3
-rw-r--r--src/types.ts11
4 files changed, 33 insertions, 47 deletions
diff --git a/public/_locales/en/messages.json b/public/_locales/en/messages.json
index df9cdb57..a70310ed 100644
--- a/public/_locales/en/messages.json
+++ b/public/_locales/en/messages.json
@@ -583,7 +583,8 @@
"message": "hidden: too short"
},
"channelDataNotFound": {
- "message": "Channel ID not loaded yet."
+ "description": "This error appears in an alert when they try to whitelist a channel and the extension is unable to determine what channel they are looking at.",
+ "message": "Channel ID is not loaded yet. If you are using an embedded video, try using the YouTube homepage instead. This could also be caused by changes in the YouTube layout, if you think so, make a comment here:"
},
"videoInfoFetchFailed": {
"message": "It seems that something is blocking SponsorBlock's ability to get video data. Please see https://github.com/ajayyy/SponsorBlock/issues/741 for more info."
@@ -603,9 +604,6 @@
"adblockerIssueWhitelist": {
"message": "If you are unable to resolve this, then disable the setting 'Force Channel Check Before Skipping', as SponsorBlock is unable to retrieve the channel information for this video"
},
- "itCouldBeAdblockerIssue": {
- "message": "If this keeps occuring, it could be caused by your ad blocker. Please check https://github.com/ajayyy/SponsorBlock/wiki/Fix-Ad-Blocker-Blocking-SponsorBlock's-Requests"
- },
"forceChannelCheck": {
"message": "Force Channel Check Before Skipping"
},
diff --git a/src/content.ts b/src/content.ts
index ff9f3769..6c5a5a4f 100644
--- a/src/content.ts
+++ b/src/content.ts
@@ -1,6 +1,6 @@
import Config from "./config";
-import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject } from "./types";
+import { SponsorTime, CategorySkipOption, VideoID, SponsorHideType, FetchResponse, VideoInfo, StorageChangesObject, ChannelIDInfo, ChannelIDStatus } from "./types";
import { ContentContainer } from "./types";
import Utils from "./utils";
@@ -29,7 +29,7 @@ const skipNotices: SkipNotice[] = [];
// JSON video info
let videoInfo: VideoInfo = null;
//the channel this video is about
-let channelID: string;
+let channelIDInfo: ChannelIDInfo;
// Skips are scheduled to ensure precision.
// Skips are rescheduled every seeking event.
@@ -160,7 +160,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
break;
case "getChannelID":
sendResponse({
- channelID: channelID
+ channelID: channelIDInfo.id
});
break;
@@ -212,7 +212,10 @@ function resetValues() {
videoInfo = null;
channelWhitelisted = false;
- channelID = null;
+ channelIDInfo = {
+ status: ChannelIDStatus.Fetching,
+ id: null
+ };
//empty the preview bar
if (previewBar !== null) {
@@ -392,7 +395,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
if (video.paused) return;
- if (Config.config.disableSkipping || channelWhitelisted || (channelID === null && Config.config.forceChannelCheck)){
+ if (Config.config.disableSkipping || channelWhitelisted || (channelIDInfo.status === ChannelIDStatus.Fetching && Config.config.forceChannelCheck)){
return;
}
@@ -703,21 +706,6 @@ async function getVideoInfo(): Promise<void> {
}
}
-async function videoInfoFetchFailed(errorMessage: string): Promise<void> {
- console.log("failed\t" + errorMessage)
- if (utils.isFirefox() && !Config.config.ytInfoPermissionGranted) {
- // Attempt to ask permission for youtube.com domain
- alert(chrome.i18n.getMessage("youtubePermissionRequest"));
-
- chrome.runtime.sendMessage({
- message: "openPage",
- url: "permissions/index.html#youtube.com"
- });
- } else {
- alert(chrome.i18n.getMessage("videoInfoFetchFailed") + "\n\n" + chrome.i18n.getMessage(errorMessage));
- }
-}
-
function getYouTubeVideoID(url: string) {
// For YouTube TV support
if(url.startsWith("https://www.youtube.com/tv#/")) url = url.replace("#", "");
@@ -817,30 +805,20 @@ function updatePreviewBar(): void {
async function whitelistCheck() {
const whitelistedChannels = Config.config.whitelistedChannels;
- const getChannelID = () => videoInfo?.videoDetails?.channelId
- ?? document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube
+ const channelID = document.querySelector(".ytd-channel-name a")?.getAttribute("href")?.replace(/\/.+\//, "") // YouTube
?? document.querySelector(".ytp-title-channel-logo")?.getAttribute("href")?.replace(/https:\/.+\//, "") // YouTube Embed
?? document.querySelector("a > .channel-profile")?.parentElement?.getAttribute("href")?.replace(/\/.+\//, ""); // Invidious
- try {
- await utils.wait(() => !!getChannelID(), 6000, 20);
- } catch {
- if (Config.config.forceChannelCheck) {
- // treat as not whitelisted
- channelID = "";
-
- // Don't warn for Invidious embeds
- if (!(onInvidious && document.URL.includes("/embed/"))) {
- videoInfoFetchFailed("adblockerIssueWhitelist");
- }
+ if (channelID) {
+ channelIDInfo = {
+ status: ChannelIDStatus.Found,
+ id: channelID
+ }
+ } else {
+ channelIDInfo = {
+ status: ChannelIDStatus.Failed,
+ id: null
}
-
- return;
- }
-
- channelID = getChannelID();
- if (!channelID) {
- channelID = null;
return;
}
@@ -851,7 +829,7 @@ async function whitelistCheck() {
}
// check if the start of segments were missed
- if (Config.config.forceChannelCheck && sponsorTimes && sponsorTimes.length > 0) startSkipScheduleCheckingForStartSponsors();
+ if (Config.config.forceChannelCheck && sponsorTimes?.length > 0) startSkipScheduleCheckingForStartSponsors();
}
/**
diff --git a/src/popup.ts b/src/popup.ts
index 511b2d3e..168d035b 100644
--- a/src/popup.ts
+++ b/src/popup.ts
@@ -581,8 +581,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
{message: 'getChannelID'},
function(response) {
if (!response.channelID) {
- alert(chrome.i18n.getMessage("channelDataNotFound") + "\n\n" +
- chrome.i18n.getMessage("itCouldBeAdblockerIssue"));
+ alert(chrome.i18n.getMessage("channelDataNotFound") + " https://github.com/ajayyy/SponsorBlock/issues/753");
return;
}
diff --git a/src/types.ts b/src/types.ts
index 80424bd7..5267bad0 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -161,3 +161,14 @@ export type VideoID = string;
export type StorageChangesObject = { [key: string]: chrome.storage.StorageChange };
export type UnEncodedSegmentTimes = [string, SponsorTime[]][];
+
+export enum ChannelIDStatus {
+ Fetching,
+ Found,
+ Failed
+}
+
+export interface ChannelIDInfo {
+ id: string,
+ status: ChannelIDStatus
+} \ No newline at end of file