mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-15 07:57:09 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlock into chapters
This commit is contained in:
@@ -85,7 +85,7 @@ chrome.runtime.onMessage.addListener(function (request, _, callback) {
|
||||
case "unregisterContentScript":
|
||||
unregisterFirefoxContentScript(request.id)
|
||||
return false;
|
||||
case "tabs":
|
||||
case "tabs": {
|
||||
chrome.tabs.query({
|
||||
active: true,
|
||||
currentWindow: true
|
||||
@@ -93,11 +93,13 @@ chrome.runtime.onMessage.addListener(function (request, _, callback) {
|
||||
chrome.tabs.sendMessage(
|
||||
tabs[0].id,
|
||||
request.data,
|
||||
(response) => callback(response)
|
||||
(response) => {
|
||||
callback(response);
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
|
||||
this.guidelinesReminder?.close();
|
||||
this.noticeRef.current.close(true);
|
||||
|
||||
this.contentContainer().resetSponsorSubmissionNotice();
|
||||
this.contentContainer().resetSponsorSubmissionNotice(false);
|
||||
|
||||
this.props.closeListener();
|
||||
}
|
||||
|
||||
@@ -255,7 +255,21 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "keydown":
|
||||
document.dispatchEvent(new KeyboardEvent('keydown', {
|
||||
key: request.key,
|
||||
keyCode: request.keyCode,
|
||||
code: request.code,
|
||||
which: request.which,
|
||||
shiftKey: request.shiftKey,
|
||||
ctrlKey: request.ctrlKey,
|
||||
altKey: request.altKey,
|
||||
metaKey: request.metaKey
|
||||
}));
|
||||
break;
|
||||
}
|
||||
|
||||
sendResponse({});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -558,6 +572,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
||||
}
|
||||
}
|
||||
|
||||
const skipBuffer = 0.003;
|
||||
const skippingFunction = (forceVideoTime?: number) => {
|
||||
let forcedSkipTime: number = null;
|
||||
let forcedIncludeIntersectingSegments = false;
|
||||
@@ -567,7 +582,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
||||
forceVideoTime ||= Math.max(video.currentTime, getVirtualTime());
|
||||
|
||||
if ((shouldSkip(currentSkip) || sponsorTimesSubmitting?.some((segment) => segment.segment === currentSkip.segment))) {
|
||||
if (forceVideoTime >= skipTime[0] && forceVideoTime < skipTime[1]) {
|
||||
if (forceVideoTime >= skipTime[0] - skipBuffer && forceVideoTime < skipTime[1]) {
|
||||
skipToTime({
|
||||
v: video,
|
||||
skipTime,
|
||||
@@ -591,7 +606,7 @@ function startSponsorSchedule(includeIntersectingSegments = false, currentTime?:
|
||||
startSponsorSchedule(forcedIncludeIntersectingSegments, forcedSkipTime, forcedIncludeNonIntersectingSegments);
|
||||
};
|
||||
|
||||
if (timeUntilSponsor < 0.003) {
|
||||
if (timeUntilSponsor < skipBuffer) {
|
||||
skippingFunction(currentTime);
|
||||
} else {
|
||||
const delayTime = timeUntilSponsor * 1000 * (1 / video.playbackRate);
|
||||
@@ -1561,9 +1576,9 @@ async function createButtons(): Promise<void> {
|
||||
controls = await utils.wait(getControls).catch();
|
||||
|
||||
// Add button if does not already exist in html
|
||||
createButton("startSegment", "sponsorStart", () => closeInfoMenuAnd(() => startOrEndTimingNewSegment()), "PlayerStartIconSponsorBlocker.svg");
|
||||
createButton("cancelSegment", "sponsorCancel", () => closeInfoMenuAnd(() => cancelCreatingSegment()), "PlayerCancelSegmentIconSponsorBlocker.svg");
|
||||
createButton("delete", "clearTimes", () => closeInfoMenuAnd(() => clearSponsorTimes()), "PlayerDeleteIconSponsorBlocker.svg");
|
||||
createButton("startSegment", "sponsorStart", () => startOrEndTimingNewSegment(), "PlayerStartIconSponsorBlocker.svg");
|
||||
createButton("cancelSegment", "sponsorCancel", () => cancelCreatingSegment(), "PlayerCancelSegmentIconSponsorBlocker.svg");
|
||||
createButton("delete", "clearTimes", () => clearSponsorTimes(), "PlayerDeleteIconSponsorBlocker.svg");
|
||||
createButton("submit", "SubmitTimes", submitSponsorTimes, "PlayerUploadIconSponsorBlocker.svg");
|
||||
createButton("info", "openPopup", openInfoMenu, "PlayerInfoIconSponsorBlocker.svg");
|
||||
|
||||
@@ -1791,17 +1806,6 @@ function closeInfoMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The content script currently has no way to notify the info menu of changes. As a workaround we close it, thus making it query the new information when reopened.
|
||||
*
|
||||
* This function and all its uses should be removed when this issue is fixed.
|
||||
* */
|
||||
function closeInfoMenuAnd<T>(func: () => T): T {
|
||||
closeInfoMenu();
|
||||
|
||||
return func();
|
||||
}
|
||||
|
||||
function clearSponsorTimes() {
|
||||
const currentVideoID = sponsorVideoID;
|
||||
|
||||
@@ -1928,8 +1932,8 @@ function dontShowNoticeAgain() {
|
||||
/**
|
||||
* Helper method for the submission notice to clear itself when it closes
|
||||
*/
|
||||
function resetSponsorSubmissionNotice() {
|
||||
submissionNotice?.close();
|
||||
function resetSponsorSubmissionNotice(callRef = true) {
|
||||
submissionNotice?.close(callRef);
|
||||
submissionNotice = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,19 @@ interface ImportSegmentsMessage {
|
||||
data: string;
|
||||
}
|
||||
|
||||
export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoFoundMessage | SkipMessage | SubmitVoteMessage | HideSegmentMessage | CopyToClipboardMessage | ImportSegmentsMessage);
|
||||
interface KeyDownMessage {
|
||||
message: "keydown";
|
||||
key: string;
|
||||
keyCode: number;
|
||||
code: string;
|
||||
which: number;
|
||||
shiftKey: boolean;
|
||||
ctrlKey: boolean;
|
||||
altKey: boolean;
|
||||
metaKey: boolean;
|
||||
}
|
||||
|
||||
export type Message = BaseMessage & (DefaultMessage | BoolValueMessage | IsInfoFoundMessage | SkipMessage | SubmitVoteMessage | HideSegmentMessage | CopyToClipboardMessage | ImportSegmentsMessage | KeyDownMessage);
|
||||
|
||||
export interface IsInfoFoundMessageResponse {
|
||||
found: boolean;
|
||||
|
||||
58
src/popup.ts
58
src/popup.ts
@@ -1,7 +1,7 @@
|
||||
import Config from "./config";
|
||||
|
||||
import Utils from "./utils";
|
||||
import { SponsorTime, SponsorHideType, ActionType, SegmentUUID, SponsorSourceType } from "./types";
|
||||
import { SponsorTime, SponsorHideType, ActionType, SegmentUUID, SponsorSourceType, StorageChangesObject } from "./types";
|
||||
import { Message, MessageResponse, IsInfoFoundMessageResponse, ImportSegmentsResponse } from "./messageTypes";
|
||||
import { showDonationLink } from "./utils/configUtils";
|
||||
import { AnimationUtils } from "./utils/animationUtils";
|
||||
@@ -153,6 +153,9 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
getSegmentsFromContentScript(false);
|
||||
await utils.wait(() => Config.config !== null && allowPopup, 5000, 5);
|
||||
document.querySelector("body").style.removeProperty("visibility");
|
||||
if (!Config.configSyncListeners.includes(contentConfigUpdateListener)) {
|
||||
Config.configSyncListeners.push(contentConfigUpdateListener);
|
||||
}
|
||||
|
||||
PageElements.sbCloseButton.addEventListener("click", () => {
|
||||
sendTabMessage({
|
||||
@@ -204,6 +207,36 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
PageElements.refreshSegmentsButton.addEventListener("click", refreshSegments);
|
||||
PageElements.sbPopupIconCopyUserID.addEventListener("click", async () => copyToClipboard(await utils.getHash(Config.config.userID)));
|
||||
|
||||
// Forward click events
|
||||
if (window !== window.top) {
|
||||
document.addEventListener("keydown", (e) => {
|
||||
const target = e.target as HTMLElement;
|
||||
if (target.tagName === "INPUT"
|
||||
|| target.tagName === "TEXTAREA"
|
||||
|| e.key === "ArrowUp"
|
||||
|| e.key === "ArrowDown") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.key === " ") {
|
||||
// No scrolling
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
sendTabMessage({
|
||||
message: "keydown",
|
||||
key: e.key,
|
||||
keyCode: e.keyCode,
|
||||
code: e.code,
|
||||
which: e.which,
|
||||
shiftKey: e.shiftKey,
|
||||
ctrlKey: e.ctrlKey,
|
||||
altKey: e.altKey,
|
||||
metaKey: e.metaKey
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//show proper disable skipping button
|
||||
const disableSkipping = Config.config.disableSkipping;
|
||||
if (disableSkipping != undefined && disableSkipping) {
|
||||
@@ -761,6 +794,17 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
thanksForVotingText.innerText = message;
|
||||
}
|
||||
|
||||
function removeVoteMessage(UUID) {
|
||||
const voteButtonsContainer = document.getElementById("sponsorTimesVoteButtonsContainer" + UUID);
|
||||
voteButtonsContainer.style.display = "block";
|
||||
|
||||
const voteStatusContainer = document.getElementById("sponsorTimesVoteStatusContainer" + UUID);
|
||||
voteStatusContainer.style.display = "none";
|
||||
|
||||
const thanksForVotingText = document.getElementById("sponsorTimesThanksForVotingText" + UUID);
|
||||
thanksForVotingText.removeAttribute("innerText");
|
||||
}
|
||||
|
||||
function vote(type, UUID) {
|
||||
//add loading info
|
||||
addVoteMessage(chrome.i18n.getMessage("Loading"), UUID);
|
||||
@@ -784,6 +828,7 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
} else if (response.successType == -1) {
|
||||
addVoteMessage(GenericUtils.getErrorMessage(response.statusCode, response.responseText), UUID);
|
||||
}
|
||||
setTimeout(() => removeVoteMessage(UUID), 1500);
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -1018,7 +1063,16 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
|
||||
return (days > 0 ? days + chrome.i18n.getMessage("dayAbbreviation") + " " : "") + (hours > 0 ? hours + chrome.i18n.getMessage("hourAbbreviation") + " " : "") + (minutes % 60).toFixed(1);
|
||||
}
|
||||
|
||||
//end of function
|
||||
function contentConfigUpdateListener(changes: StorageChangesObject) {
|
||||
for (const key in changes) {
|
||||
switch(key) {
|
||||
case "unsubmittedSegments":
|
||||
sponsorTimes = Config.config.unsubmittedSegments[currentVideoID] ?? [];
|
||||
updateSegmentEditingUI();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
runThePopup();
|
||||
|
||||
@@ -35,7 +35,7 @@ class SubmissionNotice {
|
||||
contentContainer={contentContainer}
|
||||
callback={callback}
|
||||
ref={this.noticeRef}
|
||||
closeListener={() => this.close()} />,
|
||||
closeListener={() => this.close(false)} />,
|
||||
this.noticeElement
|
||||
);
|
||||
}
|
||||
@@ -44,7 +44,8 @@ class SubmissionNotice {
|
||||
this.noticeRef.current.forceUpdate();
|
||||
}
|
||||
|
||||
close(): void {
|
||||
close(callRef = true): void {
|
||||
if (callRef) this.noticeRef.current.cancel();
|
||||
ReactDOM.unmountComponentAtNode(this.noticeElement);
|
||||
|
||||
this.noticeElement.remove();
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface ContentContainer {
|
||||
updatePreviewBar: () => void,
|
||||
onMobileYouTube: boolean,
|
||||
sponsorSubmissionNotice: SubmissionNotice,
|
||||
resetSponsorSubmissionNotice: () => void,
|
||||
resetSponsorSubmissionNotice: (callRef?: boolean) => void,
|
||||
updateEditButtonsOnPlayer: () => void,
|
||||
previewTime: (time: number, unpause?: boolean) => void,
|
||||
videoInfo: VideoInfo,
|
||||
|
||||
Reference in New Issue
Block a user