Skip to content

Commit

Permalink
Update script.js
Browse files Browse the repository at this point in the history
  • Loading branch information
SIDDHU123M authored Sep 3, 2024
1 parent eb81599 commit 687e794
Showing 1 changed file with 59 additions and 57 deletions.
116 changes: 59 additions & 57 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
if (typeof window !== "undefined") {
try {
const key = "X-XSS-Protection";
if (typeof event !== "undefined") {
event.respondWith(
new Response("", {headers: {[key]: "1; mode=block"}})
);
} else {
const existing = document.head.querySelector(
`meta[http-equiv="${key}"]`
);
if (existing) {
existing.setAttribute("content", "1; mode=block");
} else {
const meta = document.createElement("meta");
meta.setAttribute("http-equiv", key);
meta.setAttribute("content", "1; mode=block");
document.head.appendChild(meta);
}
}
} catch (e) {
console.log("Error protecting your security!");
}
try {
const key = "X-XSS-Protection";
if (typeof event !== "undefined") {
event.respondWith(
new Response("", {headers: {[key]: "1; mode=block"}})
);
} else {
const existing = document.head.querySelector(
`meta[http-equiv="${key}"]`
);
if (existing) {
existing.setAttribute("content", "1; mode=block");
} else {
const meta = document.createElement("meta");
meta.setAttribute("http-equiv", key);
meta.setAttribute("content", "1; mode=block");
document.head.appendChild(meta);
}
}
} catch (e) {
console.log("Error protecting your security!");
}
}

// Set GitHub link dynamically

// Use the native fetch API for browser environments
fetch("json/main.json")
.then((response) => response.json())
.then((data) => {
const githubLinkElement = document.getElementById("githubLink");
githubLinkElement.href = data.githubLink;
.then((response) => response.json())
.then((data) => {
const githubLinkElement = document.getElementById("githubLink");
githubLinkElement.href = data.githubLink;
githubLinkElement.target = "_blank";
})
.catch((error) => console.error("Error fetching GitHub link:", error));
})
.catch((error) => console.error("Error fetching GitHub link:", error));

// // Dynamic List Script
// const fetchDataAndCreateLinks = (skills, containerId) => {
Expand Down Expand Up @@ -61,41 +61,43 @@ fetch("json/main.json")
// };

function checkLinkStatus(link, statusId) {
const statusCircle = document.getElementById(statusId);
const statusCircle = document.getElementById(statusId);

fetch(link.href, {mode: "no-cors"})
.then((response) => {
console.log(`Response for ${link.href}:`, response);
statusCircle.classList.add("online");
})
.catch((error) => {
console.error(`Error fetching ${link.href}:`, error);
statusCircle.classList.add("offline");
});
fetch(link.href, {mode: "no-cors"})
.then((response) => {
console.log(`Response for ${link.href}:`, response);
statusCircle.classList.add("online");
})
.catch((error) => {
console.error(`Error fetching ${link.href}:`, error);
statusCircle.classList.add("offline");
});
}

document.addEventListener("DOMContentLoaded", function () {
const links = document.querySelectorAll("main ul a");
links.forEach((link, index) => {
const statusCircle = document.createElement("span");
statusCircle.classList.add("status-circle");
statusCircle.id = `status-${index}`;
link.parentNode.insertBefore(statusCircle, link);
const links = document.querySelectorAll("main ul a");
links.forEach((link, index) => {
const statusCircle = document.createElement("span");
statusCircle.classList.add("status-circle");
statusCircle.id = `status-${index}`;
link.parentNode.insertBefore(statusCircle, link);

checkLinkStatus(link, statusCircle.id);
});
checkLinkStatus(link, statusCircle.id);
});

const isIndexPage =
window.location.pathname === "/" ||
window.location.pathname.endsWith("index.html");
const isIndexPage =
window.location.pathname === "/" ||
window.location.pathname.endsWith("index.html") ||
window.location.href === "https://siddhu123m.github.io/CodehubX/" ||
window.location.href === "https://siddhu123m.github.io/CodehubX";

const allLinks = document.querySelectorAll(
'main a:not(header a):not(.back-button a):not(.logo a):not([href^="#"]):not([href="index.html"])'
);
const allLinks = document.querySelectorAll(
'main a:not(header a):not(.back-button a):not(.logo a):not([href^="#"]):not([href="index.html"])'
);

if (!isIndexPage) {
allLinks.forEach((link) => {
link.setAttribute("target", "_blank");
});
}
if (!isIndexPage) {
allLinks.forEach((link) => {
link.setAttribute("target", "_blank");
});
}
});

0 comments on commit 687e794

Please sign in to comment.