您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Prevents the default action for linked .wav/.mp3 files. Inplace playback using HTML5 instead.
当前为
- // ==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
- // @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 {
- if(/\.(wav|mp3)$/i.test(document.links[--i].toString()))
- document.links[i].addEventListener('click', WavFixOnClickHandler);
- } while(i);
- function WavFixOnClickHandler(event) {
- event.preventDefault();
- var node = event.currentTarget, wrp = document.createElement('div'), ref = node.getAttribute('href'), type = ref.slice(-3);
- switch(type){ case 'mp3': type = 'mpeg'; break; }
- wrp.setAttribute('style', 'position:absolute;visibility:hidden;');
- wrp.innerHTML = '<audio controls autoplay><source src="' + ref + '" type="audio/' + type + '"></audio>';
- wrp.firstChild.onended = function() { wrp.parentNode.removeChild(wrp); };
- document.body.appendChild(wrp);
- return false;
- }