AmazonToMagnoliaWishlist

From Chickenfoot Script Repository

I use Ma.gnolia to store my wishlist from multiple sites, but it was a pain to cleanly add items from Amazon.com, so I created this. It needs to be extended if you want to post anything but books.

It can also be easily modified to work with del.icio.us.

var title = document.title
var url = document.location.href
var description = window.getSelection()
var tags = 'wishlist, ' // Here I store my default tag for my wishlist

// Next I extract the product title and type from the page title.
var m = title.match(/^Amazon.com: (.*): (.*): (.*)/)
title = m[1]
var kind = m[2]
switch (kind) {
case 'Books':
  tags += 'books, '
  break
// This is were you could add more items, like electronics, etc. This is mainly done to automate the pre-filled tags
}

// Clean the URL:
// This probably won't work with all Amazon.com URLs...
u = url.match(/www.amazon\.com\/.*\/dp\/(.*)\/.*/)
url = 'http://www.amazon.com/dp/' + u[1] + '/'

var rating = prompt("Rating (2-maybe, 3-good read, 4-must have, 5-purchase list) for:\n\n" + title + "\n" + url, 3)

if (rating != null) {
  var u_tags = prompt("Additional tags?", tags)
  if (u_tags == null) { u_tags = tags }
  with(openTab("http://ma.gnolia.com/bookmarklet/add", true)) {
    whenLoaded(function() {
      uncheck('After saving, return')
      enter('Title', title)
      enter('URL', url)
      enter('Description', description)
      enter('Tags', tags)
      document.getElementsByName('rating')[0].value = rating
      document.forms[0].submit()
      whenLoaded(function() {
        window.close()
      })
    })
  }
}

So, basically what this script does:

Retrieves the title for the item, cleans the URL, gets a description from the selected text, pre-fills the tags, opens the Ma.gnolia page in a new tab (could use "fetch", but I choose to see it actually get posted), posts the data, and closes the tab.

The script will ask you for a rating and to customize the predefined tags. If you cancel the rating prompt, the script will stop.