Created
August 28, 2023 16:33
-
-
Save mopa/6ee0a3e4824c7d60cd748c28e2d78d0a to your computer and use it in GitHub Desktop.
A Todoist bookmarklet to pick a random task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment