const loadMarkdown = (cfg) => { if (!window.fetch) { cfg.el.innerHTML = '

Your browser outdated. Please use the latest version of Chrome or Firefox!

您的浏览器版本过低,请使用最新版的 Chrome 或 Firefox 浏览器!

'; } else { cfg.el.innerHTML = '
'; fetch(cfg.src, { method: "GET" }) .then((resp) => { return Promise.all([ resp.ok, resp.status, resp.text(), resp.headers, ]); }) .then(([ok, status, data, headers]) => { if (ok) { return { ok, status, data, headers, }; } else { throw new Error(JSON.stringify(json.error)); } }) .then((resp) => { let data = marked.parse(resp.data); cfg.el.innerHTML = data; }) .catch((error) => { console.error(error); cfg.el.innerHTML = '
'; }); }; }; $(function () { const els = document.getElementsByClassName('stellar-marked-api'); for (var i = 0; i < els.length; i++) { var cfg = new Object(); const el = els[i]; cfg.src = `${el.getAttribute('src')}?t=${new Date().getTime()}`; cfg.el = el; loadMarkdown(cfg); } });