Files
ArtPlayer/docs/docs/runCode.js
T
2018-11-20 19:52:05 +08:00

24 lines
749 B
JavaScript

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 code = window.encodeURIComponent(codeElement.innerText);
window.open(
'https://blog.zhw-island.com/ArtPlayer/lab/?code=' + code
);
}
});
});
});
};