mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-06 19:47:04 +03:00
Add support for partial segment IDs
This commit is contained in:
@@ -43,7 +43,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
|
|||||||
chrome.tabs.create({url: chrome.runtime.getURL(request.url)});
|
chrome.tabs.create({url: chrome.runtime.getURL(request.url)});
|
||||||
return false;
|
return false;
|
||||||
case "submitVote":
|
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
|
//this allows the callback to be called later
|
||||||
return true;
|
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;
|
let userID = Config.config.userID;
|
||||||
|
|
||||||
if (userID == undefined || userID === "undefined") {
|
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;
|
const typeSection = (type !== undefined) ? "&type=" + type : "&category=" + category;
|
||||||
|
|
||||||
try {
|
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) {
|
if (response.ok) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1400,7 +1400,7 @@ function updatePreviewBar(): void {
|
|||||||
showLarger: segment.actionType === ActionType.Poi,
|
showLarger: segment.actionType === ActionType.Poi,
|
||||||
description: segment.description,
|
description: segment.description,
|
||||||
source: segment.source,
|
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
|
selectedSegment: selectedSegment && segment.UUID === selectedSegment
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1678,7 +1678,7 @@ function sendTelemetryAndCount(skippingSegments: SponsorTime[], secondsSkipped:
|
|||||||
counted = true;
|
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",
|
message: "submitVote",
|
||||||
type: type,
|
type: type,
|
||||||
UUID: UUID,
|
UUID: UUID,
|
||||||
category: category
|
category: category,
|
||||||
|
videoID: getVideoID()
|
||||||
}, (response) => {
|
}, (response) => {
|
||||||
if (response.successType === 1) {
|
if (response.successType === 1) {
|
||||||
// Change the sponsor locally
|
// Change the sponsor locally
|
||||||
|
|||||||
14
src/utils.ts
14
src/utils.ts
@@ -5,6 +5,7 @@ import { getHash, HashedValue } from "../maze-utils/src/hash";
|
|||||||
import { waitFor } from "../maze-utils/src";
|
import { waitFor } from "../maze-utils/src";
|
||||||
import { findValidElementFromSelector } from "../maze-utils/src/dom";
|
import { findValidElementFromSelector } from "../maze-utils/src/dom";
|
||||||
import { isSafari } from "../maze-utils/src/config";
|
import { isSafari } from "../maze-utils/src/config";
|
||||||
|
import { asyncRequestToServer } from "./utils/requests";
|
||||||
|
|
||||||
export default class Utils {
|
export default class Utils {
|
||||||
|
|
||||||
@@ -198,7 +199,7 @@ export default class Utils {
|
|||||||
|
|
||||||
getSponsorIndexFromUUID(sponsorTimes: SponsorTime[], UUID: string): number {
|
getSponsorIndexFromUUID(sponsorTimes: SponsorTime[], UUID: string): number {
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
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;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -282,6 +283,17 @@ export default class Utils {
|
|||||||
if ((chrome.extension.inIncognitoContext && !Config.config.trackDownvotesInPrivate)
|
if ((chrome.extension.inIncognitoContext && !Config.config.trackDownvotesInPrivate)
|
||||||
|| !Config.config.trackDownvotes) return;
|
|| !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 hashedVideoID = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue;
|
||||||
const UUIDHash = await getHash(segmentUUID, 1);
|
const UUIDHash = await getHash(segmentUUID, 1);
|
||||||
|
|
||||||
|
|||||||
@@ -50,9 +50,11 @@ async function fetchSegmentsForVideo(videoID: VideoID): Promise<SegmentResponse>
|
|||||||
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
|
if (hashParams.requiredSegment) extraRequestData.requiredSegment = hashParams.requiredSegment;
|
||||||
|
|
||||||
const hashPrefix = (await getHash(videoID, 1)).slice(0, 4) as VideoID & HashedValue;
|
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, {
|
const response = await asyncRequestToServer('GET', "/api/skipSegments/" + hashPrefix, {
|
||||||
categories: CompileConfig.categoryList,
|
categories: CompileConfig.categoryList,
|
||||||
actionTypes: ActionTypes,
|
actionTypes: ActionTypes,
|
||||||
|
trimUUIDs: hasDownvotedSegments ? null : 5,
|
||||||
...extraRequestData
|
...extraRequestData
|
||||||
}, {
|
}, {
|
||||||
"X-CLIENT-NAME": `${chrome.runtime.id}/v${chrome.runtime.getManifest().version}`
|
"X-CLIENT-NAME": `${chrome.runtime.id}/v${chrome.runtime.getManifest().version}`
|
||||||
|
|||||||
Reference in New Issue
Block a user