Skip to content

Instantly share code, notes, and snippets.

View ayoisaiah's full-sized avatar
💪
Getting after it

Ayooluwa Isaiah ayoisaiah

💪
Getting after it
View GitHub Profile
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)};`;
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);
}
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);
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}`;
}
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,
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
import { GoogleGenAI, Type } from "@google/genai";
const ai = new GoogleGenAI({
apiKey: "<your_api_key>",
});
chrome.contextMenus.onClicked.addListener(async (info) => {
if (info.menuItemId === "createCalendarEvent") {
const selectedText = info.selectionText;
try {
console.log(selectedText);
} catch (e) {
console.log(e);
}
}
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "createCalendarEvent",
title: "Create Calendar Event",
contexts: ["selection"],
});
});
@ayoisaiah
ayoisaiah / style.css
Created August 3, 2023 09:33 — forked from damilolaolatunji/style.css
Stylesheet for Hacker News App
html {
box-sizing: border-box;
}
*, *::before, *::after {
box-sizing: inherit;
margin: 0;
padding: 0;
}