iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🦊

Implementing the Rabbit Presentation Tool for Firefox

に公開
2023/06/13

There is a presentation tool called Rabbit. It is a tool where a rabbit and a turtle chase each other at the bottom of the screen; it is built with Ruby and is often used by Matz (Yukihiro Matsumoto).

https://www.youtube.com/watch?v=m_LW5WIYJ9Q

I wondered if I could display a similar rabbit and turtle when viewing a PDF as well, and after playing around with it, I managed to make it work, so here is a note on it.

I implemented it by using a Firefox bookmarklet to load an .rb file via ruby.wasm. Since ruby.wasm is a recent personal favorite of mine, I'm intentionally doing in Ruby what could be done in JavaScript.

The bookmarklet looks like this:

javascript:(()=>{if(typeof rubyVM!='undefined'){rubyVM.eval('start');return};var d=document;var h=d.getElementsByTagName('head')[0];var s=d.createElement('script');s.src='https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@1.0.1/dist/browser.script.iife.js';h.appendChild(s);s=d.createElement('script');s.src='https://tmtms.net/rabbit/rabbit_firefox_pdf.rb';s.type='text/ruby';h.appendChild(s);var x=setInterval(()=>{if(typeof rubyVM != 'undefined'){try{rubyVM.eval('start');clearInterval(x)}catch(e){}}},500)})()

In this bookmarklet, https://tmtms.net/rabbit/rabbit_firefox_pdf.rb is loaded and executed.

When you execute the bookmarklet while viewing a PDF in Firefox, the rabbit is displayed.

The rabbit represents the position of the page currently being displayed.

If you add ?allotted_time=n to the PDF URL, a turtle appears.

At first it is stationary, but the turtle starts moving once you display the second page or later. allotted_time represents the duration (in minutes), and the turtle progresses from the left edge of the screen to the right edge over that period.

If the rabbit is behind the turtle, there is a possibility that you won't be able to finish the presentation within the allotted time.

Executing the bookmarklet again will reset the turtle's position.

I developed it on Linux, but I confirmed that it also works on Firefox for Mac. I'm not sure about Windows.

Since bookmarklets that load external files from untrusted third parties seem like a security risk, if any curious souls want to try it, I think it's better to copy the file locally and read the contents carefully before running it.

I also happened to make a bookmarklet for Google Slides as well. The usage is the same as for PDFs. The rabbit won't appear unless you start the slideshow. The behavior here feels a bit unstable.

javascript:(()=> {if(typeof rubyVM!='undefined'){rubyVM.eval('start');return};var d=document;var h=d.getElementsByTagName('head')[0];var s=d.createElement('script');s.src='https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@1.0.1/dist/browser.script.iife.js';h.appendChild(s);s=d.createElement('script');s.src='https://tmtms.net/rabbit/rabbit_google_slides.rb';s.type='text/ruby';h.appendChild(s);var x=setInterval(()=> {if(typeof rubyVM != 'undefined'){try{rubyVM.eval('start');clearInterval(x)}catch(e){}}},500)})()

Discussion