Skip to content

Commit

Permalink
add isFirefox function
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Dec 5, 2024
1 parent 1cc0842 commit 65d37a8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/components/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as React from "react";
import { createRoot, Root } from "react-dom/client";
import { isFirefox } from "../utils/";
import { ButtonListener } from "./component-types";
import { isFirefoxOrSafari } from "../utils/";
import { isSafari } from "../config/config";

export interface TooltipProps {
text?: string;
Expand Down Expand Up @@ -67,7 +66,7 @@ export class GenericTooltip {
if (props.positionRealtive) this.container.style.position = "relative";
if (props.containerAbsolute) this.container.style.position = "absolute";
if (props.center) {
if (isFirefoxOrSafari() && !isSafari()) {
if (isFirefox()) {
this.container.style.width = "-moz-available";
} else {
this.container.style.width = "-webkit-fill-available";
Expand Down
7 changes: 2 additions & 5 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFirefoxOrSafari } from "../utils/";
import { isFirefox } from "../utils/";

export interface SyncStorage {
invidiousInstances: string[];
Expand Down Expand Up @@ -177,7 +177,7 @@ export class ProtoConfig<T extends SyncStorage, U extends LocalStorage> {
`${chrome.i18n.getMessage("syncDisabledWarning")}${
this.inDeArrow ? `\n\n${chrome.i18n.getMessage("syncDisabledWarningDeArrow")}` : ``
}${
isFirefoxOrSafari() && !isSafari()
isFirefox()
? `\n\n${chrome.i18n.getMessage("syncDisabledFirefoxSuggestions")}`
: ``
}`
Expand Down Expand Up @@ -234,9 +234,6 @@ export class ProtoConfig<T extends SyncStorage, U extends LocalStorage> {
}
}

export function isSafari(): boolean {
return typeof navigator !== "undefined" && navigator.vendor === "Apple Computer, Inc.";
}

export function keybindEquals(first: Keybind, second: Keybind): boolean {
if (
Expand Down
10 changes: 5 additions & 5 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SkipNoticeComponent from "./components/SkipNoticeComponent";
import Config from "./config";
import { isSafari, Keybind, keybindEquals, keybindToString, StorageChangesObject } from "./config/config";
import { Keybind, keybindEquals, keybindToString, StorageChangesObject } from "./config/config";
import PreviewBar, { PreviewBarSegment } from "./js-components/previewBar";
import { SkipButtonControlBar } from "./js-components/skipButtonControlBar";
import { Message, MessageResponse, VoteResponse } from "./messageTypes";
Expand Down Expand Up @@ -35,7 +35,7 @@ import {
VideoInfo,
} from "./types";
import Utils from "./utils";
import { isFirefoxOrSafari, sleep, waitFor } from "./utils/";
import { isFirefox, isFirefoxOrSafari, isSafari, sleep, waitFor } from "./utils/";
import { AnimationUtils } from "./utils/animationUtils";
import { addCleanupListener, cleanPage } from "./utils/cleanup";
import { defaultPreviewTime } from "./utils/constants";
Expand Down Expand Up @@ -705,9 +705,9 @@ async function startSponsorSchedule(
await skippingFunction(currentTime);
} else {
let delayTime = timeUntilSponsor * 1000 * (1 / getVideo().playbackRate);
if (delayTime < (isFirefoxOrSafari() && !isSafari() ? 750 : 300)) {
if (delayTime < (isFirefox() ? 750 : 300)) {
let forceStartIntervalTime: number | null = null;
if (isFirefoxOrSafari() && !isSafari() && delayTime > 300) {
if (isFirefox() && delayTime > 300) {
forceStartIntervalTime = await waitForNextTimeChange();
}

Expand Down Expand Up @@ -755,7 +755,7 @@ async function startSponsorSchedule(
} else {
logDebug(`Starting timeout to skip ${getVideo().currentTime} to skip at ${skipTime[0]}`);

const offset = isFirefoxOrSafari() && !isSafari() ? 600 : 150;
const offset = isFirefox() ? 600 : 150;
// Schedule for right before to be more precise than normal timeout
currentSkipSchedule = setTimeout(skippingFunction, Math.max(0, delayTime - offset));
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
SponsorTime,
VideoID,
} from "./types";
import { isSafari } from "./utils/index";

import { isSafari } from "./config/config";
import { findValidElementFromSelector } from "./utils/dom";
import { getHash, getVideoIDHash, HashedValue } from "./utils/hash";

Expand Down
8 changes: 8 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ export function isFirefoxOrSafari(): boolean {
// @ts-ignore
return typeof browser !== "undefined";
}

export function isSafari(): boolean {
return typeof navigator !== "undefined" && navigator.vendor === "Apple Computer, Inc.";
}

export function isFirefox(): boolean {
return isFirefoxOrSafari() && !isSafari();
}

0 comments on commit 65d37a8

Please sign in to comment.