GetLocalStorageItem javascript macro

91 views
Skip to first unread message

Charlie Veniot

unread,
Feb 5, 2022, 4:44:36 PM2/5/22
to TiddlyWiki
I don't have much experience with javascript macros, but I know just enough to be dangerous...

So FYI, just a simple javascript macro example for anybody interested in this kind of thing.

See attached text file.

(I'll follow this up with a link to this Google Post, in case the attachment does not show in TiddlyTalk.)


GetLocalStorageItem.js.txt

Charlie Veniot

unread,
Feb 5, 2022, 4:45:02 PM2/5/22
to TiddlyWiki

Dyllon Gagnier

unread,
Feb 5, 2022, 10:32:43 PM2/5/22
to TiddlyWiki
Even in Google Groups, your attachment is empty. I would recommend pastebin or making a GitHub gist.

Charlie Veniot

unread,
Feb 5, 2022, 11:31:24 PM2/5/22
to TiddlyWiki
Arg, I totally borked the export of that file.  (The file on my local drive is empty.)

Thanks for catching that.

Instead, sneak a peek at both javascript macros (GetLocalStorageItem and SetLocalStorageItem) here: https://basicanywheremachine.neocities.org/LocalStoragePrototype.html

That TiddlyWiki is to demonstrate not just local storage in TiddlyWiki, but a way for a BASIC program and a TiddlyWiki instance can exchange data via local storage, as long as they are both in the same domain.

Hans Wobbe

unread,
Feb 6, 2022, 8:35:58 AM2/6/22
to TiddlyWiki
I am assuming that "as long as they are both in the same domain" applies to a googleDrive environment as well as your ...neocities... domain.  Please let me know if that is NOT a valid assumption.  In the mean time, I am going to ponder some "back-up" considerations that are nagging at me.

Cheers,
Hans

Charlie Veniot

unread,
Feb 6, 2022, 12:52:33 PM2/6/22
to TiddlyWiki
I am no internet expert, so not sure if and when I'm using the right language.

Let's say we have two web pages (say one is some TiddlyWiki, say the other is a TiddlyWiki with BASIC Anywhere Machine).  For them (and however many others) to share data via local storage, they must all be in the same origin.  That origin could be any web host at all, as long as all the web pages are from the same IP and port (if I understand correctly?)

I'd say as per the Same-origin policy documentation at MDN Web Docs.

If a web browser allows local storage at localhost (i.e. the hard drive on your computer), then all TiddlyWiki instances and whatever other local web pages on your computer are accessing the same local storage.

Something like that ...

Hans Wobbe

unread,
Feb 6, 2022, 1:17:03 PM2/6/22
to tiddl...@googlegroups.com
I think you are other right track.

I've even gone so far as to mention aspects of this to Jeremy.


From: tiddl...@googlegroups.com <tiddl...@googlegroups.com> on behalf of Charlie Veniot <cj.v...@gmail.com>
Sent: Sunday, February 6, 2022 12:52:33 PM
To: TiddlyWiki <tiddl...@googlegroups.com>
Subject: [tw5] Re: GetLocalStorageItem javascript macro
 
--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/mOm62AUaz8c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/502a011a-f03a-40ee-aba2-5ec2883fd6b0n%40googlegroups.com.

Dyllon Gagnier

unread,
Mar 22, 2022, 5:59:21 PM3/22/22
to TiddlyWiki
For storage purposes, you could use IndexedDB and create a database for each wiki isolated by taking the hash of the URL (which is easy to get via JS) and using that for the DB name. It doesn't really add any security, but it does avoid accidental clobbering. The downside to this approach is you would have to use IndexedDB which is a really horrible and confusing API.
Reply all
Reply to author
Forward
0 new messages