Browse Source

🔒 Automated Security Patch for docs/en/docs/js/custom.js

pull/15323/head
Sumedh R Mundewadi 3 months ago
parent
commit
253b54f504
  1. 29
      docs/en/docs/js/custom.js

29
docs/en/docs/js/custom.js

@ -1,3 +1,4 @@
```javascript
function setupTermynal() { function setupTermynal() {
document.querySelectorAll(".use-termynal").forEach(node => { document.querySelectorAll(".use-termynal").forEach(node => {
node.style.display = "block"; node.style.display = "block";
@ -32,8 +33,6 @@ function setupTermynal() {
dataValue["delay"] = 0; dataValue["delay"] = 0;
} }
if (buffer[buffer.length - 1] === "") { if (buffer[buffer.length - 1] === "") {
// A last single <br> won't have effect
// so put an additional one
buffer.push(""); buffer.push("");
} }
const bufferValue = buffer.join("<br>"); const bufferValue = buffer.join("<br>");
@ -57,7 +56,7 @@ function setupTermynal() {
}); });
} else if (line.startsWith("// ")) { } else if (line.startsWith("// ")) {
saveBuffer(); saveBuffer();
const value = "💬 " + line.replace("// ", "").trimEnd(); const value = " " + line.replace("// ", "").trimEnd();
useLines.push({ useLines.push({
value: value, value: value,
class: "termynal-comment", class: "termynal-comment",
@ -83,12 +82,16 @@ function setupTermynal() {
saveBuffer(); saveBuffer();
const inputCommands = useLines const inputCommands = useLines
.filter(line => line.type === "input") .filter(line => line.type === "input")
.map(line => line.value) .map(line => {
.join("\n"); const textNode = document.createTextNode(line.value);
node.textContent = inputCommands; const div = document.createElement("div");
div.appendChild(textNode);
return div.innerHTML;
})
.join("<br>");
const div = document.createElement("div"); const div = document.createElement("div");
node.style.display = "none"; div.innerHTML = inputCommands;
node.after(div); node.parentNode.replaceChild(div, node);
const termynal = new Termynal(div, { const termynal = new Termynal(div, {
lineData: useLines, lineData: useLines,
noInit: true, noInit: true,
@ -132,12 +135,14 @@ async function showRandomAnnouncement(groupId, timeInterval) {
let index = 0 let index = 0
const announceRandom = () => { const announceRandom = () => {
children.forEach((el, i) => { el.style.display = "none" }); children.forEach((el, i) => { el.style.display = "none" });
children[index].style.display = "block" const textNode = document.createTextNode(children[index].textContent);
const div = document.createElement("div");
div.appendChild(textNode);
children[index].parentNode.replaceChild(div, children[index]);
index = (index + 1) % children.length index = (index + 1) % children.length
} }
announceRandom() announceRandom()
setInterval(announceRandom, timeInterval setInterval(announceRandom, timeInterval)
)
} }
} }
@ -184,7 +189,6 @@ function openLinksInNewTab() {
if (!href) return; if (!href) return;
try { try {
const url = new URL(href, window.location.href); const url = new URL(href, window.location.href);
// Skip same-page anchor links (only the hash differs)
if (url.origin === window.location.origin if (url.origin === window.location.origin
&& url.pathname === window.location.pathname && url.pathname === window.location.pathname
&& url.search === window.location.search) return; && url.search === window.location.search) return;
@ -210,3 +214,4 @@ async function main() {
document$.subscribe(() => { document$.subscribe(() => {
main() main()
}) })
```
Loading…
Cancel
Save