Created
September 16, 2018 21:34
-
-
Save metaquanta/002b031b1c69fd9a0a5958dd6278b056 to your computer and use it in GitHub Desktop.
Inline Wikipedia's midis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Wikipedia: embed midi | |
// @namespace mqScripts | |
// @match *://*.wikipedia.org/* | |
// @grant none | |
// @require https://code.jquery.com/jquery-3.3.1.slim.min.js | |
// ==/UserScript== | |
// Requires that your browser knows what to do with midi audio tags. | |
// eg MIDI Player https://chrome.google.com/webstore/detail/midi-player/khppfbnjbaampmeeiocjhcodkklkcfjf | |
// | |
// Unfortunately, that extension's controls are a little big. TODO | |
const LOAD = "load"; | |
const A = 'a'; | |
const AFTER = 'afterend'; | |
((selector, mapper) => { | |
selector($).each((i, el) => { | |
console.log('match: '+el); | |
el.insertAdjacentHTML(AFTER, mapper(el)); | |
el.remove(); | |
}); | |
})( | |
$ => $(A).filter((i, a) => a.href.match(/^https:\/\/upload.wikimedia.org.*\.midi?($|\?)/)), | |
a => `<audio autoplay="false" controls> | |
<source src="${a.href}" type="audio/midi"></source> | |
</audio>` | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment