Skip to content

Commit

Permalink
Merge SB v5.5.5 into bili
Browse files Browse the repository at this point in the history
commit 9d04482d190dcc54ce62d6be97cb2f6e6950fc5b
Author: Ajay <[email protected]>
Date:   Tue Feb 13 22:35:44 2024 -0500

    bump version

commit 7c661f8e67488ded17a406940a9bec0f948bd154
Author: Ajay <[email protected]>
Date:   Tue Feb 13 22:33:11 2024 -0500

    update translations

commit 0b7a2fd197a2b961f3a7a2c00819f2c4022bbcc0
Author: Ajay <[email protected]>
Date:   Tue Feb 13 22:32:37 2024 -0500

    Fix adding custom Invidious instances on Firefox

    Fixes #815

commit 3382d8a5006430d248763dbaa93b2183367a5f76
Author: Ajay <[email protected]>
Date:   Tue Feb 13 21:52:10 2024 -0500

    Fix chapter names not appearing

commit 5d871d5fe76217e3f962ec464bb7d8a84d426056
Author: Ajay <[email protected]>
Date:   Tue Feb 13 21:32:23 2024 -0500

    Fix hidden mute segments sometimes still muting

commit b7c5737a953959d1f31e881aa5ebe12f55dffb67
Merge: e0fe0fad 0cca1c35
Author: Ajay Ramachandran <[email protected]>
Date:   Fri Feb 2 19:17:14 2024 -0500

    Merge pull request #1967 from HanYaodong/dev

    Fix license info in README

commit 0cca1c3566862bcefb7c82eaf6f2b22008ed6404
Author: HanYaodong <[email protected]>
Date:   Fri Feb 2 19:31:22 2024 +0800

    Fix license info in README

commit e0fe0fad671364cfb94df3bde5a9a17b23b25003
Author: Ajay <[email protected]>
Date:   Thu Feb 1 13:31:19 2024 -0500

    Don't close submission menu if submission didn't go through

    Fxies submission menu closing for warning about previewing a segment

commit c0bc068a18e0423f69a987c5bcf37bd5b42f1ad7
Author: Ajay <[email protected]>
Date:   Wed Jan 31 19:06:16 2024 -0500

    Handle exceptions for voting

    Maybe fixes #1961

commit 7cb413db15c89e678785f1ded3f9fdf2ff07f47b
Author: Ajay <[email protected]>
Date:   Wed Jan 31 18:58:06 2024 -0500

    Don't display preview bar while scrubbing on mobile

    Should help with #1962
  • Loading branch information
hanydd committed Feb 16, 2024
1 parent 298c3ce commit abe14bf
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 31 deletions.
50 changes: 29 additions & 21 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ async function registerFirefoxContentScript(options: Registration) {
ids: [options.id]
}).catch(() => []);

if (existingRegistrations.length > 0
&& existingRegistrations[0].matches.every((match) => options.matches.includes(match))) {
if (existingRegistrations && existingRegistrations.length > 0
&& options.matches.every((match) => existingRegistrations[0].matches.includes(match))) {
// No need to register another script, already registered
return;
}
Expand Down Expand Up @@ -207,27 +207,35 @@ async function submitVote(type: number, UUID: string, category: string) {

const typeSection = (type !== undefined) ? "&type=" + type : "&category=" + category;

//publish this vote
const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection);

if (response.ok) {
return {
successType: 1,
responseText: await response.text()
};
} else if (response.status == 405) {
//duplicate vote
return {
successType: 0,
statusCode: response.status,
responseText: await response.text()
};
} else {
//error while connect
try {
const response = await asyncRequestToServer("POST", "/api/voteOnSponsorTime?UUID=" + UUID + "&userID=" + userID + typeSection);

if (response.ok) {
return {
successType: 1,
responseText: await response.text()
};
} else if (response.status == 405) {
//duplicate vote
return {
successType: 0,
statusCode: response.status,
responseText: await response.text()
};
} else {
//error while connect
return {
successType: -1,
statusCode: response.status,
responseText: await response.text()
};
}
} catch (e) {
console.error(e);
return {
successType: -1,
statusCode: response.status,
responseText: await response.text()
statusCode: -1,
responseText: ""
};
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/components/SubmissionNoticeComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface SubmissionNoticeProps {
// Contains functions and variables from the content script needed by the skip notice
contentContainer: ContentContainer;

callback: () => unknown;
callback: () => Promise<boolean>;

closeListener: () => void;
}
Expand Down Expand Up @@ -239,9 +239,11 @@ class SubmissionNoticeComponent extends React.Component<SubmissionNoticeProps, S
}
}

this.props.callback();

this.cancel();
this.props.callback().then((success) => {
if (success) {
this.cancel();
}
});
}

