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].
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/35b77f29-53b6-404d-8b1d-f4b137091131%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.