Skip to content

Instantly share code, notes, and snippets.

@dcatanzaro
Last active November 12, 2021 14:42
Show Gist options
  • Save dcatanzaro/8833df28c485733f1723a817acbe265d to your computer and use it in GitHub Desktop.
Save dcatanzaro/8833df28c485733f1723a817acbe265d to your computer and use it in GitHub Desktop.

Revisions

  1. dcatanzaro revised this gist Sep 22, 2020. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions poke.js
    Original file line number Diff line number Diff line change
    @@ -16,10 +16,8 @@ if (config.runsInWidget) {

    const imgReqBq = await new Request("https://i.pinimg.com/originals/aa/34/e1/aa34e1c76a6569a36499ae86098759ee.jpg");
    const imgBq = await imgReqBq.loadImage();

    const imageBq = widget.addImage(imgBq);

    widget.backgroundImage = imageBq;
    widget.backgroundImage = imgBq;

    const title = widget.addText("Pokemon del día");
    title.textColor = Color.black();
  2. dcatanzaro renamed this gist Sep 22, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. dcatanzaro created this gist Sep 22, 2020.
    44 changes: 44 additions & 0 deletions javascript
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    const numberDay = () => {
    const now = new Date();
    const start = new Date(now.getFullYear(), 0, 0);
    const diff = now - start;
    const oneDay = 1000 * 60 * 60 * 24;
    const day = Math.floor(diff / oneDay);
    return day;
    };

    const pokemonUrl = `https://pokeapi.co/api/v2/pokemon/${numberDay()}`;
    const req = new Request(pokemonUrl);
    const res = await req.loadJSON();

    if (config.runsInWidget) {
    const widget = new ListWidget();

    const imgReqBq = await new Request("https://i.pinimg.com/originals/aa/34/e1/aa34e1c76a6569a36499ae86098759ee.jpg");
    const imgBq = await imgReqBq.loadImage();

    const imageBq = widget.addImage(imgBq);

    widget.backgroundImage = imageBq;

    const title = widget.addText("Pokemon del día");
    title.textColor = Color.black();
    title.textOpacity = 0.8;
    title.font = new Font("Courier", 16);

    widget.addSpacer(5);

    const namePokemon = widget.addText(`#${res.id} - ${res.name}`);
    namePokemon.textColor = Color.black();
    namePokemon.textOpacity = 0.8;
    namePokemon.font = new Font("Courier", 14);

    const imgReq = await new Request(res.sprites.front_default);
    const img = await imgReq.loadImage();

    const image = widget.addImage(img);
    image.centerAlignImage();

    Script.setWidget(widget);
    Script.complete();
    }