sound link fix

Prevents the default action for linked .wav/.mp3 files. Inplace playback using HTML5 instead.

当前为 2016-04-16 提交的版本,查看 最新版本

// ==UserScript==
// @name        sound link fix
// @namespace   gnblizz
// @description Prevents the default action for linked .wav/.mp3 files. Inplace playback using HTML5 instead.
// @include     *
// @version     1.01
// @grant       none
// @icon        http://japanese.about.com/library/weekly/graphics/speaker.gif
// ==/UserScript==
// sample page  http://japanese.about.com/od/japanesevocabulary/a/expression.htm
var i = document.links.length;
if(i) do {
  var link = document.links[--i];
  if(/\.(mp3|ogg|wav)$/i.test(link.href))
    link.addEventListener('click', WavFixOnClickHandler);
} while(i);
function WavFixOnClickHandler(event) {
  event.preventDefault();
  var node = event.currentTarget, wrp = document.createElement('div'), ref = node.getAttribute('href');
  wrp.setAttribute('style', 'position:absolute;visibility:hidden;');
  wrp.innerHTML = '<audio controls autoplay><source src="' + ref + '" type="audio/' + ref.slice(-3).replace('mp3','mpeg') + '"></audio>';
  wrp.firstChild.onended = function() { wrp.parentNode.removeChild(wrp); wrp = null; };
  document.body.appendChild(wrp);
  return false;
}
// public domain by gnblizz
// contact me with my username + '@web.de'

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址