From 56cb76b83a7ee05b5a8383f9e3e0ddd22c029471 Mon Sep 17 00:00:00 2001 From: Siphalor Date: Tue, 22 Mar 2022 19:14:19 +0100 Subject: [PATCH] Fix Codersrank stuff --- about.md | 2 +- assets/js/main.js | 49 ++++++++++++++++++++++++++--------------------- index.md | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/about.md b/about.md index 98499db..dae41dd 100644 --- a/about.md +++ b/about.md @@ -25,4 +25,4 @@ In my spare time I do quite [some modding]({% link modding.html %}) to the sandb - [ LinkedIn](https://linkedin.com/in/{{ site.author.linkedin }}) - + diff --git a/assets/js/main.js b/assets/js/main.js index 3d5cc83..92872c6 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -35,29 +35,34 @@ cbox.checked = !cbox.checked; } }); -})(); -function prepareCodersrank(type) { - var placeholders = document.getElementsByClassName("cr-placeholder"); - if (localStorage.getItem("load-codersrank")) { - loadCodersrank(type); - } else { - for (ph of placeholders) { - ph.addEventListener("click", e => { - e.preventDefault(); - console.log(e); - localStorage.setItem("load-codersrank", true); - loadCodersrank(type); - }); + if (crTypes) { + // Codersrank + const placeholders = document.getElementsByClassName("cr-placeholder"); + if (localStorage.getItem("load-codersrank")) { + loadCodersrank(crTypes); + } else { + for (ph of placeholders) { + ph.addEventListener("click", e => { + e.preventDefault(); + console.log(e); + localStorage.setItem("load-codersrank", true); + loadCodersrank(crTypes); + }); + } } } -} -function loadCodersrank(type) { - var script = document.createElement("script"); - script.src = "https://unpkg.com/@codersrank/activity/codersrank-" + type + ".min.js"; - for (ph of document.getElementsByClassName("cr-placeholder")) { - ph.parentElement.innerHTML = ph.childNodes[0].data; - } - document.head.appendChild(script); -} + function loadCodersrank(types) { + const scriptElems = []; + for (type of types) { + const script = document.createElement("script"); + script.src = "https://unpkg.com/@codersrank/activity/codersrank-" + type + ".min.js"; + scriptElems.push(script); + } + for (ph of document.getElementsByClassName("cr-placeholder")) { + ph.parentElement.innerHTML = ph.childNodes[0].data; + } + document.head.append(...scriptElems); + } +})(); diff --git a/index.md b/index.md index 92d75c8..0c60ff3 100644 --- a/index.md +++ b/index.md @@ -11,4 +11,4 @@ layout: home - +