Skip to content

Commit

Permalink
Refactor completely
Browse files Browse the repository at this point in the history
  • Loading branch information
mtodd committed Jul 8, 2011
1 parent a687b4f commit 6ff0a7a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bookmarklet to automatically "Awesome" songs every 45 seconds for [Turntable.fm](http://turntable.fm).

Full credit to @wallace for the [original solution](https://gist.github.com/1063492).

[See the AutoAwesome help page for the Bookmarklet link](https://mtodd.github.com/auto-awesome)
1 change: 0 additions & 1 deletion README.rdoc

This file was deleted.

1 change: 1 addition & 0 deletions bookmarklet.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bookmarkletize
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

source=${1:-"source.js"}
output=${2:-"bookmarklet.js"}

cat $source | ./javascript_bookmarklet_builder > $output
34 changes: 34 additions & 0 deletions javascript_bookmarklet_builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env perl
#
# http://daringfireball.net/2007/03/javascript_bookmarklet_builder
# Licence: http://www.opensource.org/licenses/mit-license.php

use strict;
use warnings;
use URI::Escape qw(uri_escape_utf8);
use open IO => ":utf8", # UTF8 by default
":std"; # Apply to STDIN/STDOUT/STDERR

my $src = do { local $/; <> };

# Zap the first line if there's already a bookmarklet comment:
$src =~ s{^// ?javascript:.+\n}{};
my $bookmarklet = $src;

for ($bookmarklet) {
s{^\s*//.+\n}{}gm; # Kill comments.
s{\t}{ }gm; # Tabs to spaces
s{[ ]{2,}}{ }gm; # Space runs to one space
s{^\s+}{}gm; # Kill line-leading whitespace
s{\s+$}{}gm; # Kill line-ending whitespace
s{\n}{}gm; # Kill newlines
}

# Escape single- and double-quotes, spaces, control chars, unicode:
$bookmarklet = "javascript:" .
uri_escape_utf8($bookmarklet, qq('" \x00-\x1f\x7f-\xff));

print "$bookmarklet\n";

# Put bookmarklet on clipboard:
`/bin/echo -n '$bookmarklet' | /usr/bin/pbcopy`;
1 change: 0 additions & 1 deletion source.bookmarklet.js

This file was deleted.

0 comments on commit 6ff0a7a

Please sign in to comment.