Local Storage or Cookie access from TiddlyWiki

109 views
Skip to first unread message

TonyM

unread,
Nov 27, 2019, 10:58:26 PM11/27/19
to TiddlyWikiDev
Folks,

I would like access to local storage for the design of some new features.

Background
  • Unlike TWC cookies and the cookie jar from Eric are not longer relevant. 
  • I understand the Browser Local Storage Plugin is designed to save tiddlers, according to the filter set within it.
  • I understand the Password widget uses this mechanism
  • There are server based possibilities but on this occasion I am not using them. This interest is for single file wikis.
Is there a TiddlyWiki way (Widget et...) or could there be a way for me to simply define, set and read values in Browser Cache, Cookies, local storage, Session  Storage?

If so I can see the opportunity for some helpful methods to be designed.

For Example;

On any load (Startup)
  • If the local storage session code equals the saved one proceed and allow saving.
  • If no Local storage session code exists randomly generate or timestamped session "ID" to generate one, save it in a tiddler and cookie (as an example), save and reload the wiki (With a custom splash screen). 
  • If the local storage session code does not equal that saved in the wiki then stop saving (thus overwitting the session who owns it) unless an express override occurs.
Further to this;
If we could have some general widgets to access local storage this way outside of the tiddler save process various other features could be designed such as custom clipboards, and alternate form of persistent variables, somewhat global (but changing variables) and counters or registers.

Thanks for considering this
Tony

Mat

unread,
Dec 14, 2019, 6:31:55 AM12/14/19
to TiddlyWikiDev
Is there a TiddlyWiki way (Widget et...) or could there be a way for me to simply define, set and read values in Browser Cache, Cookies, local storage, Session  Storage?


That'd be something. Imagine defining cookies+values like you define fields+values. Wow!

<:-)

Eric Shulman

unread,
Dec 14, 2019, 7:26:27 AM12/14/19
to TiddlyWikiDev
On Wednesday, November 27, 2019 at 7:58:26 PM UTC-8, TonyM wrote:
  • Unlike TWC cookies and the cookie jar from Eric are not longer relevant. 
Some time ago (a few years, in fact) I made a set of cookie-handling widgets for TW5.  I use them in the InsideTiddlyWiki book so that various settings and state values are automatically saved as cookies, and are re-applied when you load the page.  This allows InsideTiddlyWiki "themes" and TOC views to be preserved across sessions, so YOUR choices are applied each time you visit the site.

To see it in action, go to http://tiddlytools.com/InsideTW and then click the "select a theme" button (upper right toolbar, picture icon) and choose another theme (e.g., Woodshop), or click the "toggle stretch-to-fit" button (next to the theme button), or click the "pin Table of Contents" button (upper left, first icon).

Then, reload the page... and notice that your settings were stored (as cookies) and re-applied when you reloaded!

The plugins are:
TiddlyTools/Cookies/action-setcookie.js
TiddlyTools/Cookies/cookie.js
TiddlyTools/Cookies/cookienames.js
TiddlyTools/Cookies/getcookie.js
 
which are used here:
TiddlyBook/CookieJar

The CookieJar is tagged with $:/tags/PageTemplate so it invoked each time you load the page, and uses the <<cookie>> widget, which binds tiddlers within the document to specific cookie names.  When the <<cookie>> widget is first invoked, it loads tiddlers from stored cookies, and then automatically updates the cookies whenever those tiddlers are changed during the session.

Note: cookies won't work when viewing local files (which don't allow cookies at all)... but it DOES work when you are viewing hosted (online) files.  Also, I wrote all of the above long before the LocalStorage plugin existed... but similar handling should be possible using LocalStorage instead of cookies, which would then permit use for local files as well as hosted files.

enjoy,
-e

PMario

unread,
Dec 14, 2019, 7:45:39 AM12/14/19
to TiddlyWikiDev
Hi,

TW state is driven by tiddlers. So shouldn't be the local-storage plugin be enough? It should save every state tiddler, so it can be re-applied at statup.

-m

PMario

unread,
Dec 14, 2019, 7:52:13 AM12/14/19
to TiddlyWikiDev
On Saturday, December 14, 2019 at 1:45:39 PM UTC+1, PMario wrote:
...
TW state is driven by tiddlers. So shouldn't be the local-storage plugin be enough? It should save every state tiddler, so it can be re-applied at statup.
 
Had a closer look. ... It's not enough. ... but if combined with the possibility to "restore stories" it should be enough.

just some thoughts
-m

TonyM

unread,
Dec 14, 2019, 8:00:21 PM12/14/19
to TiddlyWikiDev
Thanks Eric,

