Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
Add manual input (text box) for redirect URL
  • Loading branch information
HTTPSRedirector committed Apr 1, 2024
1 parent 0c28060 commit ef73c5e
Showing 1 changed file with 46 additions and 20 deletions.
66 changes: 46 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<h2>HTTPS Redirector</h2>
<b>Author: Sean Pesce</b>
<br><br><br><br>
<span title="Redirecting to this URL"><b>Redirect URL:</b> <code id="redirect-url" style="background-color: rgb(230, 230, 230);"></code></span>
<span title="Redirecting to this URL"><b>Redirect URL:</b> <!-- <code id="redirect-url" style="background-color: rgb(230, 230, 230);"></code> --></span>
<br>
<input type="text" id="redirect-url" name="redirect-url" placeholder="https://example.com" style="margin-top:5px;width:80%;" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" >
<br>
<button type="button" id="redirect-button" style="margin-top:5px; font-size:1.875em;" onclick="doRedirect(true)">Redirect</button>
<br><br><br><br>
<b>Other Resources:</b>
<br><br>
Expand Down Expand Up @@ -63,10 +67,15 @@ <h2>HTTPS Redirector</h2>
return paramVal ? paramVal : defaultVal;
}

function fixRedirectUrl(url, allowUnsafe) {
function fixRedirectUrl(url) {
if (!url) {
return '';
}
// Allow "javascript:" and "data:" URLs
var allowUnsafe = getUrlParamWithAnyKey(['unsafe', 'dangerous',], false);
if ((!allowUnsafe) || allowUnsafe == '0' || allowUnsafe.toLowerCase() == 'false' || allowUnsafe.toLowerCase() == 'no') {
allowUnsafe = false;
}
if ((!allowUnsafe) && (url.toLowerCase().startsWith('data:') || url.toLowerCase().startsWith('javascript:'))) {
console.log('Unsafe redirect URI (use parameter "unsafe=1" for these kinds of URLs): ' + url);
return null;
Expand All @@ -78,39 +87,56 @@ <h2>HTTPS Redirector</h2>
return url;
}

function getRedirectUrl() {
var redirectUrl = document.getElementById('redirect-url').value;
if (!redirectUrl) {
redirectUrl = getUrlParamWithAnyKey(['redirectUrl', 'redirect', 'url', 'uri', 'r', 'u',], null);
}
redirectUrl = fixRedirectUrl(redirectUrl);
return redirectUrl;
}

function doHtmlRedirect(url) {
var metaElement = document.getElementById('html-redirect');
metaElement.content = `0; URL=${urlEscapeStr(url)}`;
var headElement = document.getElementsByTagName('head')[0];
headElement.appendChild(metaElement);
}

// Use JavaScript to redirect the page instead of an HTML meta tag
var forceJsRedirect = getUrlParamWithAnyKey(['javascriptRedirect', 'jsRedirect', 'javascript', 'js', 'j',], false);
if ((!forceJsRedirect) || forceJsRedirect == '0' || forceJsRedirect.toLowerCase() == 'false' || forceJsRedirect.toLowerCase() == 'no') {
forceJsRedirect = false;
}
function doRedirect(fromButton) {
var redirectUrl = getRedirectUrl();
if (!redirectUrl) {
var msg = 'Invalid redirect URI';
console.log(msg);
if (fromButton) {
alert(msg);
}
return;
}

// Allow "javascript:" and "data:" URLs
var allowJsUri = getUrlParamWithAnyKey(['unsafe', 'dangerous',], false);
if ((!allowJsUri) || allowJsUri == '0' || allowJsUri.toLowerCase() == 'false' || allowJsUri.toLowerCase() == 'no') {
allowJsUri = false;
}
// Use JavaScript to redirect the page instead of an HTML meta tag
var forceJsRedirect = getUrlParamWithAnyKey(['javascriptRedirect', 'jsRedirect', 'javascript', 'js', 'j',], false);
if ((!forceJsRedirect) || forceJsRedirect == '0' || forceJsRedirect.toLowerCase() == 'false' || forceJsRedirect.toLowerCase() == 'no') {
forceJsRedirect = false;
}

// Allow "javascript:" and "data:" URLs
var allowJsUri = getUrlParamWithAnyKey(['unsafe', 'dangerous',], false);
if ((!allowJsUri) || allowJsUri == '0' || allowJsUri.toLowerCase() == 'false' || allowJsUri.toLowerCase() == 'no') {
allowJsUri = false;
}

var redirectUrl = getUrlParamWithAnyKey(['redirectUrl', 'redirect', 'url', 'uri', 'r', 'u',], null);
redirectUrl = fixRedirectUrl(redirectUrl, allowJsUri);
var redirectUrlElement = document.getElementById('redirect-url');
redirectUrlElement.innerHTML = htmlEscapeStr(redirectUrl);

if (redirectUrl) {
if (forceJsRedirect || redirectUrl.toLowerCase().startsWith('javascript:')) {
window.location.href = redirectUrl;
} else {
doHtmlRedirect(redirectUrl);
}
} else {
console.log('Invalid redirect URI');
}

var redirectUrl = getRedirectUrl();
var redirectUrlElement = document.getElementById('redirect-url').value = redirectUrl;
// redirectUrlElement.innerHTML = htmlEscapeStr(redirectUrl);

doRedirect();
</script>
</html>

0 comments on commit ef73c5e

Please sign in to comment.