Bookmarklet to clean Sparknotes for printing

Apparently I can’t buy the pdf-versions of the stuff on http://www.sparknotes.com, because I don’t have an american home address? That makes me grumpy. I guess I can just print out the articles myself, though that’s not very convenient.

But OK. To create a nice printable Sparknote page (without the mess, just the text), I use the following javascript code. It extracts the div element that has the className of studyGuideText and removes everything else (including all style sheets and an advert, floatingad).

javascript: ( function() {

var body = document.getElementsByTagName('body')[0];
var divs = body.getElementsByTagName('div');
var text = null;
for(var i=0; i<divs.length; i++){
	if(divs[i].className=='studyGuideText') {
		text = divs[i];
		break;
	}
}
if (text == null) {
	alert('Did not find any text to extract (looking for divs of class studyGuideText)');
	return;
}
while (body.hasChildNodes()){
	body.removeChild(body.firstChild);
}

body.appendChild(text);

for(i=0;i<document.styleSheets.length;i++){
	void(document.styleSheets.item(i).disabled=true);
}
var els=document.getElementsByTagName('*');
for(i=0;i<els.length;i++){
	void(els[i].style.cssText='');
	if(els[i].className=='floatingad'){
		els[i].parentNode.removeChild(els[i]);
	}
}

})();

The bookmarklet version — all in one line etc:

javascript:(%20function()%20{%20var%20body%20=%20document.getElementsByTagName('body')[0];%20var%20divs%20=%20body.getElementsByTagName('div');%20var%20text%20=%20null;%20for(var%20i=0;%20i<divs.length;%20i++){%20if(divs[i].className=='studyGuideText')%20{%20text%20=%20divs[i];%20break;%20}%20}%20if%20(text%20==%20null)%20{%20alert('Did%20not%20find%20any%20text%20to%20extract%20(looking%20for%20divs%20of%20class%20studyGuideText)');%20return;%20}%20while%20(body.hasChildNodes()){%20body.removeChild(body.firstChild);%20}%20body.appendChild(text);%20for(i=0;i<document.styleSheets.length;i++){%20void(document.styleSheets.item(i).disabled=true);%20}%20var%20els=document.getElementsByTagName('*');%20for(i=0;i<els.length;i++){%20void(els[i].style.cssText='');%20if(els[i].className=='floatingad'){%20els[i].parentNode.removeChild(els[i]);%20}%20}%20})();

Tested only with Firefox (Gecko) and Epiphany (Webkit). (I would have liked to just publish it as a link, but WordPress mangles it to something incomprehensible.)

Advertisements

Order of mp3-tracks in Sansa Clip+

I use a Sansa Clip+ mp3-player for listening to audiobooks. It took me quite a while to understand how to get the player to play the tracks in the correct order, but I think the following should do it.

One has to edit the mp3-tags (metadata embedded into the mp3-files). I use EasyTAG to do this (which is available for Ubuntu, and probably many other Linux distributions and operating systems.)

Sansa Clip+ derives the play-order by looking at the “NUMBER” tag. EasyTAG displays this as the “Track”.

The NUMBER tag for each track has to have the same number of digits, so it usually has to be padded with leading zeros.

That is, tracks numbered like this will not work: 1, 2, 3, … 8, 9, 10, 11… because the Sansa player will sort tracks 10 and 11 before track 2 (which obviously will screw up the literary experience considerably).

Padding with leading zeros will solve this: 01, 02, 03, … 08, 09, 10, 11…

In EasyTAG, this padding is not automatic, but has to be specified by the user under Settings -> Preferences -> Tag Settings -> “Write the Track field with the following number of digits” (which I have set to 3, because I’ve never encountered an audiobook with more than 1000 files in it – 001, 002, 003, … 008, 009, 010, 011…).

Some more random tips from the Sansa forums (I haven’t verified that they are needed) is the following.

  • Do not specify the total number of tracks (like 01/87, 02/87, 03/87) because that may confuse the player. Just leave that field empty..?
  • Make sure that the GENRE tag is set to “Audiobook”…?

End of post.

(Appendix)

The player will not handle the case with tracks in multiple subdirectories well. I think..? So one may as well move all files to one and the same directory, and then use EasyTAG to set the correct Track tag (NUMBER) on all of them. The following little script copies all mp3 files from within a directory tree to a directory named tmp. The file name of the new file while be $DIRNAME.x.$OLD_FILENAME (so that no filename information will get lost) rather than just $OLD_FILENAME.

#!/bin/dash                                                                                                                                                             

mkdir tmp ;

find * -name *mp3 | while read FILE ; do
 NEWFILE=`echo "$FILE" | sed 's/\//.x./'` ;
 echo "Copying tmp/$NEWFILE" ;
 cp "$FILE" "tmp/$NEWFILE" ;
done

It would be cool if one could just create the zero padded track numbers command line (i.e without needing to open EasyTAG), using something like this:

NUMBER=0;
for FILE in tmp/* ; do
  NUMBER=$(($NUMBER+1));
  PADDEDNUMBER=`printf "%03d" "$NUMBER"`;
  echo "Tagging $FILE. Track number will be: $PADDEDNUMBER"
  # eyeD3 --track="$PADDEDNUMBER" "$FILE" | grep title
  # id3v2 --track "$PADDEDNUMBER" "$FILE"
done

I’ve tried both eyeD3 and id3v2. Neither seems to create the necessary padding of leading zeros (at least not if there are more than 100 files). So — EasyTAG it is!