以下の図のような感じで、各セクションへのリンクを作る。

ラベルを HTML モードで編集して以下を貼り付け

ラベルを HTML モードで編集して以下を貼り付け
<!-- Moodle jump to section --> <div id="LinkToSection"></div> <script> window.addEventListener("DOMContentLoaded", function() { let lts = document.querySelector("#LinkToSection"); let sections = document.querySelectorAll('*[id^="section-"]'); let label = lts.appendChild(document.createElement("span")); label.innerHTML = "🚀"; label.title = "Jump to section"; [].forEach.call(sections, function(section) { let a = lts.appendChild(document.createElement("a")); a.classList.add("LinkToSection"); Object.assign(a, { href: "#" + section.id, textContent: section.id.replace(/section-/, "") }); if (section.classList.contains("current")) { a.classList.add("highlight"); } }); let style = document.head.appendChild(document.querySelector("#css4moodle-jump-to-section") || document.createElement("style")); Object.assign(style, { id: "css4moodle-jump-to-section", type: "text/css" }); let heredoc = function(f){return f.toString().split("\n").slice(1,-1).join("\n");}; style.textContent = heredoc(function(){/* a.LinkToSection { border: 1px solid lightgray; background: white; display: inline-block; width: 2em; text-align: center; text-decoration: none; } a.LinkToSection.highlight { background: #d9edf7; font-weight: bold; } #LinkToSection a:hover { border: 1px solid black; background: #fff0f0; text-decoration: none; } #LinkToSection a.highlight:hover { color: red; border: 1px solid red; background: #ffc0c0; } */}); (function() { let e = document.querySelector("#LinkToSection"); s = document.querySelectorAll('*[id^="section-"]'); [].forEach.call(s, function(s) { s = s.querySelector(".summary"); s.parentNode.insertBefore(e.cloneNode(true), s.nextSibling); }); e.style.display = "none"; })(); }); </script>
TSV から課題の評点を転記します。
/** * Moodle の「課題」の「すべての提出を表示する」で * 姓名欄の TD 要素の先頭の空白までを ID として * scores に Here Document として与えた TSV * ID<TAB>score * ... * から値を参照して評点を埋める。 */ Function.prototype.hdoc =function(){return this.toString().split("\n").slice(1,-1).join("\n");}; var scores = function(){/* 0000000001 - 0000000002 100 ... */}.hdoc(); // TSV から {ID: score, ...} の Object に変換 scores = scores.split("\n").map(s=>{ let f = s.split("\t"); return [f[0].replace(/ /g, ""), (f[1].match(/[0-9]+/)||["0"])[0]]; }).reduce((r,v)=>{ r[v[0]] = v[1]; return r; },{}); // ID で scores を参照して評点を埋める var trs = document.querySelectorAll('tr[id^="mod_assign_grading_"]'); [].map.call(trs,tr=>{ let s = tr.querySelector("td:nth-child(1)").textContent; let id = (s.match(/^[^ ]*/)||[""])[0]; if (Object.hasOwn(scores, id)) { tr.querySelector("input.quickgrade").value = scores[id]; console.log(id, scores[id]); delete scores[id]; } else { console.log(id, "Not found!") } }); console.log("Remains:"); console.log(scores);
タグ
コメントをかく