如何在点击时播放音频书签?

How can I play an audio bookmarklet on click?

我试图在点击播放音频时做到这一点,但这段代码不起作用。我也想知道如何实现这段有效的代码。

javascript:(function(){ var style = document.createElement(%27style%27), styleContent = document.createTextNode(%27* { cursor: url(data:image/x-icon;base64,AAACAAEAICAAAA4AEACoEAAAFgAAACgAAAAgAAAAQAAAAAEAIAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABwcGvpc3Ns/3NybP9vcGv/JSYt/xslI/8aJSP/FyUk/xkmJf8aJyX/Hygm/09OSv8iIiEEWFVhAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY1tlkRcfI/9fYWT/cnJr/1dbXf8aHyL/Ex4c/w0cGf8KGhr/CRoZ/w8aGv8SHhz/ISIf/yEhIP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHB4l/1tfZf9kaG7/NDc8/xYeIP8NHBv/Chwb/w0dHP8RHCH/Exsc/xUfHf8jIiP/IyIl/wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgIij/XGFn/1pkaP8eJCf/FiAe/wkdGv8KHBr/DyIh/xokLP8UHB7/FyEg/yMjI/8lJCj/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABkmLP86P0X/XGRo/xsiKP8WIh7/CR0a/wscG/8SHR7/Eh0e/xQeHf8XISD/IiIi/ygnLfcAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABsg7n6Iz1y/xowYP8ZLFz/Gi9d/yIzZP8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAuTYX/EStZ/x43Z/8ZL2D/OE9//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHCEtlldd6/9Ok6D/3SGtrsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/4AH//8AA///gAP//4AD//+AA//+gAP//AAH//4AB//8AAf//AAAP/4AAB/+AAAf/AAAH/wAAB/8AAA//AAAf/wAAP/8AAH//gAB//8AAf//wAP//+Af///w////8P///+D////gf///4H///+B////gP///4H////B////4//8=javascript:(function(){ var style = document.createElement(%27style%27), styleContent = document.createTextNode(%27* { cursor: url() 22 22, auto !important}%27); style.appendChild(styleContent ); var caput = document.getElementsByTagName(%27head%27); caput[0].appendChild(style); })();) 22 22, auto !important}%27); style.appendChild(styleContent ); var caput = document.getElementsByTagName(%27head%27); caput[0].appendChild(style); })();

javascript:object.onclick = function(){var audio = new Audio('https://media1.vocaroo.com/mp3/12OdDSvf3CkE');  audio.play();};

此代码无效。

您似乎需要在调用 audio.play() 之前为 canplaycanplaythrough 事件添加一个事件侦听器。试试这个:

javascript: (function() {  var audio = new Audio('https://media1.vocaroo.com/mp3/12OdDSvf3CkE');  audio.addEventListener('canplay', () =>{  audio.play();  });})();

更具可读性:

(function() {
    var audio = new Audio('https://media1.vocaroo.com/mp3/12OdDSvf3CkE');
    audio.addEventListener('canplay', () =>{
        audio.play();
    });
})();

编辑:P.S。音频剪辑的不错选择:)