Skip to content

Instantly share code, notes, and snippets.

@snay2
Created June 17, 2011 22:00
Show Gist options
  • Select an option

  • Save snay2/1032455 to your computer and use it in GitHub Desktop.

Select an option

Save snay2/1032455 to your computer and use it in GitHub Desktop.
rule booklist {
select when web pageview "booklist.byu.edu/cas/mybooks.cfm"
pre {
my_form = <<
<div style="display: none;">
<form id="isbnForm" onsubmit="return false">
<input name="isbn" value="nonsense" />
<input type="submit" />
</form>
</div>
>>;
}
{
append("body", my_form);
watch("#isbnForm", "submit");
emit <|
var isbn = new Array();
var row_num = -1;
$K.each($K("#Content table").contents().find("tr"), function(i, val) {
// Don't take the top row, since it's a header
if (row_num >= 0) {
var item = $K(val).find('td:nth-child(4)');
isbn.push(item.text());
// Add this to an input
$K("#isbnForm").append('<input type="text" name="isbnList[' + row_num + ']" value="' + item.text() + '" />');
}
row_num++;
});
$K("[name=isbn]").trigger("submit");
|>;
}
}
rule handle_submit {
select when web submit "#isbnForm"
foreach page:param("isbnList") setting (isbn)
pre {
// API lookups, etc.
}
{
// Debugging information, so we know it's working
emit <|
KOBJ.log('ISBN: ' + isbn);
|>;
// Put the price information into the proper places on the page
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment