// ==UserScript==
// @name           Helgon-alert
// @namespace      http://www.lysator.liu.se/~jhs/userscript
// @description    This scripts plays configurable sounds when you get new messages et c on Helgon.net.
// @include        http://www.helgon.net/frameset/new.asp
// @include        http://helgon.net/frameset/new.asp
// ==/UserScript==

// Edit this list to choose what sounds to play when, depending on which icons
// are lit in the status panel. The order in which the lines below is given is
// used to signify which sound wins when several icons are lit; the first sound
// that is not commented out and is lit, will be played. To play local files on
// your hard disk, use URLs such as file:///C|/Windows/Media/notify.wav
// In case you (like these example settings) leave out some icons and want a
// "catch-all" sound for those not explicitly mentioned, keep the "any" line.
var sounds = { friends:  'http://www.lysator.liu.se/~jhs/wav/holo3.wav',
	       mail:     'http://www.lysator.liu.se/~jhs/wav/holo2.wav',
	       guestbook:'http://www.lysator.liu.se/~jhs/wav/BladeRunner.wav',
	       diary:    'http://www.lysator.liu.se/~jhs/wav/holo1.wav',
	       //gallery:'',
	       //forum:  '',
	       any:      'http://webdesignskolan.com/html/ljud/glass.wav' };

var VOLUME = 100; // 0-100, I think.

/*

Changelog:

2005-08-31 1.2 / Johan Sundström
* Changed to a comfier sound setting and added multiple sounds.

2005-08-24 1.1b / Arvid Jakobsson
* Small fix, fixed a typo which broke the script. Goddamnit :)

2005-08-23 1.1 / Arvid Jakobsson
* Rewrote the script, since I accidently deleted the old version.
* Some preparations for public release.

2005-08-* 1.0 / Arvid Jakobsson
* Initial version.

*/

/*
 BEGIN LICENSE BLOCK
Copyright (C) 2005 Arvid Jakobsson / arvid.jakobsson@gmail.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You can download a copy of the GNU General Public License at
http://www.gnu.org/licenses/gpl.html
or get a free printed copy by writing to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
END LICENSE BLOCK
 */

if( window.sounded ) return;
window.sounded = 1;

var i, j, src, embed, what, ignoreLater;
var news = /helgon\.net\/picz\/[^\/]+\/[01]_([^.]+)/;
for( i=0; i<document.images.length; i++ )
  if( what = news.exec( document.images[i].src ) )
    for( j in sounds ) // find a (higher prioritized) sound to play
      if( j == ignoreLater )
	break; // already detected a more prioritized event
      else if( (j == what[1]) || (j == 'any') )
      {
	src = sounds[j]; // highest prioritized sound found so far
	ignoreLater = j; // so do not try finding anything with lower priority
	break;           // but try the other images, too, first.
      }

if( src )
{
  embed = document.createElement( 'embed' );
  embed.src = src;
  embed.setAttribute( 'loop', 'false' );
  embed.setAttribute( 'hidden', 'true' );
  embed.setAttribute( 'autostart', 'true' );
  embed.setAttribute( 'volume', VOLUME.toString() );
  document.body.appendChild( embed );
}

