This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.contextMenus.onClicked.addListener(async (info) => { | |
if (info.menuItemId === "createCalendarEvent") { | |
const selectedText = info.selectionText; | |
try { | |
const event = await parseEventDetails(selectedText); | |
const startTime = new Date(event.start_time); | |
const endTime = new Date(event.end_time); | |
event.dates = `${format(startTime)}/${format(endTime)};`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.contextMenus.onClicked.addListener(async (info) => { | |
if (info.menuItemId === "createCalendarEvent") { | |
const selectedText = info.selectionText; | |
try { | |
const { url } = await parseEventDetails(selectedText); | |
chrome.tabs.create({ url }); | |
} catch (e) { | |
console.log(e); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createGoogleCalendarUrl(eventDetails) { | |
const googleCalendarUrl = new URL( | |
"https://calendar.google.com/calendar/u/0/r/eventedit", | |
); | |
const params = googleCalendarUrl.searchParams; | |
if (eventDetails.title) { | |
params.append("text", eventDetails.title); | |
} | |
if (eventDetails.dates) { | |
params.append("dates", eventDetails.dates); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function format(date) { | |
const month = String(date.getMonth() + 1).padStart(2, "0"); | |
const day = String(date.getDate()).padStart(2, "0"); | |
const year = date.getFullYear(); | |
const hours = String(date.getHours()).padStart(2, "0"); | |
const minutes = String(date.getMinutes()).padStart(2, "0"); | |
const seconds = String(date.getSeconds()).padStart(2, "0"); | |
return `${year}${month}${day}T${hours}${minutes}${seconds}`; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const response = await ai.models.generateContent({ | |
model: "gemini-2.0-flash", | |
contents: prompt, | |
config: { | |
responseMimeType: "application/json", | |
responseSchema: { | |
type: Type.OBJECT, | |
properties: { | |
title: { | |
type: Type.STRING, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function parseEventDetails(text) { | |
const prompt = ` | |
The following text describes an event. Extract the provided schema from the text accordingly. | |
* Use IS0-8601 format for the start and end time. | |
* If no year is provided, use the current year ${new Date().getFullYear()}. | |
* If no time is provided, default to 00:00 on the start date and 23:59 on the end date. | |
* If no timezone or description is provided, leave it empty. | |
* Do not convert the start time or end time |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { GoogleGenAI, Type } from "@google/genai"; | |
const ai = new GoogleGenAI({ | |
apiKey: "<your_api_key>", | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.contextMenus.onClicked.addListener(async (info) => { | |
if (info.menuItemId === "createCalendarEvent") { | |
const selectedText = info.selectionText; | |
try { | |
console.log(selectedText); | |
} catch (e) { | |
console.log(e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.runtime.onInstalled.addListener(() => { | |
chrome.contextMenus.create({ | |
id: "createCalendarEvent", | |
title: "Create Calendar Event", | |
contexts: ["selection"], | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html { | |
box-sizing: border-box; | |
} | |
*, *::before, *::after { | |
box-sizing: inherit; | |
margin: 0; | |
padding: 0; | |
} |
NewerOlder