Skip to content

Commit

Permalink
feat: communicate between popup and content script
Browse files Browse the repository at this point in the history
  • Loading branch information
a0m0rajab committed May 23, 2023
1 parent c735e51 commit 33eb47d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/content-scripts/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ const processGithubPage = async () => {
};

void processGithubPage();

chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.text === "getAiHighlights") {
sendResponse("test");
}
});
16 changes: 14 additions & 2 deletions src/pages/posthighlight.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext } from "react";
import { useContext, useEffect, useState } from "react";
import { FaChevronLeft } from "react-icons/fa";
import OpenSaucedLogo from "../assets/opensauced-logo.svg";
import { RouteContext } from "../App";
Expand All @@ -7,6 +7,18 @@ import GhOpenGraphImg from "../content-scripts/components/githhub-open-graph";

const PostOnHighlight = () => {
const { setCurrentPage } = useContext(RouteContext);
const [pageURL, setPageURL] = useState("");


chrome.tabs.query({ currentWindow: true, active: true }, tabs => {
function fallBack (domContent) {
console.log("fallBack", domContent);
}
console.log(tabs);
setPageURL(tabs[0]?.url ?? "");
chrome.tabs.sendMessage(Number(tabs[0].id), { text: "report_back" }, fallBack);
});


return (
<div className="grid grid-cols-1 divide-y divider-y-center-2 min-w-[320px]">
Expand All @@ -32,7 +44,7 @@ const PostOnHighlight = () => {
<main className="text-white">

<GhOpenGraphImg
githubLink={"https://github.com/open-sauced/insights/pull/1184"}
githubLink={pageURL}
/>

<input
Expand Down

0 comments on commit 33eb47d

Please sign in to comment.