generated from nathanwoodburn/python-webserver-template
parent
50275ba482
commit
6d77096a15
@ -69,6 +69,9 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
<div class="card-header bg-success text-white py-3 d-flex justify-content-between align-items-center">
|
||||
<h3 class="h5 mb-0">Result for ${escapeHtml(url)}</h3>
|
||||
<div>
|
||||
<button class="btn btn-sm btn-light ms-2" id="new-tab">
|
||||
<i class="bi bi-code-slash me-1"></i>View in new tab
|
||||
</button>
|
||||
<button class="btn btn-sm btn-light ms-2" id="view-source">
|
||||
<i class="bi bi-code-slash me-1"></i>View Source
|
||||
</button>
|
||||
@ -84,6 +87,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
// Get reference to the iframe and buttons
|
||||
const iframe = document.getElementById('result-iframe');
|
||||
const viewSourceButton = document.getElementById('view-source');
|
||||
const newTabButton = document.getElementById('new-tab');
|
||||
|
||||
const cleanedHtml = removeScripts(data.result);
|
||||
|
||||
@ -93,6 +97,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
// Set the iframe src to the blob URL
|
||||
iframe.src = blobUrl;
|
||||
|
||||
|
||||
// Add event listener to view source button
|
||||
viewSourceButton.addEventListener('click', function () {
|
||||
@ -113,6 +118,15 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
sourceWindow.document.close();
|
||||
});
|
||||
|
||||
// Add event listener to new tab button
|
||||
newTabButton.addEventListener('click', function () {
|
||||
// Get URL from window.location
|
||||
const proxyurl = `${window.location.protocol}//${window.location.host}/proxy/${url}`;
|
||||
|
||||
// Open host/proxy/url in new tab
|
||||
window.open(proxyurl, '_blank');
|
||||
});
|
||||
|
||||
// Set up cleanup when iframe is no longer needed
|
||||
window.addEventListener('beforeunload', function () {
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
|
7
tools.py
7
tools.py
@ -208,6 +208,13 @@ def proxy(url: str) -> requests.Response:
|
||||
|
||||
|
||||
def cleanProxyContent(htmlContent: str,url:str, proxyHost: str):
|
||||
# Set proxy host to https if not 127.0.0.1 or localhost
|
||||
if ":5000" not in proxyHost:
|
||||
proxyHost = proxyHost.replace("http","https")
|
||||
|
||||
|
||||
|
||||
|
||||
# Find all instances of the url in the html
|
||||
hostUrl = f"{urlparse(url).scheme}://{urlparse(url).netloc}"
|
||||
proxyUrl = f"{proxyHost}proxy/{hostUrl}"
|
||||
|
Loading…
Reference in New Issue
Block a user