4

Add "Random Memo" button to Memos v0.21+ sidebar

 1 week ago
source link: https://gist.github.com/lincolnthalles/957ee1b48634d4c41f5054526b17b5b0
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Author

This user script is meant for usememos/memos.

How to add this script

Click Settings -> System and paste the code in the Additional script field, click Save and reload the page.

image

Edit history

  • Moved code from this comment to this gist.
  • Updated code to handle v0.21+ API (name field was renamed to uid).
  • Refactored all user-relevant settings into a single object.
  • Tweaked button style when the sidebar is collapsed (there's still a minor icon alignment issue, though).

@lincolnthalles Thanks for this! I notice that random search has been implemented for the API in v0.21 (usememos/memos@bb10bb2); maybe this script can be updated to use that?

@lincolnthalles Thanks for this! I notice that random search has been implemented for the API in v0.21 (usememos/memos@bb10bb2); maybe this script can be updated to use that?

I've just added random_memo_v0.21+.js.
While this works and has less code, it has the drawback of doing one API query every time the index is reloaded.

The earlier code does a big API query once and caches all memo IDs for the specified amount of time.

Thank you for adding that, I appreciate it. The extra API queries are a trade-off, but it's nice to have another option.

I just tried it and there were no errors; however, it appeared to always show the latest memo when clicking the Random button. There's probably some mistake in the API's implementation.

Thank you for adding that, I appreciate it. The extra API queries are a trade-off, but it's nice to have another option.

I just tried it and there were no errors; however, it appeared to always show the latest memo when clicking the Random button. There's probably some mistake in the API's implementation.

The random API is only working on the latest v0.21.0. If you have a preliminary v0.21.0 built over a week ago, it won't work until you upgrade the server. Memos uses a rolling release model, so there can be different v0.21.0 in the wild.

You can test the API at the demo website.

Right, the demo website's API works—thanks for pointing that out. Now I'm not sure what's wrong with my instance (with MariaDB as storage) because I just double-checked and it was already using the latest stable Docker image updated just 2 days ago. I also tried switching to the 0.21 tag and the latest one (which actually is identical to stable, same hash) but still got the same behavior.

Anyway, for now I'll be using your original version and I'll try the v0.21+ one later when there's a new Docker image. Sorry for wasting your time on this issue!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK