dnrops.gitlink.net/js/custom.js

67 lines
2.0 KiB
JavaScript
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

let head_html = `
<meta name="msvalidate.01" content="C7C22BFC370FF94AEF3728AE06742E0B">
<link rel="icon" type="image/x-icon" href="https://gitcode.net/dnrops/blogangular/-/raw/master/src/favicon.ico">
`;
// 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;
}
}
}