I did not know you implemented a TW5 version of the great TWC cookie Jar. Thanks I will look at that ASAP
  • I presume I could display one set of cookies according to the currently selected user?

TonyM

unread,
Dec 14, 2019, 8:06:42 PM12/14/19
to TiddlyWikiDev
Mario,

I agree we can use the local storage plugin for this but with all the doom and gloom about it I was thinking of a more minimal always available way to store a limited number of values in cache, cookie, local and session storage perhaps even IndexDB. I am thinking of simple widgets which may be in Erics Cookie Jar. 

These different types of storage have different functions and purposes for all browsers and sites in the internet. I am interested in providing these simple services to tiddlywiki without necessarily using the local storage plugin. Eg session storage can be appropriate for logins and other single session values (disappear on new session).

The Password widget does this but offers little additional services.

Thanks all
Tony

Eric Shulman

unread,
Dec 14, 2019, 11:57:27 PM12/14/19
to TiddlyWikiDev
On Saturday, December 14, 2019 at 5:00:21 PM UTC-8, TonyM wrote:
I did not know you implemented a TW5 version of the great TWC cookie Jar. Thanks I will look at that ASAP
  • I presume I could display one set of cookies according to the currently selected user?
Cookies are, of course, stored in the browser -- just like LocalStorage.  So, there is, by definition, only one set of cookies.  However, the CookieJar, which is responsible for actually saving cookies to the browser, could, theoretically, write cookiename that have a username prefix.  You would then have to write some handling in the CookieJar that would explicitly re-load the cookie values that is triggered whenever the username in $:/status/UserName is changed.  That way, if the same browser is used by several people, each would have their own set of cookies.

Also, just to brag a bit... there's a whole bunch of gems hidden in the implementation of InsideTiddlyWiki...

1) go to http://tiddlytools.com/InsideTW/#PartsList%2FSystem to see a list of "System Parts"
2) press "unlock" (upper right toolbar) to enable editing mode in the document
3) view a specific System Part, and then edit it to see the actual code.

note: the "authormode" buttons -- more, info, edit, and close -- only appear in the heavily-customized tiddler viewtemplate titlebar when the document is unlocked.  They are shown floating in a separate "bubble" that appears above the "reader toolbar" buttons for the tiddler.  This allows those buttons to be toggled on/off without otherwise affecting the titlebar's "readermode" layout.

Also: only *some* of the System Parts are currently "portable" (i.e., independent of other TiddlyBook bits-and-pieces).  I'm gradually working on dis-entangling more parts so I can -- eventually -- create a separate "TiddlyTools for TW5" distribution document, similar to the old TiddlyTools (for TWClassic) document (that is still currently being presented when you visit the default index page at www.TiddlyTools.com).

If there's things you'd like to copy and use in your own documents, please ask me for details (and "permission") for those things in particular, since not everything is ready for sharing, and the dependencies might not be simple to untangle.

As "Buckaroo Bonzai" says (while assisting in brain surgery):  "... don't tug on that... you never know what it might be attached to!"


enjoy,
-e

TonyM

unread,
Dec 21, 2019, 2:23:40 AM12/21/19
to TiddlyWikiDev
Eric,

Thanks very much for the pointer to the cookie jar and your InsideTW which is looking great.

I expect I should wait until you package "set, load and get cookies" into a distributable package before trying to make use of this.

Lots of Gems for sure.

Thanks for you work Eric.

Tony

TonyM

unread,
Dec 23, 2019, 8:34:47 PM12/23/19
to TiddlyWikiDev
Eric,

I was just searching in TWinternals in relation to cookies and say a note "pending: limit search to TOC topics only" and just wanted to mention bimlas's KIN operator can iterate the list of tiddlers in the TOC hierarchy and provide the titles to the search operator to make this simple to do.

Regards
Tony

Eric Shulman

unread,
Dec 23, 2019, 8:52:25 PM12/23/19
to TiddlyWikiDev
On Monday, December 23, 2019 at 5:34:47 PM UTC-8, TonyM wrote:
Eric,

I was just searching in TWinternals in relation to cookies and say a note "pending: limit search to TOC topics only" and just wanted to mention bimlas's KIN operator can iterate the list of tiddlers in the TOC hierarchy and provide the titles to the search operator to make this simple to do.

Thanks for reminding me about that unfinished work.
However, I already have a macro for getting the TOC hierarchy as a flat list...

All I need to do is wikify the output of that macro and then enlist it into the custom search filter, and it should be all set.

oh.. and re: "TWinternals".. I think you meant "InsideTW"

-e
Reply all
Reply to author
Forward
0 new messages