Glanceway Glanceway
Alle Quellen

xkcd Comics

Unterhaltung v1.0.0

Latest comics from xkcd

@codytseng #comics #humor #science

Install and configure this source

  1. Install Glanceway and open it on your Mac before using the install link above.
  2. Choose Install in Glanceway. If the browser cannot open the app, download the .gwsrc file and import it through source management.
  3. Complete the required fields below, save, and choose a refresh interval. Check the source after its first successful fetch.

This version does not require configuration fields. Install it and allow the initial fetch to complete.

If items are missing

  • Verify the field names, list entries, and credentials against the current version’s configuration table. Sample values below are examples, not active credentials.
  • Check network access and upstream service availability. Authentication failures and rate limits can prevent a refresh; use a slower interval when the provider limits requests.
  • An empty result can also mean there are no matching items. Fetched content and update timing depend on the provider and source implementation.

Quellcode

id: codytseng/xkcd
version: 1.0.0
name: xkcd Comics
description: Latest comics from xkcd
author: codytseng
author_url: https://github.com/codytseng
category: Entertainment
tags:
  - comics
  - humor
  - science
module.exports = async (api) => {
  async function fetchData() {
    const latestRes = await api.fetch(
      "https://xkcd.com/info.0.json",
    );

    if (!latestRes.ok || !latestRes.json) {
      throw new Error(`Failed to fetch latest xkcd comic (HTTP ${latestRes.status})`);
    }

    const latest = latestRes.json;
    const count = 50;
    const comics = [latest];

    await Promise.allSettled(
      Array.from({ length: count - 1 }, (_, i) => latest.num - i - 1)
        .filter((num) => num > 0 && num !== 404)
        .map(async (num) => {
          const res = await api.fetch(
            `https://xkcd.com/${num}/info.0.json`,
          );
          if (res.ok && res.json) {
            comics.push(res.json);
            api.emit(
              comics.map((c) => ({
                id: c.num.toString(),
                title: `#${c.num}: ${c.title}`,
                subtitle: c.alt,
                url: `https://xkcd.com/${c.num}/`,
                timestamp: `${c.year}-${c.month.padStart(2, "0")}-${c.day.padStart(2, "0")}`,
              })),
            );
          }
        }),
    );
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};

Ähnliche Quellen