Files
ArtPlayer/docs/document/common.js
T
2019-04-20 18:06:32 +08:00

26 lines
866 B
JavaScript

(function () {
window.runCode = function(hook) {
hook.ready(function() {
Array.from(document.querySelectorAll('.markdown-section a'))
.filter(function(item) {
return item.innerHTML === 'Run Code';
})
.forEach(function(item) {
item.addEventListener('click', function(event) {
event.preventDefault();
var codeElement = item.parentElement.nextElementSibling;
if (
codeElement.tagName === 'PRE' &&
codeElement.dataset.lang === 'js'
) {
var libs = item.href.split('/lib=')[1] || '';
var code = encodeURIComponent(codeElement.innerText);
var url = 'https://artplayer.org/?libs=' + libs + '&code=' + code;
window.open(url);
}
});
});
});
};
})();