Is there a mime type or deserialiser for JavaScript function like in bookmarklets

The URI encoding already collapses everything into a single line. Are there still cases where the URI encoding is not enough (other than size limit issues)? If not, then a bookmarklet can be created without using a minifier:

First I created a template tiddler titled “bookmarklet template” like this:

<a href={{{[all[current]get[text]] +[encodeuri[]addprefix[javascript: (() => {]addsuffix[})()]]}}}>{{!!title}}</a>

Then a simple javascript tiddler titled “alert and console log javascript example” with contents like this:

alert("testing")
console.log("testing")

I applied the template to the javascript like this:

{{alert and console log javascript example||bookmarklet template}}

The resulting html looks like this:

<a href="javascript: (() => {alert(%22testing%22)%0Aconsole.log(%22testing%22)})()">alert and console log javascript example</a>

Clicking on that link does display an alert and a console log message. Maybe for more complicated javascript, this approach will fall apart?

1 Like

That is an interesting solution. One I hadn’t considered. I like it. +1 well done.

I’m truly sorry but I don’t think we are talking the same things. That list you have seems to be discussing a different problem then displaying bookmarklet code a <a> tags. I’m not saying anything is wrong there I just do not understand much of what you ask in the context of bookmarklets. Perhaps our vocabularies are different?

The key difference between my proposed bookmarklets and those discussed by others here is using bookmarklets to carry a payload of tiddlers. The thing is config, tweaks and appearance are just a start, we can set almost anything using a set of tiddlers containing specific values. See the top post for an example. Click on such a bookmark and the “embedded” tiddlers are installed silently.

There are two key ways to prepare the payload tiddlers

  • Use a filter that obtains the list of payload tiddlers
    • This captures the nominated tiddlers as they are at that moment
  • or have a JSON tiddler or File containing tiddlers.
    • This contains tiddlers and their contents as at the time the JSON was built.
    • The $:/Import tiddler and Plugins are already in this form

You can use such tiddler payload bookmarklets;

  • To change settings
  • Have two opposite setting’s to restore.
  • To install one or more plugins or tiddlers on any wiki you have open in a tab
  • Install test data and reinstall as needed
  • Install tiddlers then edit them and save them back to an updated bookmarklet capturing different configuration states
  • Take a temporary backup of one or more tiddlers and save in a bookmarklet, or JSON for that matter.
  • To restore the history list
  • To apply a read only or read update mode

The key issue I have found is it is hard to share and transfer such bookmarklets. I want to develop an approach that we can all share tiddler package bookmarklets with a consistent format and standard.

  • The answers I have found is just keep the JSON tiddler standard, of type application/json and using the tiddlers caption or title generate a link that can either be;
    • Clicked in wiki to apply the payload to the current wiki, one or more times.
    • Dragged to the bookmarks to reuse on other wikis as well.
    • The JSON tiddler can also be imported, exported, shared online, dragged and dropped between wikis etc…
  • Since a JSON tiddler may have being generated using a list or filter perhaps a de facto standard is to include the filter if available in the same JSON tiddler in the “filter field”.
    • This would allow a second “bookmarklet” to be generated who’s payload is the tiddlers named in the filter in their current state in the current wiki. This is Mohammad’s approach.
  • I have taken this on board and using the JSON tiddler standard makes it easier to see.

The remaining challenge, which is why I started this thread, is the best way to update the core, provide a core plugin or share bookmarklet JSON’s with additional tiddlers to support “Bookmarklets”.

  • It seems to me such functionality is so useful and empowers sharing we need to find a de facto if not de jure standard bookmarklet tool.
  • We then need only share JSON / Bookmarklet tiddlers and files without needing to install anything.