Bare Bookmarklet Example

Drag the link below into your bookmark bar.

FvB Bare

Generating this bookmarklet

  rails g easymarklet:bare fvb_bare

You'll get a bare shell of a bookmarklet.


  // Your bare bookmarklet code goes here.

Update the code

Then we just add a little bit of code to grab the current URL and send it back to our app.

Note : This code is designed to allow you to test your bookmarklets in various different environments. You could potentially simplify it by just hardcoding your destination URL.

To make the environment friendly magic work, we need to include the erb processor on the js.

mv app/assets/javascripts/fvb_bare_bookmarklet.js app/assets/javascripts/fvb_bare_bookmarklet.js.erb

  // Your bare bookmarklet code goes here.
  var protocol = 'http://'
  var host = '<%= Rails.application.config.action_controller.default_url_options[:host] %>';
  var port = '<%= Rails.application.config.action_controller.default_url_options[:port] %>';
  port = port === '' ? '' : ':' + port;
  var full_host = protocol + host + port;
  document.location = full_host + "/pages/new?url=" + encodeURIComponent(document.location)

Link to the bookmarklet

The easymarklet_js helper function makes it easy to link to your bookmarklet in a template.

  <%= link_to 'FvB Bare', easymarklet_js('fvb_bare_bookmarklet.js') %>