mgsloan / todoist-shortcuts

Browser extension which adds comprehensive keyboard shortcuts to Todoist, beyond what is offered by Todoist itself
MIT License
313 stars 23 forks source link

Parsing user options fails if not using browser extension #225

Closed mvaaltola closed 1 year ago

mvaaltola commented 1 year ago

Background

I'm using Todoist in Rambox which doesn't support browser extensions but allows users to inject their own JavaScript. For this reason I'm bundling your wonderful extension to a minified js file:

cat src/mousetrap.js > build.js
cat src/todoist-shortcuts.js >> build.js
uglifyjs build.js > build-min.js

This has worked perfectly, but some time ago after upgrading from around version 135 to the latest v164 I started noticing an annoying issue.

The issue

After upgrading I noticed that the cursor disappears after marking tasks as done. For a while I worked around this by manually selecting another task or changing the task list, but eventually started looking for the cause.

I located the issue to loadOptions. If document.body.getAttribute('data-todoist-shortucts-options') returns null (which it will since I don't have the browser extension installed), the default empty options array is overwritten with JSON.parse(null), i.e. null. This in turn results in uncaught TypeErrors in both getXOption functions which expect options to be an object.

I'll submit a oneliner PR that has fixed this issue for me. Thanks again for the great extension!