Skip to content

Instantly share code, notes, and snippets.

@mopa
Created August 28, 2023 16:33
Show Gist options
  • Save mopa/6ee0a3e4824c7d60cd748c28e2d78d0a to your computer and use it in GitHub Desktop.
Save mopa/6ee0a3e4824c7d60cd748c28e2d78d0a to your computer and use it in GitHub Desktop.
A Todoist bookmarklet to pick a random task
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