let head_html = `
`;
// let head = window.document.head.innerHTML;
// window.document.head.innerHTML = head.concat([head_html]);
let h2_vec = document.getElementsByTagName("h2");
let li = document.createElement("li");
li.className = "h2-to-li";
let replace_list = [
[",",""],
[",",""],
[" ","-"],
[".",""],
[",",""],
];
function replace_all(str) {
let newstr = str.trim();
for (let i = 0; i < replace_list.length; i++) {
newstr = newstr.replace(replace_list[i][0], replace_list[i][1]);
}
return newstr;
}
for (let index = 0; index < h2_vec.length; index++) {
const h2 = h2_vec[index];
let a = document.createElement("a");
a.href = `#${replace_all(h2.innerText.toLowerCase().replace(/\(/g,"").replace(/\)/g,"").replace(/ /g,"-"))}`;
a.innerText = h2.innerText;
li.appendChild(a);
}
const activeElement = document.querySelector('.active');
const parentElement = activeElement.parentNode;
if(parentElement.parentNode.classList.contains("section")){
parentElement.setAttribute('style', 'display: flex;flex-direction: column;');
parentElement.appendChild(li);
}
function handleLogin() {
if (localStorage.getItem('token') != null) {
let originalUrl = localStorage.getItem('originalUrl');
window.location.href = originalUrl;
}
}
if (window.location.pathname("posts/ctf")) {
// Get the current URL
if (!window.location.pathname.endsWith("ctf/login.html")) {
if(localStorage.getItem('token') !== "token"){
let originalUrl = window.location.href;
localStorage.setItem('originalUrl', originalUrl);
window.location.href = "login.html";
}else{
let originalUrl = localStorage.getItem("originalUrl");
window.location.href = originalUrl;
}
}
}