mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-09 11:56:15 -08:00
26 lines
866 B
JavaScript
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);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
};
|
|
})();
|