request: improve Wikipedia "listen" link

in Ideas and script requests
Subscribe to request: improve Wikipedia "listen" link 14 posts, 3 voices



ekbworldwide Scriptwright
FirefoxWindows

request - wikipedia - make the...
listen
... .ogg link play the audio sample without needing to change location.href. In other words - you click the link - the audio plays.

An ogg version of an inline player isn't needed - just the ability to click the link and have it play.

example

Archaea
http://en.wikipedia.org/wiki/Archaea

Archaea [.ogg audio link]
http://upload.wikimedia.org/wikipedia/commons/0...

There doesn't seem to already be such a script.

Your search - sound | audio intitle:wikipedia site:userscripts.org/scripts/show - did not match any documents.
http://www.google.com/search?hl=en&lr=&safe=off...=

I'm assume making such a script would be very easy for some of you - but it would take me hours more time.

 
JoeSimmons Scriptwright
FirefoxWindows

Actually there is such a script (http://userscripts.org/scripts/show/779) but the player that it uses seems to throw a 403 error.

 
ekbworldwide Scriptwright
FirefoxWindows

That script...

Inline Mp3 Player
http://userscripts.org/scripts/show/779

...doesn't work. The key problem being: Mp3.

Why don't you use something to capture the title + url? Having the title there too makes things a lot clearer.

I edited my first post.

 
JoeSimmons Scriptwright
FirefoxWindows

No that's not really the problem, just change the regex and it works on mp3 too. But like I said, the player it uses throws a 403 forbidden error when you access it, so even though the script adds the code, the player doesn't load. Maybe you could find a new player and adapt the script.

 
devnull69 Scriptwright
FirefoxWindows

If you restrict your script to Firefox 3.5 or higher, you can use the <audio> tag to play the sound directly when clicking the link.

See: http://userscripts.org/scripts/show/62987

 
JoeSimmons Scriptwright
FirefoxWindows

Hmm, audio tag, that's cool.
I hope you don't mind, I made some improvements on your script.

var array=document.evaluate("//a[contains(@href, '.mp3') or contains(@href, '.ogg') or contains(@href, 'wav') or contains(@href, 'wave')]", document, null, 6, null), regex=/\.(mp3|ogg|wave?)$/i;

for(let i=0,item; (item=array.snapshotItem(i)); i++) {
if(regex.test(item.href)) {
var audio=document.createElement("audio");
	audio.src=item.href;
document.body.appendChild(audio);
item.setAttribute("onclick", "return false;");
item.removeAttribute("target");
item.addEventListener("click", function(e) {audio.play();}, false);
}
}

I remove the target attribute because I have the "Offsite links in new window" and it would play but open a new window too.

 
ekbworldwide Scriptwright
FirefoxWindows

@devnull69
@JoeSimmons

Thanks.

I remove the target attribute because I have the "Offsite links in new window" and it would play but open a new window too.

Middle click opens a blank tab with the url javascript:void(0);.

The page also scrolls to the top. I use stylish - so the link is lower on the page.

 
devnull69 Scriptwright
FirefoxWindows

@ekbworldwide: My script doesn't scroll to the top any more. Maybe you will have to reinstall it. I had to update it very shortly after my first response to prevent it from doing that.

 
ekbworldwide Scriptwright
FirefoxWindows

Okay.

Middle click now opens link + #

I think it's better if a middle click opens the .ogg link.

 
devnull69 Scriptwright
FirefoxWindows

Changed accordingly ... please reinstall again

 
JoeSimmons Scriptwright
FirefoxWindows

ekbworldwide wrote:
Middle click opens a blank tab with the url
Why would you middle click it?
ekbworldwide wrote:
The page also scrolls to the top
Not with my code.
ekbworldwide wrote:
I think it's better if a middle click opens the .ogg link.
Updated my code above. Should work like that.
 
ekbworldwide Scriptwright
FirefoxWindows

Why would you middle click it?

I developed the habit of clicking middle clicking at many sites - I don't like back button navigation. In fact - I hate it.

Also middle clicking should never open a blank tab (with or without javascription in the address bar). link + # is much better. It's amazing to me that even popular sites force open a useless blank tab on middle click.

@devnull69

You could add tags to your script so it's easier to find: wikipedia, ogg, audio (or whatever). And a screen shot wouldn't hurt. Images make things clearer and not everybody can read English (well).

 
ekbworldwide Scriptwright
FirefoxWindows

@devnull69
@JoeSimmons

Your code fails on this page:

Schadenfreude
http://en.wikipedia.org/wiki/Schadenfreude

@devnull69

I'll make future comment in your script's comment thread.

 
devnull69 Scriptwright
FirefoxWindows

Changed ... please reinstall :-)

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel