# Description
This code provides a browser extension or user script that leverages Google's Generative AI model (Gemini) to enhance your LinkedIn experience. Here's what it offers:
- Voice Commands: Speak commands related to LinkedIn actions, and the script will interpret them and potentially generate relevant information.
- AI-powered Comment Generation: When clicking on a "Reply" button or a comment text input area, an "AI Search" button appears. Clicking this button lets you enter a prompt, and the Gemini AI model will generate a comment suggestion ready to paste.
# Requirements
- A browser that supports the SpeechRecognition API (
window.SpeechRecognitionorwindow.webkitSpeechRecognition). - A Google Cloud project with the Google Generative AI API enabled (https://cloud.google.com/products/ai)
- An API key obtained from the Google Cloud project (replace
YOUR_API_KEYin the code)
# Installation
1. Browser Extension (Optional):
- Choose a browser extension framework (e.g., Manifest V3).
- Include the code from this file in the extension's content script or background script.
- Package and install the extension in your browser following the framework's documentation.
2. User Script:
- Copy the code from this file.
- Create a new userscript file (e.g.,
linkedin_ai_assistant.user.js) and paste the code into it. - Install a userscript manager extension in your browser (e.g., Tampermonkey, Greasemonkey).
- Create a new userscript within the manager and paste the script content.
- Save the userscript and enable it for LinkedIn.
# Usage
Voice Commands:
- Use the default keyboard shortcut (
Ctrl+Space) to activate speech recognition. - Speak a command related to LinkedIn actions (e.g., "Search for profiles with X skills").
AI-powered Comment Generation:
- Click on a "Reply" button or a text input area for comments on LinkedIn.
- The "AI Search" button should appear next to the input field.
- Click the "AI Search" button.
- A popup window will appear. Enter a prompt describing the comment you want to generate (e.g., "Ask about their experience in X").
- Click the "Geminai " button.
- The script will generate a comment suggestion based on your prompt and the context of the post.
- Copy and paste the suggested comment into the LinkedIn input field.
# Customization
- You can modify the keyboard shortcut for voice recognition by changing the
handleKeyDownfunction in the code. - The code uses the Gemini-pro model for AI generation. You can experiment with different models provided by the Google Generative AI API (update the
model: "gemini-pro"part in the code).
# Ethical Considerations
- Use the script responsibly and avoid any activities that violate LinkedIn's terms of service.
- Be aware of potential biases in the AI model's output and review the suggestions carefully before posting.
- Users should disclose the use of AI-generated content whenever appropriate.
# Disclaimer
This code is provided for educational purposes only. The author is not responsible for any misuse or unintended consequences of its use.
# Explanation of Key Code Sections
- Imports:
import { GoogleGenerativeAI } from "@google/generative-ai";: Imports the Google Generative AI library for interacting with the Gemini model.
- API Key:
const API_KEY = "YOUR_API_KEY";: Replace this with your actual Google Cloud API key.
- Speech Recognition:
- The code checks for SpeechRecognition API support and creates an object to capture voice commands. It processes the recognized text and triggers comment generation.
- AI Integration:
generateResponseandgenerateLinkfunctions handle interaction with the Gemini model. The script sends the prompt to the model and receives a response.
- Comment Generation:
- When the "AI Search" button is clicked, a popup appears with an input field for the comment prompt. Clicking the "Geminai " button sends the prompt to the Gemini model for comment generation.
- The generated comment is displayed in the popup and can be copied and pasted into LinkedIn.
- Toast Notifications:
- The
createToastfunction displays informative messages to the user (e.g., success, error).
- The
# Further Enhancements (Optional):
- Sentiment Analysis: Analyze the original post or comment to determine its mood and