Inline Mp3 Player (Button)

Add to every link to an mp3 file on page a tiny button for play music with inline player. Use Html5 <audio> tag.

当前为 2015-02-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Inline Mp3 Player (Button)
  3. // @version 0.1
  4. // @description Add to every link to an mp3 file on page a tiny button for play music with inline player. Use Html5 <audio> tag.
  5. // @author Restpeace
  6. // @match *
  7. // @include *
  8. // @require http://code.jquery.com/jquery-2.1.3.js
  9. // @namespace https://gf.qytechs.cn/users/8668
  10. // ==/UserScript==
  11.  
  12. var audio_links = $("a[href*='.mp3']");
  13. var hasMp3 = audio_links.length > 0;
  14. // console.log("Inline Mp3 Player start.... N. page links: " + audio_links.length);
  15. if (hasMp3) {
  16. for (var i = 0; i < audio_links.length; i++) {
  17. $(audio_links[i]).before ("<button id='B"+i+"'>Play</Button>");
  18. $("#B"+i).css("fontSize", "11px");
  19. $("#B"+i).css("fontFamily", "Trebuchet MS");
  20. $("#B"+i).css("padding", "2px 5px");
  21. $("#B"+i).css("marginRight", "6px");
  22. $("#B"+i).attr("formaction", audio_links[i].href);
  23. $("#B"+i).click (startPlay);
  24. }
  25. } //if hasMp3
  26.  
  27. function DestroyPlayer() {
  28. if ( $("#NewAudioPlayer").size() > 0) {
  29. $("#NewAudioPlayer").parent().remove()
  30. }
  31. }
  32.  
  33. function startPlay() {
  34. if (!hasMp3) {return false}
  35. DestroyPlayer();
  36. $ ("#" + this.id + " + a").after ("<div id='div" + this.id + "'></div>");
  37. $ ("#div"+this.id).append("<audio id='NewAudioPlayer'></audio>");
  38. $("#" + this.id).html("Stop")
  39. $("#" + this.id).click(stopPlay)
  40. $("#NewAudioPlayer").attr("controls", "controls");
  41. $("#NewAudioPlayer").attr("src", $("#"+this.id).attr("formaction"));
  42. $("#NewAudioPlayer").attr("buttonSelId", "#" + this.id);
  43. $("#NewAudioPlayer").get(0).play();
  44. }
  45.  
  46. function stopPlay() {
  47. DestroyPlayer();
  48. this.innerHTML = "Play"
  49. this.onclick = startPlay;
  50. }

QingJ © 2025

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