added http error detection.
This commit is contained in:
parent
7e9107f9f2
commit
05c909787a
2 changed files with 86 additions and 147 deletions
206
index.html
206
index.html
|
@ -191,6 +191,17 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="blockedModal" class="modal blocked-modal">
|
||||
<div class="modal-content">
|
||||
<h2>⚠️ Content Blocked</h2>
|
||||
<p>This content cannot be displayed due to security restrictions.</p>
|
||||
<div class="blocked-modal-buttons">
|
||||
<button id="blockedRetryBtn" class="blocked-retry-btn">Try Another Site</button>
|
||||
<button id="blockedOpenBtn" class="blocked-open-btn">Open in New Tab</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<main>
|
||||
<iframe
|
||||
id="contentFrame"
|
||||
|
@ -256,146 +267,73 @@
|
|||
|
||||
// Wait for the page to load then focus
|
||||
frame.onload = () => {
|
||||
// Check if we landed on a blocked/error page
|
||||
try {
|
||||
// Get the actual URL from the iframe
|
||||
const currentUrl = frame.contentWindow.location.href;
|
||||
console.log("Current URL:", currentUrl); // Debug log
|
||||
|
||||
// Check if it's an HTTP URL
|
||||
if (currentUrl.startsWith('http:')) {
|
||||
console.log("HTTP URL detected, showing modal"); // Debug log
|
||||
const httpModal = document.createElement('div');
|
||||
httpModal.className = 'modal http-modal show';
|
||||
httpModal.innerHTML = `
|
||||
<div class="modal-content">
|
||||
<h2>⚠️ HTTP Content</h2>
|
||||
<p>This website uses HTTP and cannot be displayed in the frame for security reasons.</p>
|
||||
<div class="http-modal-buttons">
|
||||
<button class="http-open-btn">Open in New Tab</button>
|
||||
<button class="http-skip-btn">Skip This Site</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(httpModal);
|
||||
|
||||
// Handle button clicks
|
||||
const openBtn = httpModal.querySelector('.http-open-btn');
|
||||
const skipBtn = httpModal.querySelector('.http-skip-btn');
|
||||
|
||||
openBtn.addEventListener('click', () => {
|
||||
console.log("Opening in new tab:", currentUrl); // Debug log
|
||||
window.open(currentUrl, '_blank');
|
||||
httpModal.remove();
|
||||
fumble();
|
||||
});
|
||||
|
||||
skipBtn.addEventListener('click', () => {
|
||||
console.log("Skipping site"); // Debug log
|
||||
httpModal.remove();
|
||||
fumble();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for error pages
|
||||
const title = frame.contentWindow.document.title.toLowerCase();
|
||||
if (
|
||||
title.includes("blocked") ||
|
||||
title.includes("error") ||
|
||||
title.includes("refused") ||
|
||||
title.includes("cannot") ||
|
||||
title.includes("denied")
|
||||
) {
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
>>>>>>> parent of 97f3a78 (Reverted back to 4cd4110 before changes were made to monitoring. Trying)
|
||||
fumble();
|
||||
return;
|
||||
}
|
||||
|
||||
frame.focus();
|
||||
try {
|
||||
frame.contentWindow.focus();
|
||||
const title = frame.contentWindow.document.title.toLowerCase();
|
||||
if (
|
||||
title.includes("blocked") ||
|
||||
title.includes("error") ||
|
||||
title.includes("refused") ||
|
||||
title.includes("cannot") ||
|
||||
title.includes("denied")
|
||||
) {
|
||||
fumble();
|
||||
return;
|
||||
}
|
||||
|
||||
frame.focus();
|
||||
try {
|
||||
frame.contentWindow.focus();
|
||||
} catch (e) {
|
||||
// Ignore cross-origin errors
|
||||
}
|
||||
} catch (e) {
|
||||
// Ignore cross-origin errors
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Error in onload:", e); // Debug log
|
||||
// If we can't access the URL due to CORS, try using the src attribute
|
||||
if (frame.src.startsWith('http:')) {
|
||||
console.log("HTTP URL detected from src attribute"); // Debug log
|
||||
const httpUrl = frame.src;
|
||||
const httpModal = document.createElement('div');
|
||||
httpModal.className = 'modal http-modal show';
|
||||
httpModal.innerHTML = `
|
||||
<div class="modal-content">
|
||||
<h2>⚠️ HTTP Content</h2>
|
||||
<p>This website uses HTTP and cannot be displayed in the frame for security reasons.</p>
|
||||
<div class="http-modal-buttons">
|
||||
<button class="http-open-btn">Open in New Tab</button>
|
||||
<button class="http-skip-btn">Skip This Site</button>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(httpModal);
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
// Show blocked content modal
|
||||
const blockedModal = document.getElementById('blockedModal');
|
||||
const retryBtn = document.getElementById('blockedRetryBtn');
|
||||
const openBtn = document.getElementById('blockedOpenBtn');
|
||||
|
||||
blockedModal.classList.add('show');
|
||||
|
||||
retryBtn.onclick = () => {
|
||||
blockedModal.classList.remove('show');
|
||||
// Only show modal for mixed content errors
|
||||
if (e.toString().includes("mixed active content")) {
|
||||
const blockedModal = document.getElementById('blockedModal');
|
||||
const retryBtn = document.getElementById('blockedRetryBtn');
|
||||
const openBtn = document.getElementById('blockedOpenBtn');
|
||||
|
||||
blockedModal.classList.add('show');
|
||||
|
||||
retryBtn.onclick = () => {
|
||||
blockedModal.classList.remove('show');
|
||||
fumble();
|
||||
};
|
||||
|
||||
openBtn.onclick = () => {
|
||||
window.open(frame.src, '_blank');
|
||||
blockedModal.classList.remove('show');
|
||||
fumble();
|
||||
};
|
||||
return;
|
||||
}
|
||||
// For other errors, just try another site
|
||||
fumble();
|
||||
};
|
||||
|
||||
openBtn.onclick = () => {
|
||||
window.open(frame.src, '_blank');
|
||||
blockedModal.classList.remove('show');
|
||||
fumble();
|
||||
};
|
||||
=======
|
||||
// Try again if we hit an error page
|
||||
fumble();
|
||||
>>>>>>> b6825be (Revert "Reverted back to 4cd4110 before changes were made to monitoring. Trying")
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
// Can't access title due to CORS - assume page is OK
|
||||
}
|
||||
>>>>>>> 495bda9 (Reverted back to 4cd4110 before changes were made to monitoring. Trying)
|
||||
=======
|
||||
>>>>>>> parent of 97f3a78 (Reverted back to 4cd4110 before changes were made to monitoring. Trying)
|
||||
|
||||
// Handle button clicks
|
||||
const openBtn = httpModal.querySelector('.http-open-btn');
|
||||
const skipBtn = httpModal.querySelector('.http-skip-btn');
|
||||
|
||||
openBtn.addEventListener('click', () => {
|
||||
console.log("Opening in new tab:", httpUrl); // Debug log
|
||||
window.open(httpUrl, '_blank');
|
||||
httpModal.remove();
|
||||
fumble();
|
||||
});
|
||||
|
||||
skipBtn.addEventListener('click', () => {
|
||||
console.log("Skipping site"); // Debug log
|
||||
httpModal.remove();
|
||||
fumble();
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Handle load errors
|
||||
frame.onerror = () => {
|
||||
fumble(); // Try again if loading fails
|
||||
// Also update error handler to check for mixed content
|
||||
frame.onerror = (error) => {
|
||||
if (error && error.toString().includes("mixed active content")) {
|
||||
const blockedModal = document.getElementById('blockedModal');
|
||||
const retryBtn = document.getElementById('blockedRetryBtn');
|
||||
const openBtn = document.getElementById('blockedOpenBtn');
|
||||
|
||||
blockedModal.classList.add('show');
|
||||
|
||||
retryBtn.onclick = () => {
|
||||
blockedModal.classList.remove('show');
|
||||
fumble();
|
||||
};
|
||||
|
||||
openBtn.onclick = () => {
|
||||
window.open(frame.src, '_blank');
|
||||
blockedModal.classList.remove('show');
|
||||
fumble();
|
||||
};
|
||||
} else {
|
||||
fumble(); // For other errors, just try another site
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
27
styles.css
27
styles.css
|
@ -909,20 +909,19 @@ main:hover .floating-button {
|
|||
|
||||
.full-license a:hover {
|
||||
text-decoration: underline;
|
||||
<<<<<<< HEAD
|
||||
}
|
||||
|
||||
.http-modal .modal-content {
|
||||
.blocked-modal .modal-content {
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
.http-modal-buttons {
|
||||
.blocked-modal-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.http-open-btn, .http-skip-btn {
|
||||
.blocked-retry-btn, .blocked-open-btn {
|
||||
flex: 1;
|
||||
padding: 12px;
|
||||
border: none;
|
||||
|
@ -933,31 +932,33 @@ main:hover .floating-button {
|
|||
transition: background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.http-open-btn {
|
||||
.blocked-retry-btn {
|
||||
background-color: #ff4500;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.dark-mode .http-open-btn {
|
||||
.dark-mode .blocked-retry-btn {
|
||||
background-color: #ff6b4a;
|
||||
}
|
||||
|
||||
.http-open-btn:hover {
|
||||
.blocked-retry-btn:hover {
|
||||
background-color: #ff5722;
|
||||
}
|
||||
|
||||
.http-skip-btn {
|
||||
.blocked-open-btn {
|
||||
background-color: #f0f0f0;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.dark-mode .http-skip-btn {
|
||||
.dark-mode .blocked-open-btn {
|
||||
background-color: #2a2a2a;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.http-skip-btn:hover {
|
||||
.blocked-open-btn:hover {
|
||||
background-color: #e0e0e0;
|
||||
=======
|
||||
>>>>>>> b6825be (Revert "Reverted back to 4cd4110 before changes were made to monitoring. Trying")
|
||||
}
|
||||
}
|
||||
|
||||
.dark-mode .blocked-open-btn:hover {
|
||||
background-color: #333;
|
||||
}
|
Loading…
Reference in a new issue