diff --git a/apps/browser-extension/entrypoints/content/twitter.ts b/apps/browser-extension/entrypoints/content/twitter.ts index 875f4bab3..29befa0ed 100644 --- a/apps/browser-extension/entrypoints/content/twitter.ts +++ b/apps/browser-extension/entrypoints/content/twitter.ts @@ -4,6 +4,7 @@ import { MESSAGE_TYPES, POSTHOG_EVENT_KEY, STORAGE_KEYS, + TWITTER_BOOKMARKS_PATH, UI_CONFIG, } from "../../utils/constants" import { trackEvent } from "../../utils/posthog" @@ -86,9 +87,9 @@ export async function initializeTwitter() { return } - if (window.location.pathname === "/i/bookmarks") { + if (window.location.pathname === TWITTER_BOOKMARKS_PATH) { setTimeout(async () => { - if (window.location.pathname === "/i/bookmarks") { + if (window.location.pathname === TWITTER_BOOKMARKS_PATH) { await handleBookmarksPageLoad() } }, 2000) @@ -102,7 +103,7 @@ export async function initializeTwitter() { * Handle what to show when user lands on bookmarks page */ async function handleBookmarksPageLoad() { - if (window.location.pathname !== "/i/bookmarks") { + if (window.location.pathname !== TWITTER_BOOKMARKS_PATH) { return } @@ -589,7 +590,7 @@ export async function handleTwitterNavigation() { return } - if (window.location.pathname === "/i/bookmarks") { + if (window.location.pathname === TWITTER_BOOKMARKS_PATH) { addTwitterImportButtonForFolders() await handleBookmarksPageLoad() } else { @@ -601,7 +602,7 @@ export async function handleTwitterNavigation() { * Adds import buttons to bookmark folders */ function addTwitterImportButtonForFolders() { - if (window.location.pathname !== "/i/bookmarks") { + if (window.location.pathname !== TWITTER_BOOKMARKS_PATH) { return } diff --git a/apps/browser-extension/entrypoints/popup/App.tsx b/apps/browser-extension/entrypoints/popup/App.tsx index ace10a03c..9fb0a943b 100644 --- a/apps/browser-extension/entrypoints/popup/App.tsx +++ b/apps/browser-extension/entrypoints/popup/App.tsx @@ -6,6 +6,8 @@ import { getSupermemoryLoginUrl, MESSAGE_TYPES, STORAGE_KEYS, + TWITTER_BOOKMARKS_PATH, + TWITTER_BOOKMARKS_PAGE_URL, UI_CONFIG, } from "../../utils/constants" import { @@ -484,7 +486,7 @@ function App() { } const handleTwitterBookmarksImport = async () => { - const targetUrl = "https://x.com/i/bookmarks" + const targetUrl = TWITTER_BOOKMARKS_PAGE_URL try { const [activeTab] = await chrome.tabs.query({ @@ -492,9 +494,10 @@ function App() { currentWindow: true, }) - const isOnBookmarksPage = - activeTab?.url?.includes("x.com/i/bookmarks") || - activeTab?.url?.includes("twitter.com/i/bookmarks") + const activePathname = activeTab?.url + ? new URL(activeTab.url).pathname + : "" + const isOnBookmarksPage = activePathname === TWITTER_BOOKMARKS_PATH if (isOnBookmarksPage && activeTab?.id) { try { diff --git a/apps/browser-extension/utils/constants.ts b/apps/browser-extension/utils/constants.ts index c5fe83473..4b3aa37c0 100644 --- a/apps/browser-extension/utils/constants.ts +++ b/apps/browser-extension/utils/constants.ts @@ -76,6 +76,9 @@ export const DOMAINS = { SUPERMEMORY: ["localhost", "supermemory.ai", "app.supermemory.ai"], } as const +export const TWITTER_BOOKMARKS_PATH = "/i/history" +export const TWITTER_BOOKMARKS_PAGE_URL = `https://x.com${TWITTER_BOOKMARKS_PATH}` + /** * Container Tags */