From f885ab684e955d25607007d2c7360b64faa58b7a Mon Sep 17 00:00:00 2001 From: Brian Read Date: Thu, 10 Apr 2025 19:48:59 +0100 Subject: [PATCH] Supress prev and next links when inside iframe --- root/opt/mailstats/js/mailstats.js | 38 +++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/root/opt/mailstats/js/mailstats.js b/root/opt/mailstats/js/mailstats.js index 912e3b2..693bbf5 100644 --- a/root/opt/mailstats/js/mailstats.js +++ b/root/opt/mailstats/js/mailstats.js @@ -1,4 +1,6 @@ -window.onload = function(){doNavs();} +document.addEventListener("DOMContentLoaded", () => { + doNavs(); // Your initialization code +}); //function openTab(event, tabId){ //// Get all elements with class="tab-content" and hide them //const tabContents = document.querySelectorAll('.tab-content'); @@ -12,24 +14,44 @@ window.onload = function(){doNavs();} //document.getElementById(tabId).classList.add('tab-content-active'); //event.target.classList.add('tab-active');} -function LinkCheck(url){ - var http = new XMLHttpRequest(); - http.open('HEAD', url, false); - http.send(); - return http.status!=404; +//function LinkCheck(url){ + //var http = new XMLHttpRequest(); + //http.open('HEAD', url, false); + //http.send(); + //return http.status!=404; +//} + +async function LinkCheck(url) { + //Not allowed by CSP rules. + //try { + //const response = await fetch(url, { mode: "no-cors" }); + //return response.ok; // Returns true if the resource exists + //} catch (error) { + //console.error("Error checking link:", error); + //return false; + //} + return true; } + function doNavs() { + const isInIframe = window.self !== window.top; var aTags = document.getElementsByTagName('a'), atl = aTags.length,i; for (i = 0; i < atl; i++) { if (aTags[i].innerText == "Previous") { - if (!LinkCheck(aTags[i].href)) { + if (isInIframe){ //!LinkCheck(aTags[i].href)) { aTags[i].style.visibility = "hidden"; } else { aTags[i].style.visibility = "visible"; } } else if (aTags[i].innerText == "Next") { - if (!LinkCheck(aTags[i].href)) { + if (isInIframe){ //!LinkCheck(aTags[i].href)) { + aTags[i].style.visibility = "hidden"; + } else { + aTags[i].style.visibility = "visible"; + } + } else if (aTags[i].innerText == "Index of files") { + if (isInIframe){ //!LinkCheck(aTags[i].href)) { aTags[i].style.visibility = "hidden"; } else { aTags[i].style.visibility = "visible";