<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by MJ WU on Medium]]></title>
        <description><![CDATA[Stories by MJ WU on Medium]]></description>
        <link>https://medium.com/@JordanWuInTheHouse?source=rss-7b54366c082------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EiFgMJY1g6J6CyzrZCsYUQ.jpeg</url>
            <title>Stories by MJ WU on Medium</title>
            <link>https://medium.com/@JordanWuInTheHouse?source=rss-7b54366c082------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:21:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@JordanWuInTheHouse/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Build a Google Chrome Extension with React, Next.js, and MongoDB]]></title>
            <link>https://medium.com/@JordanWuInTheHouse/how-to-build-a-google-chrome-extension-with-react-next-js-and-mongodb-912e1d46f49e?source=rss-7b54366c082------2</link>
            <guid isPermaLink="false">https://medium.com/p/912e1d46f49e</guid>
            <dc:creator><![CDATA[MJ WU]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 18:40:55 GMT</pubDate>
            <atom:updated>2025-01-23T18:40:55.085Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Building a Chrome extension with modern web technologies such as <strong>React</strong>, <strong>Next.js</strong>, and <strong>MongoDB</strong></p><h3>Step 1: Understand the Chrome Extension Anatomy</h3><p>A Chrome extension typically consists of the following parts:</p><ol><li><strong>Manifest file</strong>: Defines the extension’s metadata, permissions, and scripts.</li><li><strong>Background scripts</strong>: Executes logic in the background (e.g., event listeners).</li><li><strong>Content scripts</strong>: Injected into web pages to interact with their DOM.</li><li><strong>Popup</strong>: The UI displayed when the user interacts with the extension icon.</li></ol><p>We’ll integrate these components with a <strong>React-based UI</strong>, use <strong>Next.js</strong> for API routes, and connect to <strong>MongoDB</strong> for data storage.</p><h3>Step 2: Set Up the Development Environment</h3><h4>Install Dependencies</h4><p>Start by creating a Next.js app:</p><pre>npx create-next-app@latest chrome-extension-react<br>cd chrome-extension-react<br>npm install</pre><p>Add the following dependencies:</p><pre>npm install mongoose dotenv @plasmohq/crx @crxjs/vite</pre><h3>Step 3: Create the Manifest File</h3><p>Inside the public/ folder, create a manifest.json file. This file configures the extension:</p><pre>{<br>  &quot;manifest_version&quot;: 3,<br>  &quot;name&quot;: &quot;React Chrome Extension&quot;,<br>  &quot;version&quot;: &quot;1.0&quot;,<br>  &quot;description&quot;: &quot;A Chrome extension built with React, Next.js, and MongoDB.&quot;,<br>  &quot;permissions&quot;: [&quot;storage&quot;, &quot;activeTab&quot;, &quot;scripting&quot;],<br>  &quot;action&quot;: {<br>    &quot;default_popup&quot;: &quot;index.html&quot;,<br>    &quot;default_icon&quot;: &quot;icon.png&quot;<br>  },<br>  &quot;background&quot;: {<br>    &quot;service_worker&quot;: &quot;background.js&quot;<br>  },<br>  &quot;content_scripts&quot;: [<br>    {<br>      &quot;matches&quot;: [&quot;&lt;all_urls&gt;&quot;],<br>      &quot;js&quot;: [&quot;content.js&quot;]<br>    }<br>  ]<br>}</pre><p>This file:</p><ul><li>Specifies the extension type (manifest_version: 3).</li><li>Adds permissions for storage and scripting.</li><li>Connects the popup, background script, and content scripts.</li></ul><h3>Step 4: Build the Popup UI with React</h3><p>The popup UI is the main interaction point for users. Here’s how to create it:</p><h4>Popup Component</h4><p>In components/Popup.js, write the popup UI:</p><pre>const Popup = () =&gt; {<br>  const handleSave = async () =&gt; {<br>    const response = await fetch(&quot;/api/save-data&quot;, {<br>      method: &quot;POST&quot;,<br>      headers: { &quot;Content-Type&quot;: &quot;application/json&quot; },<br>      body: JSON.stringify({ data: &quot;Sample Data&quot; }),<br>    });<br>    const result = await response.json();<br>    console.log(result);<br>  };</pre><pre>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;React Chrome Extension&lt;/h1&gt;<br>      &lt;button onClick={handleSave}&gt;Save Data&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>};</pre><pre>export default Popup;</pre><h4>Connect to Next.js</h4><p>Update pages/index.js:</p><pre>import Popup from &quot;../components/Popup&quot;;</pre><pre>export default function Home() {<br>  return &lt;Popup /&gt;;<br>}</pre><p>This serves the popup component when the extension is loaded.</p><h3>Step 5: Add Background and Content Scripts</h3><h4>Background Script</h4><p>In public/background.js, add logic for background tasks:</p><pre>chrome.runtime.onInstalled.addListener(() =&gt; {<br>  console.log(&quot;Extension Installed&quot;);<br>});</pre><pre>chrome.action.onClicked.addListener((tab) =&gt; {<br>  chrome.scripting.executeScript({<br>    target: { tabId: tab.id },<br>    files: [&quot;content.js&quot;],<br>  });<br>});</pre><h4>Content Script</h4><p>In public/content.js, add code that interacts with the web page:</p><pre>console.log(&quot;Content script loaded!&quot;);<br>document.body.style.backgroundColor = &quot;lightblue&quot;;</pre><h3>Step 6: Connect MongoDB</h3><h4>MongoDB Setup</h4><ol><li>Add a .env.local file:</li></ol><pre>MONGODB_URI=mongodb+srv://&lt;username&gt;:&lt;password&gt;@cluster0.mongodb.net/&lt;dbname&gt;</pre><p>Create a connection handler (lib/mongodb.js):</p><pre>import mongoose from &quot;mongoose&quot;;<br><br>const connectMongo = async () =&gt; {<br>  if (mongoose.connections[0].readyState) return;<br>  await mongoose.connect(process.env.MONGODB_URI);<br>  console.log(&quot;Connected to MongoDB&quot;);<br>};<br><br>export default connectMongo;</pre><ul><li>import mongoose from &quot;mongoose&quot;; const connectMongo = async () =&gt; { if (mongoose.connections[0].readyState) return; await mongoose.connect(process.env.MONGODB_URI); console.log(&quot;Connected to MongoDB&quot;); }; export default connectMongo;</li></ul><h4>Create API Routes</h4><p>Set up a route to save data to MongoDB (pages/api/save-data.js):</p><pre>import connectMongo from &quot;../../lib/mongodb&quot;;<br>export default async function handler(req, res) {<br>  await connectMongo();<br>  if (req.method === &quot;POST&quot;) {<br>    const { data } = req.body;<br>    // Save data logic<br>    res.status(200).json({ message: &quot;Data saved!&quot; });<br>  } else {<br>    res.status(405).json({ message: &quot;Method not allowed&quot; });<br>  }<br>}</pre><h3>Step 7: Bundle the Extension</h3><h4>Update Next.js Configuration</h4><p>Modify next.config.js:</p><pre>module.exports = {<br>  reactStrictMode: true,<br>  webpack: (config) =&gt; {<br>    config.output.publicPath = &quot;/_next/&quot;;<br>    return config;<br>  },<br>};</pre><h4>Build the Extension</h4><pre>npm run build</pre><p>Manually copy the out directory to the Chrome extension directory.</p><h3>Step 8: Load and Test the Extension</h3><ol><li>Open Chrome and navigate to chrome://extensions/.</li><li>Enable <strong>Developer Mode</strong>.</li><li>Click <strong>Load unpacked</strong> and select the out folder.</li><li>Test the extension functionality, ensuring the popup and background logic work as expected.</li></ol><h3>Step 9: Publish the Extension</h3><p>Once your extension is complete, you can publish it:</p><ol><li>Compress the build folder into a .zip file.</li><li>Submit it to the <a href="https://chrome.google.com/webstore/devconsole/">Chrome Web Store Developer Dashboard</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=912e1d46f49e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[到瑞典KTH念媒體碩士]]></title>
            <link>https://medium.com/@JordanWuInTheHouse/%E5%88%B0%E7%91%9E%E5%85%B8kth%E5%BF%B5%E5%AA%92%E9%AB%94%E7%A2%A9%E5%A3%AB-e8bb4d73c0f?source=rss-7b54366c082------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8bb4d73c0f</guid>
            <dc:creator><![CDATA[MJ WU]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 13:58:31 GMT</pubDate>
            <atom:updated>2022-08-22T14:02:46.338Z</atom:updated>
            <content:encoded><![CDATA[<p>夏天總會用大量的冰塊降溫，在倒水入冰塊盒複雜的過程中，我總感覺悟到了什麼人生道理？</p><p>首先必須緩緩地將開水注入盒中，倒太快水會來不及流入其他格子而溢出來….</p><p>我想著想著得到一個結論：</p><p>趕快去買一台會製冰的冰箱吧！</p><p>謝謝爸媽的支持，姊姊的鼓勵和教育部的貸款補助（讚讚），今年終於到瑞典皇家理工學院念MSc Interactive Media Technology了</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TDKmwg-AaAZRTx9EkDurpw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R7dprRGHmPl31zlPp-d1hQ.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8bb4d73c0f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>