MediaWiki:HTML5AudioPlayer/code.js

/**
 * HTML5AudioPlayer
 * @author: Manuel de la Fuente (https://manuelfte.com)
 * @version: 1.0.0
 * @license: CC-BY-SA 3.0
 * @description: Play audio files with a native HTML5 player

var divs = document.getElementsByClassName('html5audio')

for (var i = 0; i < divs.length; i++) { var div = divs[i]

var file = div.dataset.file var format = file.split('.').pop if (format === 'mp3') { format = 'mpeg' }

var preload = div.dataset.preload if (preload !== 'auto' || preload !== 'metadata') { preload = 'none' }

var download = div.dataset.download if (download === 'false') { download = ' controlsList="nodownload"' } else { download = '' }

var options = div.dataset.options var parsedOptions = '' if (options) { var optionsArr = options.split(',') var validOptions = ['autoplay', 'loop', 'muted'] var filteredOptions = optionsArr.filter(function (el) {     return validOptions.indexOf(el) > -1    }) parsedOptions = filteredOptions.join(' ') }

var audioTag = '' + '' + 'Your browser does not support the audio tag.' + ' '

div.innerHTML = audioTag

var vol = Number(Number(div.dataset.volume).toFixed(1)) if (vol >= 0 && vol <= 1) { div.querySelector('audio').volume = vol } }