diff --git a/src/background.ts b/src/background.ts index a5a70219..6bb21d1b 100644 --- a/src/background.ts +++ b/src/background.ts @@ -43,7 +43,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) { chrome.tabs.create({url: chrome.runtime.getURL(request.url)}); return false; case "submitVote": - submitVote(request.type, request.UUID, request.category).then(callback); + submitVote(request.type, request.UUID, request.category, request.videoID).then(callback); //this allows the callback to be called later return true; @@ -214,7 +214,7 @@ async function unregisterFirefoxContentScript(id: string) { } } -async function submitVote(type: number, UUID: string, category: string) { +async function submitVote(type: number, UUID: string, category: string, videoID: string) { let userID = Config.config.userID; if (userID == undefined || userID === "undefined") { @@ -226,7 +226,7 @@ async function submitVote(type: number, UUID: string, category: string) { const typeSection = (type !== undefined) ? "&type=" + type : "&category=" + category; try { - const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection); + const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&videoID=" + videoID + "&userID=" + userID + typeSection); if (response.ok) { return { diff --git a/src/content.ts b/src/content.ts index 0b075450..0eb01389 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1400,7 +1400,7 @@ function updatePreviewBar(): void { showLarger: segment.actionType === ActionType.Poi, description: segment.description, source: segment.source, - requiredSegment: requiredSegment && (segment.UUID === requiredSegment || segment.UUID?.startsWith(requiredSegment)), + requiredSegment: requiredSegment && (segment.UUID === requiredSegment || segment.UUID?.startsWith(requiredSegment) || requiredSegment.startsWith(segment.UUID)), selectedSegment: selectedSegment && segment.UUID === selectedSegment }); }); @@ -1678,7 +1678,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped: counted = true; } - if (fullSkip) asyncRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + segment.UUID); + if (fullSkip) asyncRequestToServer("POST", "/api/viewedVideoSponsorTime?UUID=" + segment.UUID + "&videoID=" + getVideoID()); } } } @@ -2268,7 +2268,8 @@ async function voteAsync(type: number, UUID: SegmentUUID, category?: Category): message: "submitVote", type: type, UUID: UUID, - category: category + category: category, + videoID: getVideoID() }, (response) => { if (response.successType === 1) { // Change the sponsor locally diff --git a/src/utils.ts b/src/utils.ts index c1887119..6c646a7b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,7 @@ import { getHash, HashedValue } from "../maze-utils/src/hash"; import { waitFor } from "../maze-utils/src"; import { findValidElementFromSelector } from "../maze-utils/src/dom"; import { isSafari } from "../maze-utils/src/config"; +import { asyncRequestToServer } from "./utils/requests"; export default class Utils { @@ -198,7 +199,7 @@ export default class Utils { getSponsorIndexFromUUID(sponsorTimes: SponsorTime[], UUID: string): number { for (let i = 0; i < sponsorTimes.length; i++) { - if (sponsorTimes[i].UUID === UUID) { + if (sponsorTimes[i].UUID.startsWith(UUID) || UUID.startsWith(sponsorTimes[i].UUID)) { return i; } } @@ -282,6 +283,17 @@ export default class Utils { if ((chrome.extension.inIncognitoContext && !Config.config.trackDownvotesInPrivate) || !Config.config.trackDownvotes) return; + if (segmentUUID.length < 60) { + const segmentIDData = await asyncRequestToServer("GET", "/api/segmentID", { + UUID: segmentUUID, + videoID + }); + + if (segmentIDData.ok && segmentIDData.responseText) { + segmentUUID = segmentIDData.responseText; + } + } + const hashedVideoID = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue; const UUIDHash = await getHash(segmentUUID, 1); diff --git a/src/utils/segmentData.ts b/src/utils/segmentData.ts index 1c2e631a..5741730d 100644 --- a/src/utils/segmentData.ts +++ b/src/utils/segmentData.ts @@ -48,11 +48,13 @@ async function fetchSegmentsForVideo(videoID: VideoID): Promise const extraRequestData: Record = {}; const hashParams = getHashParams(); if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment; - + const hashPrefix = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue; + const hasDownvotedSegments = !!Config.local.downvotedSegments[hashPrefix]; const response = await asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, { categories: CompileConfig.categoryList, actionTypes: ActionTypes, + trimUUIDs: hasDownvotedSegments ? null : 5, ...extraRequestData }, { "X-CLIENT-NAME": `${chrome.runtime.id}/v${chrome.runtime.getManifest().version}`