diff --git a/src/constants.ts b/src/constants.ts index cdbaeaf7..76c211d5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,15 +1,19 @@ // OpenSauced constants -export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env.VITE_OPEN_SAUCED_INSIGHTS_DOMAIN; -export const OPEN_SAUCED_API_ENDPOINT = import.meta.env.VITE_OPEN_SAUCED_API_ENDPOINT; -export const SUPABASE_LOGIN_URL = `https://${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/`; +export const OPEN_SAUCED_INSIGHTS_DOMAIN = import.meta.env + .VITE_OPEN_SAUCED_INSIGHTS_DOMAIN; +export const OPEN_SAUCED_API_ENDPOINT = import.meta.env + .VITE_OPEN_SAUCED_API_ENDPOINT; +export const SUPABASE_LOGIN_URL = `https://${ + import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID +}.supabase.co/auth/v1/authorize?provider=github&redirect_to=https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/`; - -export const SUPABASE_AUTH_COOKIE_NAME = `sb-${import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID}-auth-token`; +export const SUPABASE_AUTH_COOKIE_NAME = `sb-${ + import.meta.env.VITE_OPEN_SAUCED_SUPABASE_ID +}-auth-token`; export const OPEN_SAUCED_AUTH_TOKEN_KEY = "os-access-token"; export const OPEN_SAUCED_OPTED_LOG_OUT_KEY = "opted-log-out"; export const AI_PR_DESCRIPTION_CONFIG_KEY = "ai-pr-description-config"; - export const OPEN_SAUCED_USERS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/users`; export const OPEN_SAUCED_REPOS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/repos`; export const OPEN_SAUCED_SESSION_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/auth/session`; @@ -24,21 +28,37 @@ export const OPEN_SAUCED_HIGHLIGHTS_LIST_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT} export const OPEN_SAUCED_EMOJIS_ENDPOINT = `${OPEN_SAUCED_API_ENDPOINT}/emojis`; // GitHub constants/selectors -export const GITHUB_PROFILE_MENU_SELECTOR = ".p-nickname.vcard-username.d-block"; -export const GITHUB_PROFILE_EDIT_MENU_SELECTOR = "button.js-profile-editable-edit-button"; -export const GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR = ".p-note.user-profile-bio.mb-3.js-user-profile-bio.f4"; -export const GITHUB_PR_COMMENT_HEADER_SELECTOR = "timeline-comment-header clearfix d-flex"; -export const GITHUB_NEW_PR_COMMENT_EDITOR_SELECTOR = "flex-nowrap d-none d-md-inline-block mr-md-0 mr-3"; -export const GITHUB_PR_COMMENT_EDITOR_SELECTOR = "flex-nowrap d-inline-block mr-3"; -export const GITHUB_REVIEW_SUGGESTION_SELECTOR = "js-suggestion-button-placeholder"; +export const GITHUB_PROFILE_MENU_SELECTOR = + ".p-nickname.vcard-username.d-block"; +export const GITHUB_PROFILE_EDIT_MENU_SELECTOR = + "button.js-profile-editable-edit-button"; +export const GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR = + ".p-note user-profile-bio mb-3 js-user-profile-bio f4"; +export const GITHUB_PROFILE_USER_PROFILE_EDITABLE_AREA_SELECTOR = + "js-profile-editable-area d-flex flex-column d-md-block"; +export const GITHUB_PR_COMMENT_HEADER_SELECTOR = + "timeline-comment-header clearfix d-flex"; +export const GITHUB_NEW_PR_COMMENT_EDITOR_SELECTOR = + "flex-nowrap d-none d-md-inline-block mr-md-0 mr-3"; +export const GITHUB_PR_COMMENT_EDITOR_SELECTOR = + "flex-nowrap d-inline-block mr-3"; +export const GITHUB_REVIEW_SUGGESTION_SELECTOR = + "js-suggestion-button-placeholder"; export const GITHUB_REPO_ACTIONS_SELECTOR = ".pagehead-actions"; export const GITHUB_PR_COMMENT_TEXT_AREA_SELECTOR = "pull_request[body]"; export const GITHUB_PR_SUGGESTION_TEXT_AREA_SELECTOR = "[name='comment[body]']"; -export const GITHUB_PR_BASE_BRANCH_SELECTOR = "css-truncate css-truncate-target"; +export const GITHUB_PR_BASE_BRANCH_SELECTOR = + "css-truncate css-truncate-target"; // External Links export const EXTERNAL_RESOURCES = [ - { link: "https://docs.opensauced.pizza/chrome-extension/introduction-to-the-chrome-extension/", key: "Docs" }, - { link: "https://github.com/open-sauced/ai/issues", key: "Issues" }, - { link: "https://github.com/orgs/open-sauced/discussions", key: "Discussions" }, + { + link: "https://docs.opensauced.pizza/chrome-extension/introduction-to-the-chrome-extension/", + key: "Docs", + }, + { link: "https://github.com/open-sauced/ai/issues", key: "Issues" }, + { + link: "https://github.com/orgs/open-sauced/discussions", + key: "Discussions", + }, ]; diff --git a/src/content-scripts/components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton.ts b/src/content-scripts/components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton.ts index 2e7f9a24..e1aeb79e 100644 --- a/src/content-scripts/components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton.ts +++ b/src/content-scripts/components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton.ts @@ -4,14 +4,14 @@ import { createHtmlElement } from "../../../utils/createHtmlElement"; import { OPEN_SAUCED_INSIGHTS_DOMAIN } from "../../../constants"; export const ViewOnOpenSaucedButton = (username: string) => { - const viewOnOpenSaucedButton = createHtmlElement("a", { - id: "view-on-opensauced-button", - href: `https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/user/${username}/contributions`, - className: - "inline-block mt-4 text-black bg-gh-white dark:bg-gh-gray dark:text-white rounded-md p-2 text-sm font-semibold text-center select-none w-full border hover:shadow-button hover:no-underline", - target: "_blank", - rel: "noopener noreferrer", - innerHTML: ` + const viewOnOpenSaucedButton = createHtmlElement("a", { + id: "view-on-opensauced-button", + href: `https://${OPEN_SAUCED_INSIGHTS_DOMAIN}/user/${username}/contributions`, + className: + "inline-block my-4 text-black bg-gh-white dark:bg-gh-gray dark:text-white rounded-md p-2 text-sm font-semibold text-center select-none w-full border hover:shadow-button hover:no-underline", + target: "_blank", + rel: "noopener noreferrer", + innerHTML: ` { /> View On OpenSauced `, - }); + }); - return viewOnOpenSaucedButton; + return viewOnOpenSaucedButton; }; diff --git a/src/utils/dom-utils/viewOnOpenSauced.ts b/src/utils/dom-utils/viewOnOpenSauced.ts index 8653e877..ae4d93fe 100644 --- a/src/utils/dom-utils/viewOnOpenSauced.ts +++ b/src/utils/dom-utils/viewOnOpenSauced.ts @@ -1,21 +1,24 @@ import { - GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR, - GITHUB_PROFILE_EDIT_MENU_SELECTOR, + GITHUB_PROFILE_USER_PROFILE_EDITABLE_AREA_SELECTOR, + GITHUB_PROFILE_EDIT_MENU_SELECTOR, } from "../../constants"; import { ViewOnOpenSaucedButton } from "../../content-scripts/components/ViewOnOpenSaucedButton/ViewOnOpenSaucedButton"; const injectViewOnOpenSaucedButton = (username: string) => { - if (document.getElementById("view-on-opensauced-button")) { - return; - } + if (document.getElementById("view-on-opensauced-button")) { + return; + } - const viewOnOpenSaucedButton = ViewOnOpenSaucedButton(username); + const viewOnOpenSaucedButton = ViewOnOpenSaucedButton(username); - const userBio = document.querySelector( - `${GITHUB_PROFILE_USER_PROFILE_BIO_SELECTOR}, ${GITHUB_PROFILE_EDIT_MENU_SELECTOR}`, - ); - - userBio?.append(viewOnOpenSaucedButton); + const userBio = document.querySelector( + `${GITHUB_PROFILE_USER_PROFILE_EDITABLE_AREA_SELECTOR} + , ${GITHUB_PROFILE_EDIT_MENU_SELECTOR}` + ); + const user = document.getElementsByClassName( + "js-profile-editable-area d-flex flex-column d-md-block" + ); + user[0]?.parentNode.insertBefore(viewOnOpenSaucedButton, user[0]); }; export default injectViewOnOpenSaucedButton;