JavaScript macros are intended to generate an output string from their input parameters; they are not supposed to have side effects.
What are you trying to do here? It looks like you’re trying to compose a search URL for Google books; is the intention to provide a UI onto the search, or to search with information drawn from the current tiddler? Best wishes Jeremy > On 14 Jul 2016, at 12:01, László Zsigmond <[email protected]> > wrote: > > Hello! > > I'm trying to start with my first homebrew javascript snippet/macro that gets > the value of a tiddler's field and replaces two strings inside it... > I came up with the following not working code that should just return that > modified string. This script shouldn't run jut once but > each time one input element (inputterm) is edited. Have no idea how to call > such a function in Tiddlywiki context, for getElements it > would be safer to use ids but I just want to see if my plan is doable in the > first place. > > Help please. > > > Laci > > /*\ > title: $:/macros/obeliksz/library_api_macro.js > type: application/javascript > module-type: macro > > <<libraryapimacro>> > > Example: > <<libraryapimacro>> > > \*/ > (function(){ > > /*jslint node: true, browser: true */ > /*global $tw: false */ > "use strict"; > > /* > Information about this macro > Replaces inside the api_url string the inputterm with the more than 3 > characters > typed input from the title's edit-text and inputauthor with author edit-text > default api_url: > https://www.googleapis.com/books/v1/volumes?printType=books&q=+intitle:inputterm+inauthor:inputauthor > > */ > > exports.name = "libraryapimacro"; > > /* > Run the macro > */ > exports.run = function() { > var api_url = {{$:/plugins/inmysocks/LibraryTracker/Library Tracker > Settings!!api_url}} > var inputterm = > document.getElementsByClassName('tc-edit-texteditor')[0].value > var inputauthor = document.getElementsByTagName('select')[1].value > var output ="New url: " + > api_url.replace("inputterm",inputterm).replace("inputauthor",inputauthor); > return output; > }; > > })(); > > -- > You received this message because you are subscribed to the Google Groups > "TiddlyWiki" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To post to this group, send email to [email protected] > <mailto:[email protected]>. > Visit this group at https://groups.google.com/group/tiddlywiki > <https://groups.google.com/group/tiddlywiki>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/tiddlywiki/35b77f29-53b6-404d-8b1d-f4b137091131%40googlegroups.com > > <https://groups.google.com/d/msgid/tiddlywiki/35b77f29-53b6-404d-8b1d-f4b137091131%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/924DF5FD-52CF-4829-BD41-ED3E754D72FE%40gmail.com. For more options, visit https://groups.google.com/d/optout.

