Skip to content

Instantly share code, notes, and snippets.

@holly-hacker
Created October 14, 2018 16:11
Show Gist options
  • Save holly-hacker/aa51338e7331b1b2a344bf90f4a9caa9 to your computer and use it in GitHub Desktop.
Save holly-hacker/aa51338e7331b1b2a344bf90f4a9caa9 to your computer and use it in GitHub Desktop.
NinSheetMusic MIDI player
// ==UserScript==
// @name NinSheetMusic MIDI player
// @version 1
// @grant none
// @include https://www.ninsheetmusic.org/browse/series/*
// ==/UserScript==
function injectJs(url, callback) {
script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = callback;
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
}
injectJs('https://www.midijs.net/lib/midi.js', function() {
injectJs('https://code.jquery.com/jquery-3.3.1.slim.min.js', function() {
unsafeWindow.eval(`
$('.content tbody tr td[width]:last-child').each(function(idx, elem) {
var td = $(this);
var href = td.children('a').attr('href');
td.after(
$('<td>').append(
$('<a>').css('cursor', 'pointer').html('▶').click(function() {
MIDIjs.play(href);
})
)
).after(
$('<td>').append(
$('<a>').css('cursor', 'pointer').html('⏸').click(function() { MIDIjs.stop() })
)
);
});
console.log('loaded script');
`);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment