Identify tiddlers installed by bookmarklet

Folks,

I am further developing bookmarklet handing and hope to share some easy to use tools soon. As you may know bookmarklets use the following javascript:(function()%20%7B%0A%24tw.wiki.addTiddlers...
and add tiddler(s) silently.

  • This is a very useful feature.

However in some special cases I would like to be able show some indicator that this add tiddlers “function” took place, and ideally even see the tiddler titles so added.

  • Is there an event or message catcher we could use?

In a similar vein can we use other functions in bookmarklets and what are they. eg to have a delete tiddler function as well.

Hi @TW_Tones the obvious approaches would be your bookmarklet to insert an additional metadata tiddler that lists the tiddlers that have been added, or to somehow mark the fields of the tiddlers that you are creating so that they can be subsequently identified.

The API that your bookmark uses is the general purpose method to create a tiddler. There’s no provision in the core for metadata that is external to the tiddler. When something along those lines is needed we use separate tiddlers for the metadata.

1 Like

If you transformed the array of tiddlers you are passing to addTiddlers into an array of just one tiddler such that that tiddler has the format you see when you edit $:/Import, then it will be rendered using TW’s normal import mechanism. That way you can see the list of tiddlers like you want. After the user clicks the Import button, the import tiddler shows a list of the tiddlers which were imported. That seems close to what you are asking for.

The format for the text field of $:/Import is

{
  "tiddlers": {
    "my tiddler title1": {"<key value pairs of tiddler fields here>"},
    "my tiddler title2": {"<key value pairs of tiddler fields here>"},
    ...
  }
}

and the tiddler should also have a field plugin-type with value import.

Unfortunately that format is very different from the format addTiddlers takes as input:

[
    {"<key value pairs of tiddler fields here>"},
    {"<key value pairs of tiddler fields here>"},
    ...
]

This latter format is the format you can use to drop tiddlers into your wiki, so there should be some function in TW which is converting that format to the first format above. I looked, but didn’t find that function yet. If that function does exist then you can call $tw.wiki.addTiddlers($tw.wiki.someTransformationFunction([...])) in your bookmarklet.

I found the code in core/modules/widgets/navigator.js and the bad news is that it isn’t encapsulated in an easy-to-call javascript function. The good news is that you don’t even need javascript to do it. It is exposed via the tm-import-tiddler message.

That means you can use $action-sendmessage to pass the JSON array of tiddlers via $param:

<$action-sendmessage
  $message="tm-import-tiddler"
  $param="[{...}, {...}, ...]"
  importTitle="better title than $:/Import here"
/>
1 Like

Thanks for this help, sometimes it is as important to know when something can be simplified and when it may not be possible.

  • Yes this is my normal approach with plugins and JSON packages. I actually have a sophisticated solution in place for this.
  • In fact apart from the bookmarklet, In this project I have a tool to create a bookmarklet tiddler which in fact contains this metadata, primarily so it can be shared on the forums and in packages.

Bookmarklet generation;

\define save-as-bookmarklet-href()
(function() {
$tw.wiki.addTiddlers($(json-tiddlers)$);
})()
\end
\define function-prefix()
javascript:(function() {
$tw.wiki.addTiddlers(
\end
\define function-suffix()
);
})()
\end
\define bookmarklet(title,filter)
<$wikify name="json-tiddlers" output="text" text="""<$text text=<<jsontiddlers filter:"$filter$">>/>""">
<a href={{{ [<save-as-bookmarklet-href>encodeuricomponent[]addprefix[javascript:]] }}}>{{$:/PSaT/bookmarklets/icon}}<$text text="""$title$"""/></a>
</$wikify>
\end
  • The above is the code used to generate the bookmarklets
  • I need better skills at transforming the result of the above back to the different multi-tiddler formats , but I am getting there slowly.

This leads to a good idea, rather than the bookmark containing multiple tiddlers just get it to drop an Import pending tiddler which requires further interaction and allows other actions like;

  • Cancel
  • Selective install
  • Conversion to JSON or Plugin tiddler
  • Perhaps plugin tiddlers in bookmarklets could be installed along with the disable state so they must be activated etc…
  • Since I am building the bookmarklet tool I choose what is included so perhaps I add in tiddlers that announce the bookmarklet was installed in a custom list etc…
    • But I am starting with simple first

Progress so far (if you are interested in this subject, if not perhaps you should be :nerd_face: )

I will publish this work at bookmarklets.tiddlyhost.com in time. I have built some tools around bookmarklets and using them, a “lived experience” you could say. Challenges I am learning about include;

  • Once captured as a bookmarklet it is static and needs to be deleted and re-added should one of the payload tiddlers be upgraded
  • Gets more complex if you use more than one browser or multiple browser windows, because each can maintain seperate bookmarklets
  • This is even more complex if first distributing a “bookmarklet tiddler”
  • If you erroneously installed something its hard to see;
    • It happen (hence this topic)
    • How to reverse it
  • Something so quick and easy to use means the user can overload their mind and browser by overusing the feature.

As is often the case for many of the features and hacks I develop or other creative developers and designers create, this seems like a revolutionary extension of tiddlywiki capabilities, and I hope will prove simple and accessible.

1 Like