添加运行代码

This commit is contained in:
Harvey Zack committed 2018-11-20 16:02:37 +08:00
1 parent d8e1e597e2
commit 8d52cf8bba
4 files changed
+57 -598

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
window.runCode = function(hook) {
hook.ready(function() {
Array.from(document.querySelectorAll('.markdown-section a'))
.filter(function(item) {
return item.innerHTML === 'Run Code';
})
.forEach(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
);
}
});
});
});
};