sortSegments(): void {
Expand Down
15 changes: 11 additions & 4 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,7 @@ function getVirtualTime(): number {

function inMuteSegment(currentTime: number, includeOverlap: boolean): boolean {
const checkFunction = (segment) => segment.actionType === ActionType.Mute
&& segment.hidden === SponsorHideType.Visible
&& segment.segment[0] <= currentTime
&& (segment.segment[1] > currentTime || (includeOverlap && segment.segment[1] + 0.02 > currentTime));
return sponsorTimes?.some(checkFunction) || sponsorTimesSubmitting.some(checkFunction);
Expand Down Expand Up @@ -2123,21 +2124,21 @@ function submitSegments() {

//send the message to the background js
//called after all the checks have been made that it's okay to do so
async function sendSubmitMessage() {
async function sendSubmitMessage(): Promise<boolean> {
// check if all segments are full video
const onlyFullVideo = sponsorTimesSubmitting.every((segment) => segment.actionType === ActionType.Full);
// Block if submitting on a running livestream or premiere
if (!onlyFullVideo && (getIsLivePremiere() || isVisible(document.querySelector(".ytp-live-badge")))) {
alert(chrome.i18n.getMessage("liveOrPremiere"));
return;
return false;
}

if (!previewedSegment
&& !sponsorTimesSubmitting.every((segment) =>
[ActionType.Full, ActionType.Poi].includes(segment.actionType)
|| segment.segment[1] >= getVideo()?.duration)) {
alert(`${chrome.i18n.getMessage("previewSegmentRequired")} ${keybindToString(Config.config.previewKeybind)}`);
return;
return false;
}

// Add loading animation
Expand All @@ -2163,7 +2164,7 @@ async function sendSubmitMessage() {
const confirmShort = chrome.i18n.getMessage("shortCheck") + "\n\n" +
getSegmentsMessage(sponsorTimesSubmitting);

if(!confirm(confirmShort)) return;
if(!confirm(confirmShort)) return false;
}
}
}
Expand Down Expand Up @@ -2213,6 +2214,8 @@ async function sendSubmitMessage() {
if (fullVideoSegment) {
categoryPill?.setSegment(fullVideoSegment);
}

return true;
} else {
// Show that the upload failed
playerButtons.submit.button.style.animation = "unset";
Expand All @@ -2224,6 +2227,8 @@ async function sendSubmitMessage() {
alert(getErrorMessage(response.status, response.responseText));
}
}

return false;
}

//get the message that visually displays the video times
Expand All @@ -2249,6 +2254,8 @@ function getSegmentsMessage(sponsorTimes: SponsorTime[]): string {
}

function updateActiveSegment(currentTime: number): void {
previewBar?.updateChapterText(sponsorTimes, sponsorTimesSubmitting, currentTime);

chrome.runtime.sendMessage({
message: "time",
time: currentTime
Expand Down
4 changes: 2 additions & 2 deletions src/render/SubmissionNotice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ class SubmissionNotice {
// Contains functions and variables from the content script needed by the skip notice
contentContainer: () => unknown;

callback: () => unknown;
callback: () => Promise<boolean>;

noticeRef: React.MutableRefObject<SubmissionNoticeComponent>;

noticeElement: HTMLDivElement;

root: Root;

constructor(contentContainer: ContentContainer, callback: () => unknown) {
constructor(contentContainer: ContentContainer, callback: () => Promise<boolean>) {
this.noticeRef = React.createRef();

this.contentContainer = contentContainer;
Expand Down

0 comments on commit abe14bf

Please sign in to comment.