Created
May 31, 2025 07:19
-
-
Save ayoisaiah/0e00c3e8218f3606fcb349b1307a7b84 to your computer and use it in GitHub Desktop.
H
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); | |
} | |
} | |
}); | |
async function parseEventDetails(text) { | |
const prompt = ` | |
The following text describes an event. Extract "title", "start_time", "end_time", "description", "timezone" and "location" of the event | |
Return a URL in the following format: | |
https://calendar.google.com/calendar/u/0/r/eventedit?text=<title>&dates=<dates>&details=<details>&location=<location> | |
* The <dates> format should be <start_time>/<end_time> | |
* The times should be formatted like this: YYYYMMDDTHHMMSS. For example: 20250531T090000 | |
* 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 | |
Here is the text: | |
${text}`; | |
const response = await ai.models.generateContent({ | |
model: "gemini-2.0-flash", | |
contents: prompt, | |
config: { | |
responseMimeType: "application/json", | |
responseSchema: { | |
type: Type.OBJECT, | |
properties: { | |
url: { | |
type: Type.STRING, | |
}, | |
}, | |
}, | |
}, | |
}); | |
console.log(response.text); | |
return JSON.parse(response.text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment