Skip to content

Instantly share code, notes, and snippets.

@mopa
Created August 28, 2023 16:33
Show Gist options
  • Select an option

  • Save mopa/6ee0a3e4824c7d60cd748c28e2d78d0a to your computer and use it in GitHub Desktop.

Select an option

Save mopa/6ee0a3e4824c7d60cd748c28e2d78d0a to your computer and use it in GitHub Desktop.

Revisions

  1. mopa created this gist Aug 28, 2023.
    23 changes: 23 additions & 0 deletions todoist_random_task.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    javascript: (function () {
    const token = "TOKEN";
    fetch("https://api.todoist.com/rest/v2/tasks", {
    method: "GET",
    headers: {
    Authorization: `Bearer ${token}`,
    },
    })
    .then((response) => {
    if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json();
    })
    .then(data => {
    item = data[Math.floor(Math.random()*data.length)];
    window.location.href = item.url
    })
    .catch((error) => {
    console.error("Error:", error);
    alert(`An error occurred: ${error.message}`);
    });
    })();