iOS Users: Please click here for the latest information: (updated 5.10.2016)
Say It Right Series

Scripted play-back mp3 buttons for hands-off practice

Posted by weibosi December 23, 2008 in the Group General Discussion.

Tags: practice writing scripts javascript greasemonkey

I've been trying to find a way to practice writing sentences from the lesson. So I learned Greasemonkey and wrote a script that plays all the mp3 buttons of the "css_audio_btn" class (hopefully chinesepod doesn't change that any time soon) any number of times you want with any time delay in seconds. Sound useful to you? Try it out and if you have suggestions or bugs, send them to mailto:cyber.warden@gmail.com.

You have to have firefox and greasemonkey installed to use the script. After you've done that, go to the "tools" menu and you can create a new script. Paste it this text, play around with the settings, and enjoy:

// Play all chinesepod.com audio buttons
// version 1.0.0
// 2008-12-22
// Copyright (c) 2008, Bryce Hathaway (cyber.warden@gmail.com)
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// This is a Greasemonkey user script.
//
// You need to install Greasemonkey if you haven't already done so. Check it
// out at http://greasemonkey.mozdev.org/  Check the "tools" menu in firefox
// for options on how to configure this script.
//
// ==UserScript==
// @name           play_all
// @namespace      http://chinesepod.com/
// @description    Plays all the mp3 files in one Chinese pod page, prompting
//                 the user for repeat count and delay.
// ==/UserScript==

var global_counter = 0
var global_index = 0

mp3_buttons = document.getElementsByClassName('css_audio_btn')
if (mp3_buttons.length == 0) abort()

var choice = prompt("How many times would you like to play back all sounds?")
if (choice < 1) {
   alert("Your entry should be a number greater than zero.")
   abort()
}
global_counter = choice

choice = prompt("How many seconds should I delay between playback?")
if (choice < 1) {
   alert("Your entry should be a number greater than zero.")
   abort()
}

function playNextSound()
{
   mp3_buttons[global_index].click()
   ++global_index
   if (global_index >= mp3_buttons.length) {
      global_index = 0
      --global_counter
   }
   if (global_counter != 0) {
      window.setTimeout(playNextSound, choice * 1000)
   }
}

Comments (0) RSS

loading... Updating ...

To comment, please login.

Not sure if your comment is appropriate? Check our Commenting Policy first.

New lesson idea? Please contact us.