Created
April 1, 2010 06:41
-
-
Save fwenzel/351478 to your computer and use it in GitHub Desktop.
The source of http://userscripts.org/scripts/show/22474, up for the fixing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name gmail-wavplay | |
// @description Adds an embedded player within Gmail messsages containing audio files in the WAV format (e.g. Vonage voicemails). | |
// @author Evan Grim | |
// @include http://mail.google.com/* | |
// @include https://mail.google.com/* | |
// ==/UserScript== | |
unsafeWindow.addEventListener('load', wavPlay, true); | |
function wavPlay(){ | |
//GM_log('loading gmonkey') | |
if (unsafeWindow.gmonkey){ | |
unsafeWindow.gmonkey.load('1.0', onGLoaded); | |
} | |
} | |
function onGLoaded(gmail){ | |
//GM_log('gmonkey loaded'); | |
unsafeWindow.gmail = gmail | |
gmail.registerViewChangeCallback(scheduleSearchAndEmbed); | |
scheduleSearchAndEmbed(); | |
} | |
function scheduleSearchAndEmbed(){ | |
unsafeWindow.setTimeout(searchAndEmbed, 300); | |
} | |
function searchAndEmbed(){ | |
//GM_log('searching and embedding'); | |
if (unsafeWindow.gmail.getActiveViewType() == 'cv'){ | |
//GM_log('in conversation thread'); | |
var ave = unsafeWindow.gmail.getActiveViewElement(); | |
var imgs = ave.getElementsByTagName('IMG'); | |
for (var i=0; i<imgs.length; i++){ | |
var img = imgs[i]; | |
var imgParent = img.parentNode; | |
//GM_log('parent: ' + imgParent.nodeName + '/src: ' + img.src); | |
if (imgParent.nodeName == 'A' && | |
img.src.search('sound.gif') != -1){ | |
//GM_log('Linked sound.gif image found, embedding'); | |
tableRow = findTableRow(img) | |
if (tableRow != null){ | |
var embed = document.createElement('TD'); | |
embed.innerHTML = '<div><embed src=' + img.parentNode.href + ' autostart="false" loop="false" height="25" width="144"><noembed>This browser does not support embedded multimedia</noembed></embed></div>'; | |
tableRow.appendChild(embed); | |
} | |
} | |
} | |
} | |
} | |
function findTableRow(element){ | |
while (element != null){ | |
if (element.nodeName == 'TR'){ | |
break; | |
} | |
element = element.parentNode; | |
} | |
return element; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment