terriko: (Default)
One of the things that bugs me when I'm doing book reviews is that I prefer it when reviews have a picture of the cover and link to the book of some sort, but I didn't love the output from Amazon's referal link generator, which would have been the easiest solution. I've been doing it manually, but that's a lot of cut and pasting and I kind of abhor doing tasks that are easy to automate.

Thankfully, I'm a coder and a user of greasemonkey, so I have all the skills I need to automate it. Seriously, being able to tweak web pages to suit my own needs is the greatest thing.

In the spirit of sharing, here's the script I'm using to generate the code I wanted for my reviews using the book page on LibraryThing:

// ==UserScript==
// @name        Book review header generator
// @namespace   tko-bookreview
// @description Takes any librarything book page and gives me a nice link to the book with cover and author details
// @include     http://www.librarything.com/work/*
// @version     1
// @grant       none
// ==/UserScript==

// Get all the data we'd like to display at the top of a review
var coverimage = document.getElementById('mainCover').outerHTML;
var title = document.getElementsByTagName('h1')[0].innerHTML;
var author = document.getElementsByTagName('h2')[0].innerHTML;
var librarythinglink = document.URL; 


// Trim down the title and author info
title = title.replace(/ *<span .*<\/span>/, '');

author = author.replace(/href="/, 'href="http://www.librarything.com');
author = author.replace(/<hr>/, '');

// Generate the code for this book
var reviewheader = '<a href="' + librarythinglink + '">' + 
   coverimage + '<br />' +
   '<b>' + title + '</b></a> ' +
   '<em>' + author + '</em>';

// Add code around this for embedding it into the page
var textbox = '<h4>Review Code</h4>' +
	'<textarea name="embedHTML" onFocus="this.select();" rows="5" ' + 
	'style="width: 250px;" wrap="virtual">' + reviewheader + '</textarea>';


// Find a good spot and add it to the page
var insert = document.getElementsByClassName('gap')[0];
insert.outerHTML =  textbox + insert.outerHTML;


Please feel free to consider this open sourced and free for any type of use: alter it to suit your needs as you will!

Edit: Github link, for those so inclined.
terriko: (Default)
The exhaustion/stress from fixing crud and trying to get my thesis done at the same time hit me hard today, so I came home at 4pm and immediately fell asleep.

As these things usually go, this resulted in me awakening sometime later, still feeling like a zombie, but unable to go back to sleep. I completely failed to read a magazine because I found myself skimming before I'd read a couple of sentences. So I figured I'd go mess about with flickr... time flies, and I find I've written a greasemonkey script making it easier for me to blog photos. Which is fine, except how the heck does it work that I can't concentrate long enough to read two sentences, yet I can write JavaScript code just fine?

I am concerned that in the dystopian future, some evil megacorp will take advantage of this and generate worker drones who are incapable of reading but perfectly good at writing code.

No, wait, that's just the exhaustion talking. In that spirit, though... Have some tentacles, and I'm going back to bed:


Profile

terriko: (Default)
terriko

June 2017

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25 2627282930 

Syndicate

RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jul. 22nd, 2017 02:42 am
Powered by Dreamwidth Studios