// Name: Feedbin Unread // Author: Kevin Kipp // Email: kevin.kipp@gmail.com // Twitter: https://twitter.com/kevin_kipp // Github: https://github.com/third774 import '@johnlindquist/kit'; const feedbinUsername = await env('FEEDBIN_USERNAME'); const feedbinPassword = await env('FEEDBIN_PASSWORD', () => arg({ placeholder: 'Feedbin Password', secret: true, }), ); const headers = { Authorization: `Basic ${btoa(`${feedbinUsername}:${feedbinPassword}`)}`, }; type Entries = EntriesItem[]; interface EntriesItem { author: null; content: string; created_at: string; extracted_content_url: string; feed_id: number; id: number; published: string; summary: string; title: string; url: string; } const { data } = await get<Entries>( `https://api.feedbin.com/v2/entries.json?read=false`, { headers }, ); const selection = await arg<EntriesItem>( { name: data.length > 0 ? 'Article Title' : 'No unread articles', actions: [ { name: 'Open', onAction: async (_, state) => { open(state.focused.value.url); finishScript(); }, shortcut: 'o', }, { name: 'Mark as read', onAction: async (_, state) => { await post( `https://api.feedbin.com/v2/unread_entries/delete.json`, { unread_entries: [state.focused.value.id] }, { headers }, ); }, shortcut: 'm', }, ], }, data.map((item: any) => ({ name: item.title, description: item.url, value: item, })), ); await open(selection.url); await post( `https://api.feedbin.com/v2/unread_entries/delete.json`, { unread_entries: [selection.id] }, { headers }, );