mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-12 22:47:18 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock
This commit is contained in:
@@ -65,8 +65,8 @@ const videosWithEventListeners: HTMLVideoElement[] = [];
|
||||
const controlsWithEventListeners: HTMLElement[] = []
|
||||
|
||||
// This misleading variable name will be fixed soon
|
||||
let onInvidious;
|
||||
let onMobileYouTube;
|
||||
let onInvidious: boolean;
|
||||
let onMobileYouTube: boolean;
|
||||
|
||||
//the video id of the last preview bar update
|
||||
let lastPreviewBarUpdate;
|
||||
@@ -100,7 +100,10 @@ const playerButtons: Record<string, {button: HTMLButtonElement, image: HTMLImage
|
||||
// Direct Links after the config is loaded
|
||||
utils.wait(() => Config.config !== null, 1000, 1).then(() => videoIDChange(getYouTubeVideoID(document)));
|
||||
// wait for hover preview to appear, and refresh attachments if ever found
|
||||
window.addEventListener("DOMContentLoaded", () => utils.waitForElement(".ytp-inline-preview-ui").then(() => refreshVideoAttachments()));
|
||||
window.addEventListener("DOMContentLoaded", () => {
|
||||
utils.waitForElement(".ytp-inline-preview-ui").then(() => refreshVideoAttachments())
|
||||
utils.waitForElement("[data-sessionlink='feature=player-title']").then(() => videoIDChange(getYouTubeVideoID(document)))
|
||||
});
|
||||
addPageListeners();
|
||||
addHotkeyListener();
|
||||
|
||||
@@ -117,6 +120,9 @@ let submissionNotice: SubmissionNotice = null;
|
||||
// If there is an advert playing (or about to be played), this is true
|
||||
let isAdPlaying = false;
|
||||
|
||||
// last response status
|
||||
let lastResponseStatus: number;
|
||||
|
||||
// Contains all of the functions and variables needed by the skip notice
|
||||
const skipNoticeContentContainer: ContentContainer = () => ({
|
||||
vote,
|
||||
@@ -163,6 +169,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
||||
//send the sponsor times along with if it's found
|
||||
sendResponse({
|
||||
found: sponsorDataFound,
|
||||
status: lastResponseStatus,
|
||||
sponsorTimes: sponsorTimes,
|
||||
onMobileYouTube
|
||||
});
|
||||
@@ -202,8 +209,12 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
||||
submitSponsorTimes();
|
||||
break;
|
||||
case "refreshSegments":
|
||||
// update video on refresh if videoID invalid
|
||||
if (!sponsorVideoID) videoIDChange(getYouTubeVideoID(document));
|
||||
// fetch segments
|
||||
sponsorsLookup(false).then(() => sendResponse({
|
||||
found: sponsorDataFound,
|
||||
status: lastResponseStatus,
|
||||
sponsorTimes: sponsorTimes,
|
||||
onMobileYouTube
|
||||
}));
|
||||
@@ -829,7 +840,6 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
||||
const hashParams = getHashParams();
|
||||
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
|
||||
|
||||
// Check for hashPrefix setting
|
||||
const hashPrefix = (await utils.getHash(sponsorVideoID, 1)).slice(0, 4) as VideoID & HashedValue;
|
||||
const response = await utils.asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
|
||||
categories,
|
||||
@@ -838,6 +848,9 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
||||
...extraRequestData
|
||||
});
|
||||
|
||||
// store last response status
|
||||
lastResponseStatus = response?.status;
|
||||
|
||||
if (response?.ok) {
|
||||
const recievedSegments: SponsorTime[] = JSON.parse(response.responseText)
|
||||
?.filter((video) => video.videoID === sponsorVideoID)
|
||||
@@ -905,8 +918,10 @@ async function sponsorsLookup(keepOldSubmissions = true) {
|
||||
//otherwise the listener can handle it
|
||||
updatePreviewBar();
|
||||
}
|
||||
} else if (response?.status === 404) {
|
||||
retryFetch();
|
||||
} else {
|
||||
if (lastResponseStatus === 404) {
|
||||
retryFetch();
|
||||
}
|
||||
}
|
||||
|
||||
if (Config.config.isVip) {
|
||||
|
||||
Reference in New Issue
Block a user